Published: Thu 05 November 2015
Updated: Thu 05 November 2015
Revisions: Thu 05 November 2015
Thu 05 November 2015

dogelang adding pattern matching

If you haven't read about dogelang, you really should. It is python with haskell-syntax where you can use all python modules. So basically coffee-script but for a language that is already useful. And python bytecode is emitted instead of first compiling to python itself, but that just as a side-node.

On my behest, the developer of dg added pattern matching so that in an if-condition a tuple-unpacking-expression does not raise an exception if the unpacking fails but returns false.

Therefore one can now implement their own zip and list-constructor in the following manner:

zip = x' y' -> if
  ([x, *xs], [y, *ys] = x', y') =>
    yield (x, y)
    yield from $ zip xs ys
  otherwise => yield from ()

list = x' -> if
  ([] = x') => []
  ([x, *xs] = x') => [x] + list xs

This looks almost like haskell's case-pattern-matching but not quite, so it is sure to annoy every haskell-programmer.

You might need to execute python3 -m dg -b once after installing/updating dg to rebuild the interpreter/compiler-bundle with this feature.

In other news: It is quite likely that I will hold a small talk about dogelang at Leipzig's next Haskell conference HaL-10.

Previous: Upgrading Fedora 22 to 23 , Next: Musings on Graph Isomorphism pre-results



Theme based on notmyidea