Ad esempio nella definizione di -firstabbiamo:
(--first (funcall pred it) list))
Naturalmente il significato di "it" è molto difficile da cercare o cercare nel manuale.
Ad esempio nella definizione di -firstabbiamo:
(--first (funcall pred it) list))
Naturalmente il significato di "it" è molto difficile da cercare o cercare nel manuale.
Risposte:
In realtà è proprio lì nel manuale: https://github.com/magnars/dash.el#anaphoric-functions .
Se stai usando lispy , a partire da:
;; anaphoric version
(--map (* it it) '(1 2 3 4))
e il punto prima (--map, è possibile premere xfper chiamare lispy-flattene ottenere:
;; anaphoric version
(mapcar (lambda (it) (* it it)) (quote (1 2 3 4)))
È un po 'più complesso con questo codice, poiché dash è troppo desideroso di delegare e posticipare:
(--reduce (max it acc) '(1 2 3 4))
Dopo 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))))
Dopo 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))))
Dopo 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))))
Basti dire che itè la var iterabile implicita ed accè l'accumulatore implicito var.
Ad un certo punto, ho provato ad aggiungere una breve patch lambda a Emacs che avrebbe abilitato questa notazione, che penso sia più semplice delle macro anaforiche:
(map #(* % %) '(1 2 3 4))
(cl-reduce #(max %1 %2) '(1 2 3 4))
Tuttavia, non è andato da nessuna parte.