2

I am looking to see if there is prior work, or design ideas for implementing pattern-matched guard statements in a very natural format for python programmers.

For those not familiar with pattern matching in SCALA, Erlang, or F#

They all have constructs similiar to:

When (pattern == condition) then invoke( behavior)

This is also very similiar to trigger-stored-procedure techniques in Databases.

What we want to do is create an agent-based system, where there is a large shared memory, with lots of binary structs (python has good modules for this). Which has many attached guard-statement rules, that will fire when the values match the pattern (we will have monitors that watch when structs are modified).

Has anyone seen prior work of this nature? The goal is to get something that is quite natural to a python programmer, not force SCALA, GO, Erlang, F#, etc on python folks.

We have our own ideas, but I would love to see what the community might have already done along these lines.

Community
  • 1
  • 1
Dr.YSG
  • 7,171
  • 22
  • 81
  • 139
  • Do you mean something like [this](http://www.grantjenks.com/docs/pypatt-python-pattern-matching/)? That page also lists about a dozen alternatives – evan.oman Nov 15 '16 at 16:42
  • Interesting. I'm guessing this was withheld from the language because it can be implemented with some combination of `if`/`elif`/`else`/`while`/`__eq__` -- There's probably something in the python mailing list about it. Edit: [found one](https://mail.python.org/pipermail/python-ideas/2015-April/032922.html) See also: [this blog post](http://stupidpythonideas.blogspot.com/2014/08/a-pattern-matching-case-statement-for.html) -- Of course, that hasn't stopped anybody from implementing them. – sytech Nov 15 '16 at 16:42

0 Answers0