Re: SWITCH question

new topic     » goto parent     » topic index » view thread      » older message » newer message

More problems with the switch statement:

Example 1

include std/stack.e  
  
constant op = stack:new(FIFO)  
    ? op  
 
constant stk = op  
    ? stk  
 
    switch stk do -- err line 
        case op then  
            puts(1, "\n result is first stack \n" )  
        case else  
            puts(1, "\n result is something else \n")  
    end switch  
  

1
1

/home/irv/stk.ex:9 A machine-level exception occurred during execution of this statement (signal 11)

Example 2

include std/stack.e  
  
atom op = stack:new(FIFO)  
    ? op  
 
atom stk = op  
    ? stk  
 
    switch stk do  
        case op then -- err line has moved 
            puts(1, "\n result is first stack \n" )  
        case else  
            puts(1, "\n result is something else \n")  
    end switch  
  

/home/irv/stk.ex:10
<0091>:: found variable but expected 'else', an atom, string, constant or enum
case op then



Notice, please, that this second version has two problems:

  • It did not print the two 1s, unlike the first program
  • Secondly, what does that error message even mean????

Given the difference, I suspect the problems exist in at least two separate places. The first example fails in the actual switch function, and the second is in an earlier step (parsing?).

Clearly, there are some major problems with switch!
Just to clarify that it isn't (all) a result of using std/stack, I submit this example:



Example 3

atom stk = 1 
    ? stk 
 
atom op = stk 
    ? op 
     
    switch stk do  
        case op then -- err here again 
            puts(1, "\n result is first stack \n" )  
        case else  
            puts(1, "\n result is something else \n")  
    end switch  

/home/irv/stk.ex:8
<0091>:: found variable but expected 'else',an atom, string, constant or enum
case op then

Am I misunderstanding something? I could swear that everything in there was atoms!

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu