merits of Lisp vs Python

André Thieme address.good.until.2006.dec.22 at justmail.de
Mon Dec 11 09:17:42 EST 2006


Paul Rubin schrieb:
> Steven D'Aprano <steve at REMOVE.THIS.cybersource.com.au> writes:
>> Now, if you want to tell me that, despite all the talk, Lisp coders don't
>> actually create new syntax or mini-languages all that often, that they
>> just use macros as functions, then the question becomes: why do you need
>> macros then if you are just using them as functions? Why not use functions?
> 
> Macros let you write what amounts to functions that don't evaluate
> their arguments.  Think of the endless clpy wars over the ternary
> conditional operator.  You want to write something like
> 
>    def ternary(test, iftrue, iffalse):
>       if test: return iftrue
>       else iffalse
> 
> but because of side effects, you don't want
> 
>    a = cond(test, f(x), g(x)) 
> 
> to evaluate both f and g.  That is trivial to do with a macro but
> can't be done with a function.

I think you could do that with functional programming.
You can protect the evaluation by encapsulating the args in a function
object?


def f_Args(x):
   return x

def g_Args(x):
   return x


and then
a = cond(test, f, g, f_Args(x), g_Args(x))

if you adopt cond. But of course it is getting ugly.
So a macro can free you from this extra code.


André
-- 



More information about the Python-list mailing list