Skip to content

Instantly share code, notes, and snippets.

@pertsevds
Forked from Morgul/atom.py
Created July 13, 2021 19:50
Show Gist options
  • Save pertsevds/9d6c27948bfc58c6017b5e3905c3c1ff to your computer and use it in GitHub Desktop.
Save pertsevds/9d6c27948bfc58c6017b5e3905c3c1ff to your computer and use it in GitHub Desktop.
Atoms/Symbols in Python
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