The 'case' statement
Posted: Mon Nov 14, 2005 11:36 am
Hi,
As known, the 'case' statement must be used as follows:
This works fine but I find it a bit limited. Because it is impossible to use constants instead of the actual values. E.g. this is impossible:
So there is no way to compare variable or constant names in a case statement. In case of programs using an external context for example, this turns out to be quite annoying:
So the constant values which are intentionally kept in a separate context, cannot be used in a case statement. Instead, I have to lookup the actual values again and use those. If not, I receive the error 'symbol expected'.
Why is this case statement designed this way? Wouldn't it be more convenient to use constants and even expressions as well?
Peter
As known, the 'case' statement must be used as follows:
Code: Select all
(case n
(1 "one")
(2 "two")
(3 "three")
(4 "four")
(true "Can't translate this")
)
Code: Select all
(constant 'one 1)
(constant 'two 2)
(constant 'three 3)
(constant 'four 4)
(case n
(one "this is one")
(two "this is two")
(three "this is three")
(four "this is four")
(true "Can't translate this")
)
Code: Select all
(case k
(0x0065: #GLUT:GLUT_KEY_UP:
(set 'view_rotx (add view_rotx 5.0))
)
(0x0067: #GLUT:GLUT_KEY_DOWN:
(set 'view_rotx (sub view_rotx 5.0))
)
(0x0064: #GLUT:GLUT_KEY_LEFT:
(set 'view_roty (add view_roty 5.0))
)
(0x0066: #GLUT:GLUT_KEY_RIGHT:
(set 'view_roty (sub view_roty 5.0))
)
)
Why is this case statement designed this way? Wouldn't it be more convenient to use constants and even expressions as well?
Peter