Theoretical question about Lambda
Paul Foley
see at below
Tue May 7 22:03:43 EDT 2002
On Tue, 7 May 2002 08:25:21 -0400, Steve Holden wrote:
> "Paul Foley" <see at below> wrote in message
> news:m2y9ewu4fe.fsf at mycroft.actrix.gen.nz...
>> def test():
>> print x
>> x = 42
>>
>> raises an error because the (empty, error-causing) binding for x is
>> already in force when the "print" statement executes, before the "="
>> is even reached.
>>
> So, it appears that you think binding is the implicit declaration assoicated
> with assignment to a name inside a particular scope? If so, it would seem
Binding is the association between a name and a chunk of memory which
is used to store a PyObject pointer, if you insist on looking at it
that way. Assignment is just changing the value stored there.
[This is the same meaning of "assignment" as in any other language;
Lisp, C, whatever; there's nothing particularly unusual about Python!]
> Consider namespaces as dictionaries. I *know* they aren't all implemented as
> dictionaries, but bear with me.
> You seem to be insisting that an operation is only a "binding" when the key
> (name) does not already exist in the dictionary (namespace). If the
> dictionary (namespace) already contains the key (name) then it's not a
> rebinding, it's an "assignment".
Well, of course -- because you don't add new names to that dictionary
during the life of your code; you make a new dictionary when you make
a new binding! If a name doesn't exist in one dictionary, you have to
look it up in the next-outermost dictionary (either the module dict or
whatever scope the current one is nested in, depending on whether or
not you have nested_scopes turned on), and so on. If a particular
name isn't in any of those dictionaries, there's no binding for it; if
it is present, changing the value associated with it would be
assignment [but Python won't let you assign into any but the outermost
(i.e., current) dictionary; instead, it automatically creates a new
dictionary (binding)]
--
You don't have to agree with me; you can be wrong if you want.
(setq reply-to
(concatenate 'string "Paul Foley " "<mycroft" '(#\@) "actrix.gen.nz>"))
More information about the Python-list
mailing list