[Python-3000] symbols?

Kendall Clark kendall at monkeyfist.com
Tue Apr 11 21:30:13 CEST 2006


On Apr 11, 2006, at 2:18 PM, Martin v. Löwis wrote:

> I think it's as simple as the the LISP symbols, except when it comes
> to name binding.

Common Lisp symbols are a lot more complex in that they are not  
globally unique, can be uninterned, can carry data, get automagically  
upcased, have property lists, etc. etc.

> 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_]

Yes, I wrote exactly this regex in the message I was working on.

> As you can put them into source code, you also need support
> for marshalling them.

Yes.

> That's about all that he has specified so far.

Correct.

> Open issues
> then are:
>
> - does .name include the colon or not?

No. (And its repr has no quote marks, either.)

> - can you pass them to getattr, instead of strings?

Haven't thought about that at all.

> 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).

Thanks, Martin. That is, in fact, pretty much what I'd like to see in  
Py3K, modulo the issue about getattr.

Cheers,
Kendall




More information about the Python-3000 mailing list