[Python-Dev] Re: PEP 308

Roman Suzi rnd@onego.ru
Sun, 9 Feb 2003 23:37:57 +0300 (MSK)


Inline if is about extending Python's functional paradigm by adding a function
those two arguments (out of 3) are evaluated only if needed.

Isn't it better to provide more general mechanism so arbitrary function could
evaluate it's arguments on demand? (Or what about evaluating everything
lazily?)

Then everybody could build his/her own if-function and much more.

(LISPers will be happy ;-)

This "inline if" debate is, IMHO, dual to "code thunks" thread at python-dev,
because in one case we want full-scale lambdas, and in another one - ifs,
reduced to fit expression. Both do not have nice syntactic solutions in spirit
of Python.

This is symptomatic. More bridges are needed between control statements
and expressions.

Why only if deserves inline version?
What about

k = try a/b except c
f = try open(filename) except sys.stdin
lst1 = while cond(i) i

Some bridges are here already:

[f(i) for i in lst]

In short:

 Expression - Statement
     [for]  - for
   [for if] - for:\n if ...
 recursion? - while
    PEP308! - if-else
     lambda - def
       eval - exec
          ? - class
          ? - try-except
          ? - raise
 __import__ - import   (?)
   reload() - ?
 not needed - return
          ? - yield
   .write() - print
          ? - del
       None - pass
          ? - =

Of course, there are only similarities between these structures, but on the
whole it could be noted that functional side is poorer than imperative one.

General laziness present in imperative side is missing in expression (thus
functional) side: arguments get evaluated more often than not. Only operations
like 'or' and 'and' (and chained comparisons) add some laziness to
expressions.

Please, do not understand me as asking for features. This posting of mine is
an attempt to take more general view of the Python landscape today and
development directions under discussion.

If (ever) lazy execution will be Python reality, Python will be great choice
for mathematical programming people with their fancy search algorithms.  
(Anybody who knows Amanda/Miranda programming languages will understand what I
am speaking about).


Sincerely yours, Roman Suzi
-- 
rnd@onego.ru =\= My AI powered by Linux RedHat 7.3