We can use :let
in for
to define local variable like this
(for [i (range 5)
:let [inc-i (inc i)]]
[i inc-i])
;;=> ([0 1] [1 2] [2 3] [3 4] [4 5])
Otherwise, if we specified :let
as first element, it causes an macro expansion error.
(for [:let [range-end 5]
i (range range-end)
:let [inc-i (inc i)]]
[i inc-i])
;;=> Syntax error macroexpanding for at (*cider-scratch*:555:1).
;; Can't pop empty vector
Of course, in this case, we should have wrapped for
in let
. However, I'm curious whether making :let
available only for second and subsequent elements is intended behavior as part of the public interface.