On 16/03/2016 12:21, Marko Rauhamaa wrote:
BartC <b...@freeuk.com>:
That's the first time I've heard a language feature common in C
described as sexy.
Scheme has a "switch" statement (a "case" form). However, it is slightly
better equipped for it than Python:
* Scheme has an atom type ("symbol"). It corresponds to interned
strings and is supposed to be compared by reference.
* Scheme has defined three equality operators: "eq?", "eqv?" and
"equal?". Python only has two: "is" (~ "eq?") and "==" (~ "equal?").
The "case" form makes use of the operator "eqv?" that is missing from
Python ("eqv?" compares numbers numerically but is otherwise the same
as "eq?").
Yes, a few scripting languages can do interesting things with switch or
case statements. Perl for example (where I think it is created out other
language features, but it looks a regular part of the syntax).
Even Ruby has one. It doesn't do anything 'sexy' with it, but it does
have this:
case
when this
....
when that
....
when other
...
end
which is exactly equivalent to if this... elif that... (when the tests
are ordered), with one difference:
Each test starts with "when", instead of "if" for the first and "elif"
for subsequent ones. That makes it easier to reorder tests, temporarily
comment out the first test, copy a test from elsewhere, insert a new
first test (you get the idea).
--
Bartc
--
https://mail.python.org/mailman/listinfo/python-list