Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make symbols of a given name always the same symbol.

  • Loading branch information...
commit 24521bb52cecfdecfb6852ad6e24a658eedd77b5 1 parent 9d62e1e
@plathrop authored
Showing with 9 additions and 2 deletions.
  1. +9 −2 pdlisp/
11 pdlisp/
@@ -19,16 +19,23 @@
class Symbol(object):
Simple class to differentiate lisp symbols from the strings that name
- them.
+ them. Each Symbol of a given name is a singleton, calling Symbol(<name>)
+ will always give you the same Symbol object.
+ _symbols = {}
def __init__(self, name):
if valid_symbol_name(name): = name
raise LispSyntaxError('Invalid symbol name: %s' % name)
def __repr__(self):
return "Symbol<%s>" %
+ def __new__(cls, name, *args, **kwargs):
+ if name in cls._symbols:
+ return cls._symbols.get(name)
+ sym = super(Symbol, cls).__new__(cls, name, *args, **kwargs)
+ cls._symbols[name] = sym
+ return sym
def symbol(name):
Please sign in to comment.
Something went wrong with that request. Please try again.