[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sc-users] A bug in switch/case?
The code below, with 7 expressions, works:
(
var x, z;
z = [0, 1, 1.1, 1.3, 1.5, 2, 3];
switch (z.choose.postln,
1, { \no },
1.1, { \wrong },
1.3, { \wrong },
1.5, { \wrong },
2, { \wrong },
0, { \true },
3, { \true }
).postln;
)
Now, let us add another expression and we'll get a failure:
(
var x, z;
z = [0, 1, 1.1, 1.3, 1.5, 2, 3, 4];
switch (z.choose.postln,
1, { \no },
1.1, { \wrong },
1.3, { \wrong },
1.5, { \wrong },
2, { \wrong },
0, { \true },
3, { \true },
4, { \true }
).postln;
)
ERROR: Message '☖@P0.Ɇ' not understood.
Both "switch" and "case" are limited to 7 expressions. Is it a bug or an
arbitrary limit?
"Switch" is defined in Object.sc:
switch { arg ... cases;
cases.pairsDo { | test, trueFunc |
if (this == test.value) { ^trueFunc.value };
};
if (cases.size.odd) { ^cases.last.value };
^nil
}
I don't see anything which would limit to 7 the number of expressions...
It is possible to use additional switch structures in case there are
more than 7 expressions to be evaluated, but I wonder what is the
advantage of using "case" or "switch" instead of an IdentityDictionary. ??
Ph.