In article <358b227c-d836-4243-b79a-57258590a...@a10g2000pre.googlegroups.com>,
metal  <metal...@gmail.com> wrote:
>
>I want to get pattern matching like OCaml in python(ref:http://
>en.wikipedia.org/wiki/Tagged_union)
>
>I consider the syntax:
>
>def decl():
>       def Plus(expr, expr): pass
>       def Minus(expr, expr): pass
>       def Times(expr, expr): pass
>       def Divide(expr, expr): pass
>       def Value(str): pass
>       @enum
>       def expr(Plus, Minus, Times, Divide, Value): pass
>       declare_types(locals())
>
>def f(e):
>       def _Plus(l, r):
>               return '(%s+%s)' % (l, r)
>       def _Minus(l, r):
>               return '(%s-%s)' % (l, r)
>       def _Times(l, r):
>               return '(%s*%s)' % (l, r)
>       def _Divide(l, r):
>               return '(%s/%s)' % (l, r)
>       def _Value(x):
>               return x
>       try:
>               match(e, locals()) # visitor pattern
>       except NoMatchedError:
>               pass

Perhaps you want to define what match() does?
-- 
Aahz (a...@pythoncraft.com)           <*>         http://www.pythoncraft.com/

The best way to get information on Usenet is not to ask a question, but
to post the wrong information.  
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to