Hello python-list,

I decided to have some fun and altered a copy of python to use a
Haskell-like syntax for declaring lambdas.

>>> filter( \ x -> x == 3 or x > 8 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ,
10 ] )
[3, 9, 10]
>>> ( \-> "Hello World!" )()
'Hello World!'

While doing this I found something interesting while changing the grammar to
:

    old_lambdef: ( 'lambda' | '\\' ) [varargslist] ( ':' | '->' ) old_test
    ...
    lambdef: ( 'lambda' | '\\' ) [varargslist] ( ':' | '->' ) test


In Parser/tokenizer.c, instead of needing to change only the PyToken_OneChar
function to have a
        case '\\':      return LAMBDAARGS;
option, I also had to add
        case '\\':
                switch (c2) {
                case '\\':      return LAMBDAARGS;
                }
to PyToken_TwoChars.

The interactive runtime requires the OneChar definition, and the compilation
process ( specifically pgen ) requires the TwoChar definition.

If anyone wants the changes required to play around with it just email me
and I'll find somewhere to stick them on the web for download.

It seems a waste that whack acts only as an end of line continuance.

- Michael Speer
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to