A possible lazy evaluation system?

Michael Hudson mwh at python.net
Tue Mar 11 14:46:03 CET 2003


Stephen Horne <intentionally at blank.co.uk> writes:

> I one mentioned that I thought it was sensible to label function
> parameters in some way to modify the call mechanism. The obvious
> analogy is 'var' parameters in Pascal, though I was thinking more of a
> 'lazy' modifier.
> 
> It occured to me that, instead of a fully lazy parameter system, a
> simpler approach may be to lable parameters as lambdas.
> 
> You could then write something like...
> 
>   def IF (c, lambda x, lambda y) :
>     if c :
>       return x ()
>     else :
>       return y ()
> 
> ...and call it with...
> 
>   IF (y != 0, x/y, 1000000)
> 
> The 'lambda' asserts that the parameters expression gets converted to
> a parameterless lambda instead of being evaluated immediately.
> 
> The same notation in declarations of __call__ could provide the same
> capability to all callables.
> 
> The question is - is this a sane suggestion?

No :-)

Two problems spring to mind: at compile you don't know whether the
callable evaluates all it arguments or not.  I can't really see a sane
implementation strategy, though where there's a will there's no doubt
a way.

Also, as I said a while back, there's a reason for this table:

                   |no side effects| side effects  |
    ---------------+---------------+---------------+
                   | ML(ish)       | Python, C,    |
        strict     | probably some | many others   |
                   |  others       |               |
    ---------------+---------------+---------------+
        lazy       |  Haskell      | <gaping void> |
    ---------------+---------------+---------------+

Cheers,
M.

-- 
  ... with these conditions cam the realisation that ... nothing
  turned a perfectly normal healthy individual into a great political
  or military leader better than irreversible brain damage.
                   -- The Hitch-Hikers Guide to the Galaxy, Episode 11




More information about the Python-list mailing list