A critic of Guido's blog on Python's lambda

Alexander Schmolck a.schmolck at gmail.com
Fri May 12 16:06:29 EDT 2006


Ken Tilton <kentilton at gmail.com> writes:

> Alexander Schmolck wrote:
> > jayessay <nospam at foo.com> writes:
> >
> 
> >>"Michele Simionato" <michele.simionato at gmail.com> writes:
> >>
> >>
> >>>I was interested in a proof of concept, to show that Python can
> >>>emulate Lisp special variables with no big effort.
> >>
> >>OK, but the sort of "proof of concept" given here is something you can
> >> hack up in pretty much anything.
> 
> > Care to provide e.g. a java equivalent?
> 
> 
> I think the point is that, with the variable actually being just a string and
> with dedicated new explicit functions required as "accessors", well, you could
> hack that up in any language with dictionaries. 

Great -- so can I see some code? Can't be that difficult, it takes about 10-15
lines in python (and less in scheme).

> It is the beginnings of an interpreter, not Python itself even feigning
> special behavior.
> 
> 
> perhaps the way to go is to take the Common Lisp:
> 
>      (DEFVAR *x*)
> 
>      *x* = special_var(v=42) ;; I made this syntax up
> 
> that could make for cleaner code:
> 
>      *x*.v = 1
> 
>      print *x*.v -> 1
> 
> (Can we hide the .v?) 

I'd presumably write special variable access as something like:

with specials('x','y','z'):
     special.x = 3 + 4
     special.y = special.x + 10
     ...

I haven't tested this because I haven't got the python 2.5 alpha and won't go
through the trouble of installing it for this usenet discussion, but I'm
pretty sure this would work fine (I'm sure someone else can post an
implementation or prove me wrong). I also can't see how one could sensibly
claim that this doesn't qualify as an implementation of dynamically scoped
variables. Doesn't look any worse to me than

    (let (x y z)
         (declare (special x y z))
         ...)

-- in fact it looks better.

> But there is still the problem of knowing when to revert a value to its
> prior binding when the scope of some WITH block is left.

Can you explain what you mean by this statement? I'm not quite sure but I've
got the impression you're a possibly confused. Have you had a look at
<http://docs.python.org/dev/whatsnew/pep-343.html> or some other explanation
of the with statement?

> Of course that is what indentation is for in Python, so... is that extensible
> by application code? 

The meaning of indentation? No.

> Or would this require Python internals work?




More information about the Python-list mailing list