merits of Lisp vs Python

greg greg at cosc.canterbury.ac.nz
Sat Dec 16 02:21:50 EST 2006


André Thieme wrote:
>  (aif (timeConsumingCalculation)
>      (use it))

I think the answer is that you just wouldn't do
that in Python at all. Having magic variables
spring into existence in your local namespace
as a side effect of calling something is just
not Pythonic. (It is very Perlish, on the other
hand.)

The closest you might come is using the new
"with" statement like this:

   with aif(timeConsumingCalculation()) as it:
     use(it)

where the object returned by aif(x) has an
__enter__ method that raises an exception which
aborts the whole with statement if x is None,
thus avoiding executing the body. But that's
so horribly convoluted that any sane programmer
would just write it out the straightforward
way to begin with.

>  > There's a Haskell builtin called 'seq' which forces evaluation but
>  > again I'm not sure precisely how to apply it here.
> 
> So in some languages that support functional programming one needs to do
> extra work to get lazyness, while in Haskell one gets extra work if one
> doesn't want it.

Sort of, but it's more so that you can write code
that does things like I/O in what looks like a
procedural style, even though it's still purely
functional. Read about "monads" if you want to
know more -- it's truly mind-expanding (and
possibly head-exploding:-) stuff...

--
Greg



More information about the Python-list mailing list