why no ++?

Bengt Richter bokr at accessone.com
Tue Aug 21 16:33:06 EDT 2001


On 19 Aug 2001 18:28:23 GMT, Bernd.Nawothnig at t-online.de (Bernd Nawothnig) wrote:
[...]
>
>Is there a possibility in Python to return a symbol? In other words: is it
>possible to write:
>
>a() = 5
>
>if the function a() returns a symbol like in Lisp:
>
>(defun a() 'x)
>(set (a) 5) ; x is now bound to 5
>
[...]

I too was thinking that a symbol object might be a useful thing.
Say it was created with the expression
    sym = .
which would work a lot like
    sym='sym'
except there would be no need for a separate string value. The binding
could be changed as usual, of course:
    sym = .
    sym = 123
but
    d = {}
    d[sym]=123
    d['sym']=123
would make two entries.
    type(sym) would presumably return
    <type 'symbol'>
and symbol('sym') would return a symbol object, and writing
    sym = symbol('sym')
would be equivalent to
    sym = .
It would also be ok to write
    spam = symbol('sym')

Presumably
    str(sym)
would return
    sym
not
    'sym'
and
    print sym
would return
    <symbol sym>
as would
    print spam
given the assignment preceding above.

You could get a list of symbol objects by, e.g.,
    map(symbol,'abc')
which would (not currently implemented, obviously) return
    [<symbol a>, <symbol b>, <symbol c>]

It should be legal to have a symbol like this be either key
or value or both in a dictionary, so
    d={'a':'a', symbol('a'):symbol('a')}
should be ok.

I would think these kinds of symbols could play a useful role
as elements of an actual set type.

Hm, should symbol('') be an alias for None ?

If you extended the interpretation of the () trailer when it
was suffixed to a symbol whose value was a symbol object,
you could have the effect of your (grabbed and repeated from above)

>(defun a() 'x)
>(set (a) 5) ; x is now bound to 5

by writing
    a = symbol('x')
    a() = 5

IOW, a=5 would rebind a normally, but a() would access the symbol object
from symbol('x') and rebind that instead. So () would be like dereferencing
a sym link.





More information about the Python-list mailing list