Skip to content

Instantly share code, notes, and snippets.

@gmarkall
Created April 25, 2011 12:12
Show Gist options
  • Save gmarkall/940425 to your computer and use it in GitHub Desktop.
Save gmarkall/940425 to your computer and use it in GitHub Desktop.
Example of very simple multiple dispatch in python
class Visitor:
def visit(self, node):
"Dispatcher function, dispatching tree type T to method _T."
meth = getattr(self, "_"+node.__class__.__name__)
meth(node)
def _Scope(self, node):
print "Scope"
def _GlobalScope(self, node):
self._Scope(node)
def _Statement(self, node):
print "Statement"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment