For example in the definition of -first
we have:
(--first (funcall pred it) list))
Naturally the meaning of "it" is very hard to google or search in the manual.
For example in the definition of -first
we have:
(--first (funcall pred it) list))
Naturally the meaning of "it" is very hard to google or search in the manual.
Actually it's right there in the manual: https://github.com/magnars/dash.el#anaphoric-functions.
If you're using lispy, starting with:
;; anaphoric version
(--map (* it it) '(1 2 3 4))
and the point before (--map
, you can press xf to call lispy-flatten
and obtain:
;; anaphoric version
(mapcar (lambda (it) (* it it)) (quote (1 2 3 4)))
It's a bit more complex with this code, since dash is too eager to delegate and postpone:
(--reduce (max it acc) '(1 2 3 4))
After xfM:
(let ((list-value (quote (1 2 3 4))))
(if list-value (--reduce-from (max it acc)
(car list-value)
(cdr list-value))
(let (acc it)
(max it acc))))
After fjfxfM:
(let ((list-value (quote (1 2 3 4))))
(if list-value (let ((acc (car list-value)))
(--each (cdr list-value)
(setq acc (max it acc)))
acc)
(let (acc it)
(max it acc))))
After fjxfM:
(let ((list-value (quote (1 2 3 4))))
(if list-value (let ((acc (car list-value)))
(let ((list (cdr list-value))
(it-index 0))
(while list (let ((it (car list)))
(setq acc (max it acc)))
(setq it-index (1+ it-index))
(!cdr list)))
acc)
(let (acc it)
(max it acc))))
Suffice to say, that it
is the implicit iterable var and acc
is
the implicit accumulator var.
At one point, I tried to add a short lambda patch to Emacs that would enable this notation, which I think is simpler than anaphoric macros:
(map #(* % %) '(1 2 3 4))
(cl-reduce #(max %1 %2) '(1 2 3 4))
However, it kind of went nowhere.