1. stack.e functions
- Posted by Larry Miller <larrymiller at saskt?l.ne?> May 04, 2008
- 589 views
I was looking at the functions defined in stack.e on SourceForge and found 2 problems. push() will not word properly if value is a sequence. dup() will not work properly if the top element is a sequence. The corrected functions:
global function push(stack sk, object value) if sk[1] = FIFO then if length(sk) = 1 then return sk & {value} end if return FIFO & {value} & sk[2..$] else return sk[1..$] & {value} end if end function global function dup(stack sk) if length(sk) = 1 then crash("stack underflow in dup()", {}) end if return sk & {sk[$]} end function
Larry Miller
2. Re: stack.e functions
- Posted by Jeremy Cowgar <jeremy at cowga?.co?> May 04, 2008
- 594 views
- Last edited May 05, 2008
Larry Miller wrote: > > I was looking at the functions defined in stack.e on SourceForge and found 2 > problems. push() will not word properly if value is a sequence. dup() will not > work properly if the top element is a sequence. > > The corrected functions: Thanks Larry! This is what the standard libraries are all about! I added a few tests to exploit the bug you found:
sk = s:push(sk, {10,20}) test_equal("FIFO push sequence #1", {FILO, {10,20}}, sk) sk = s:push(sk, {30,40}) test_equal("FIFO push sequence #3", {FILO, {10,20},{30,40}}, sk) sk = s:dup(sk) test_equal("FIFO dup sequence", {FILO, {10,20},{30,40},{30,40}}, sk)
I then applied replaced the dup and push functions with your variants and all tests pass again. The changes have been committed to SVN. 579 tests run, 579 passed, 0 failed, 100% success -- Jeremy Cowgar http://jeremy.cowgar.com