Re: Switch question - yet again!
- Posted by _tom (admin) Sep 28, 2016
- 10952 views
There is a mystery here which I can't explain.
Example 1 // works
include std/stack.e constant op = 1 ? op --> 1 integer stk = op ? stk --> 1 switch stk do case op then puts(1, "\n result is first stack \n" ) case else puts(1, "\n result is something else \n") end switch --> result is first stack
Example 2 // fails
include std/stack.e constant op = stack:new(FIFO) ? op --> 1 // "stacks" start numbering at one integer stk = op ? stk --> 1 switch stk do case op then puts(1, "\n result is first stack \n" ) case else puts(1, "\n result is something else \n") end switch --> machine level exeception
Since "op" is a constant, in theory it should work in a switch statement--but it fails.
Example 3 // works
include std/stack.e constant op = stack:new(FILO) ? op --> 1 // "stacks" start numbering at one stack:push(op, 23 ) ? stack:peek_top(op) --> 23 // value at top of "op" stack show_stack( op ) procedure show_stack( integer stk ) puts(1, "\n executing show_stack \n" ) ? stk ? op -- this does work if equal(stk,op) then puts(1, "\n result is first stack \n" ) else puts(1, "\n result is something else \n" ) end if end procedure --> result is first stack
_tom