|, for Mixed Array and Map [editor/fennel-macros/bar]

In my opinion, it is an anti-feature that Lua mixes arrays and maps, seeing them as tables. Fennel authors agree with me, so they didn’t include a syntax for mixed tables. Most of the time it’s fine, until you find that some libraries and plugins consume data in this shape.

It’s okay for me if the data looks like {elem_at_1, key = value, ...} since {1 elem_at_1 :key value ...} is not too bad, but I’m not going to accept {1 x 2 y 3 z :k v} because it feels redundant and noisy. So I made a simple macro for this case:

(fn | [& args]
  (let [len (length args)]
    (table.move args 1 (- len 1) 1 (. args len))))

Usage:

(| 1 2 3 {:a 4 :b 5})

which translates to

{1, 2, 3, a = 4, b = 5}

in Lua.

The implementation is trivial, but it took me some time to come up with this name which is short and pretty enough to be practical.