Various folks wrote:

Superpositions in the core? You're kidding, right?
Nope. They're in (this week at least!)


What's wrong with "if 1 <= $var <= 31"?

...nothing.  If you like it, by all means use it.  But, (1) TIMTOWTDI,
(2) Smyler's version is more visually concise (although, granted, it
actually takes a few extra chars), (3) Smyler's version puts the
variable (the important thing in the expression) on the left instead
of the in the middle, and (4) IMHO, Smyler's version reads better as
English.

It's also far slower. Constructing a 31-element list, junctionizing it,
This might well be done at compile-time. And/or, lazily. So the cost of these
two steps is likely to be negligible.

then testing against each element vs. 2 numeric comparisons.
Yes. That's a significant cost in this case.


Wanting to do this for arbitrary lists dosen't need junctions. "if grep $_ ==
$var, @mylist" suffices.
Except that it's much uglier (and hence less maintainable) than:

	if $var == any(@mylist)

Moreover, in this case, junctions may well be faster, since they short-circuit and
C<grep> probably still doesn't.

Damian

Reply via email to