question about what lamda does
Bruno Desthuilliers
onurb at xiludom.gro
Thu Jul 20 11:06:49 EDT 2006
danielx wrote:
(snip)
> Python's lambda really can't be as powerful as Lisp's because Python
> does not have expressions that do case analysis (this is not lambda's
> fault, of course ;). The reason is that you really want to put each
> case on its own set of lines. This enhances readability at the expense
> of terseness. Since Python's statements are terminated by a newline, it
> would be rather awkward to have a kind of expression where good style
> calls for it to be spread out accross multiple lines.
>
> You can try to simulate these kinds expressions using into a list or
> dictionary, but this becomes rather messy. I think the only way to get
> this done properly is to use eval. For example:
>
> def recursiveFunction(args):
> ... # do stuff...
> choices = { True:"0", False:"recurisveFunction(newArgs)" }
> return eval( choices[predicate] )
Why do you want to use eval here ?
> The reason that you need eval is that you want to prevent any cases
> from being executed until you decide which one you want.
What about:
def recursiveFunction(args):
... # do stuff...
... # that defines 'newArgs' and 'predicate' of course ...
return (recursiveFunction, lambda x: 0)[predicate](newArgs)
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"
More information about the Python-list
mailing list