[Python-3000] symbols?

"Martin v. Löwis" martin at v.loewis.de
Tue Apr 11 20:18:30 CEST 2006


Barry Warsaw wrote:
> To be fair, I think Ruby stole the idea and syntax from Lisp. It's an
> interesting idea, but I'd like to understand exactly what you mean by "a
> Python symbol". Can you give more detail about your idea, perhaps as a
> pseudo-PEP?

I think it's as simple as the the LISP symbols, except when it comes
to name binding. What the OP apparently wants is this:
class Symbol(object):
 def __init__(self, str):
 self.name = name
symbols = {}
def make_symbol(str):
 try:
 return symbols[str]
 except KeyError:
 symbols[str] = result = Symbol(str)
In addition, he wants literals for the symbol type, namely
 :[A-Za-z_][A-Za-z0-9_]
As you can put them into source code, you also need support
for marshalling them.
That's about all that he has specified so far. Open issues
then are:
- does .name include the colon or not?
- can you pass them to getattr, instead of strings?
Everything else follows from this spec (I hope). Symbols
compare for identity, are hashable, meant to be immutable
(Bug: the specification allows for mutation; the implementation
shouldn't).
Regards,
Martin


More information about the Python-3000 mailing list

AltStyle によって変換されたページ (->オリジナル) /