Python's "only one way to do it" philosophy isn't good?

Paul Rubin http
Fri Jun 22 20:00:08 EDT 2007


Douglas Alan <doug at alum.mit.edu> writes:
> People (myself included) haven't had much trouble implementing nice
> and useful macro packages for Lisp.  Admittedly, it's a harder problem
> for a language that doesn't have a Lisp-like syntax.

One very simple hack would be to define a syntax extension like

   f.(arg1,arg2,arg3)

to compile f's args into unevaluated thunks passed into f, instead of
evaluating them as expressions before calling f.  That could replace
macros and syntax extensions in some circumstances.  For example the
famous ternary operator would just be

    def ternary(cond, a, b): 
       if cond(): return a()
       else: return b()

Then you'd write, e.g.

    selection = ternary.(x > y, exp1, exp2)

without worrying about side effects of exp1 and exp2 both getting
evaluated.




More information about the Python-list mailing list