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.


Comments and Discussion is provided by Disqus. They are tracking site and user interaction. Please refer to their privacy policy for information about data usage and retention. If you still want to look at comments or comment yourself, enable disqus by clicking here.

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

links

social

Theme based on notmyidea