Re: New switch/case idea

new topic     » goto parent     » topic index » view thread      » older message » newer message
irv said...

I am failing to detect the logic in this discussion.

switch x -- x = 1, let's say 
   case 1 : print "one" 
   case 2 : print "two" 

Why on earth would anyone EVER expect this to print "onetwo", when x = 1?

Can anyone show me a justification for this? Or any example where some other construct wouldn't do the same thing in a clearer way? Or have I simply misread some posts and don't understand?

Jeremy already addressed this. However, I'd like to add that even though "switch x do" will default to without fallthru (and thus print out only "one"), you can still do this:

switch x do 
	case 1 then 
		? 1 
		fallthru 
	case 2 then 
		? 2 
		fallthru 
	case 3 then 
		? 3 
		fallthru 
	case else 
		? 0 
end switch 

At least this is more readable, since you have an explicit keyword that tells you that the case is about to fall through to the next case.

useless said...

It's NOT a logical switch, it's a closeted goto stack.

You haveto add "break" on each line.

switch x -- x = 1, let's say 
   case 1 : print "one" break 
   case 2 : print "two" break 

Not any more. break is necessary now only if the entire switch is changed to "with fallthru".

useless said...

Sorry, Irv, i asked for goto, and sure enough, we got spagetti code from someone. Just chalk this up to "it works like this for historical C reasons" which have nothing to do with reading the source like it was a natural language. It does what it was designed to do: be a stack of goto targets, not a stack of if-thens evaluations. If it doesn't work like you want, make an if-then stack and add a goto "endofstack" to shortcut evaluation. Or, errr, no, we don't have OOEU's eval yet(?) so we cannot goto the value we seek to execute upon it being so. <cough>

useless

If you can write the code to make the interpreter do this, you will probably getit in the next version of Eu. (I'd say more, but I'm not exactly sure what you are asking for here.)

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

Search



Quick Links

User menu

Not signed in.

Misc Menu