-
-
Save pertsevds/9d6c27948bfc58c6017b5e3905c3c1ff to your computer and use it in GitHub Desktop.
Atoms/Symbols in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class atom(object): | |
"""An implementation of the atom concept, inspired by Erlang. | |
Modified from here: http://www.me.net.nz/blog/atoms-slash-symbols-in-python/ | |
""" | |
def __init__(self, a): | |
self._a = intern(a) | |
def __eq__(self, other): | |
if isinstance(other, atom): | |
return other._a == self._a | |
else: | |
return other == self._a | |
def __ne__(self, another_atom): | |
return not self.__eq__(another_atom) | |
def __repr__(self): | |
return '<atom ' + self._a + '>' | |
def __hash__(self): | |
return hash(self._a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment