new enum idiom
Alex Martelli
aleaxit at yahoo.com
Thu Jan 11 07:52:44 EST 2001
"Robert Amesz" <rcameszREMOVETHIS at dds.removethistoo.nl> wrote in message
news:90268BCE3rcamesz at 127.0.0.1...
[snip]
> Oh, allright. let's just call it a *little* easier, then. I mainly like
> the lispy flavour.
Which is probably what will turn many other people OFF:-).
> Also, as a small extra bonus, you can use
> expressions with the tuple-notation. That allows you to do things like:
>
> #global constants
> base1 = 100
> base2 = 200
>
> #Someplace else
> xx = enum(('foo',base1), 'foo2', 'foo3', ('bar',base2), 'etc')
>
> Of course, you can always eval() the right hand part of 'foo=base1',
> but the other form catches any syntax errors in those expressions
> before the program actually runs.
But the string-syntax goes one better by allowing, not just syntax
checking (at compile time), but also type-checking (at runtime) if
you wish to specify it:
xx = enum('foo=%s'%base1, 'foo2', 'foo3', 'bar=%d'%base2, 'etc')
here, base1 is accepted whatever type it is (as long as it's able
to produce a string-form:-), but base2 is requested to be able to
produce an integer specifically.
Very un-Lispish, no doubt, but, IS this comp.lang.lisp...?-)
Alex
More information about the Python-list
mailing list