< Back to IRCAM Forum

Switch/case-like statement

What’s the equivalent of a c switch/case statement, as in:

switch (something) { case x: statement; break;
case y: statement(s); break;

}

(if-then-else doesn’t have many inputs)

Hi das. Check #'case: CLHS: Macro CASE, CCASE, ECASE

-anders

Thanks very much anders. But when I try to make a box with any of these, nothing happens. How do I ‘plug this into’ om-sharp?

I see. Perhaps you could set up a 'lispfun and add the lisp code inside. Eg:
Skjermdump fra 2021-05-20 14-12-16

You can add further inputs by adding to the lambda clause: (lambda (x a b c …)

Thanks again, much appreciated. (I’m surprised this basic conditional is not available in the ‘core’ om-sharp, even as if-then-else-else-else…)

You can also use OR, which just evaluates its inputs until one returns a non-NIL value.

Connecting a AND on each branch might be a way to add an equality test along with a result/statement for this case, and implement pretty much an equivalent to Lisp’s COND.

I think I’ll try and work this up into a generalized flexible de facto case structure. If it works out, I’ll post it. Thanks Jean.