Version 0.1.4 released
Well, another release with a load more improvements! The highlights:
- Add support for module level documentation.
- Further improvements to how variables are inlined, meaning even more constant expressions get folded.
- Pattern matching! Ahahahr. Hype! Hype!
Right, if you’ve never seen pattern matching before, then you can think of it as a switch statement on steroids. In short, it allows you to compare the specified object against a series of “patterns”: these can be constants, descriptions of a list, or arbitrary functions. For instance, the pattern:
(case x
[((?x ?y) . ?xs) (print! "List where the head has two entries" x y (pretty xs))]
[(?x . ?xs) (print! "List with head and tail" (pretty x) (pretty xs))]
[() (print! "Empty list")])
- If you run it against a list looking something like
((1 2) 3 4 5)
then the first pattern will match, withx = 1
,y = 2
,xs = (3 4 5)
as it has the same “layout”. - If it is a list with at least one entry (such as (1 2 3)) then the second pattern matches, giving
x = 1
,xs = (2 3)
. - If the above pattern didn’t work, then we must have an empty list, meaning the third pattern matches.
As you can see, this is much shorter than the equivalent Lua (or Lisp without match) code. For the full capabilities of the pattern matching library, see the documentation.