nathanmarz/storm — pull request #36 by twpayne (2011-11-02 11:21:02+00:00)
Title: Add lettuple macro

This pull request adds a `lettuple` macro which provides a convenient way for unpacking tuples in bolts. It saves you from having to manage indices, and allows you to conveniently specify per-value transformations.

Example:

(lettuple tuple [i Integer h (String read-json)]
(prn i)
(prn h))

expands to:

(let* [tuple79 tuple
i (. tuple79 getInteger 0)
h (-> (. tuple79 getString 1) read-json)]
(prn i)
(prn h))

Note that `tuple79` is a symbol generated by the compiler that will be guaranteed to be unique. The first binding of `tuple79` to `tuple` ensures that `tuple` is only evaluated once.

The syntax is:

(lettuple tuple [bindings*] exprs*)

`binding`s are of the form `var-symbol type-expr`.

If `type-expr` is not a sequence, it is combined with `"get"` to make a method name, e.g. `Integer` becomes `getInteger`, `DoesntExist` becomes `getDoesntExist`. This method is then invoked on `tuple` with the index of the binding.

If `type-expr` is a sequence, the first element of the sequence is treated as above, and the remaining arguments are threaded with `->`. See the example above.