It can be useful to bind a name to an argument and destructure it at the same time. Haskell's pattern matching allows this with the syntax: f xs@(x1:x2:rest) = ... -- do something with xs, x1, x2 and rest
That receives a list named xs, plucks the first 2 elems into x1 and x2, and leaves the rest in `rest'.Arc isn't bad at this but it's nice to have it integrated into the definition. Currently: (def f (xs)
(let (x1 x2 . rest) xs
...))
I haven't thought up any nice syntax but something like this may work: (def f (<xs (x1 x2 . rest)>)
...)
An example of this making code shorter is a fn for updating some structure stored in a list. (def newstruct (st other args)
(let (tag a b c d) st
(if (< a b)
(struct tag (+ a other) b c (cons d args))
st)))
could become: (def newstruct (<st (tag a b c d)> other args)
(if (< a b)
(struct tag (+ a other) b c (cons d args))
st))
The savings may not be huge but every bit helps. |