11

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.

Malabarba
  • 22,878
  • 6
  • 78
  • 163
  • 4
    Precisely the question one should ask, and a reasonable general criticism of anaphoric this-and-that. In **Emacs**, at least (it is "the self-documenting editor"), ***each doc string*** of an anaphoric thingie should clearly call it out, even if that seems verbose to some who are familiar with it (sic), and even if it is well documented in a manual. (Just one opinion.) – Drew Mar 03 '15 at 15:29

1 Answers1

10

Actually it's right there in the manual: https://github.com/magnars/dash.el#anaphoric-functions.

Update: inspecting and flattening macros

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.

abo-abo
  • 13,943
  • 1
  • 29
  • 43