A modern list API for Emacs. No
'cl
required.
See the end of the file for license conditions.
See the NEWS.md
file.
Dash is available on GNU ELPA, GNU-devel
ELPA, and MELPA,
and can be installed with the standard command package-install
:
M-x package-install RET dash RET
See (info "(emacs) Package Installation")
.
Alternatively, you can just dump dash.el
in your load-path
somewhere. See (info "(emacs) Lisp Libraries")
.
Add something like this to the library's headers:
;; Package-Requires: ((dash "2.19.1"))
See (info "(elisp) Library Headers")
.
Font lock of special Dash variables (it
, acc
, etc.) in Emacs Lisp
buffers can optionally be enabled with the autoloaded minor mode
dash-fontify-mode
. In older Emacs versions which do not dynamically
detect macros, the minor mode also fontifies Dash macro calls.
To automatically enable the minor mode in all Emacs Lisp buffers, just
call its autoloaded global counterpart global-dash-fontify-mode
,
either interactively or from your user-init-file
:
(global-dash-fontify-mode)
While editing Elisp files, you can use C-h S
(info-lookup-symbol
)
to look up Elisp symbols in the relevant Info manuals (see (emacs) Info Lookup
).
To enable the same for Dash symbols, use the command
dash-register-info-lookup
. It can be called directly when needed,
or automatically from your user-init-file
. For example:
(with-eval-after-load 'info-look
(dash-register-info-lookup))
All functions and constructs in the library use a dash (-
) prefix.
The library also provides anaphoric macro versions of functions where
that makes sense. The names of these macros are prefixed with two
dashes (--
) instead of one.
While -map
applies a function to each element of a list, its
anaphoric counterpart --map
evaluates a form with the local variable
it
temporarily bound to the current list element instead. For
example:
(-map (lambda (n) (* n n)) '(1 2 3 4)) ; Normal version.
(--map (* it it) '(1 2 3 4)) ; Anaphoric version.
The normal version can of course also be written as follows:
(defun my-square (n)
"Return N multiplied by itself."
(* n n))
(-map #'my-square '(1 2 3 4))
This demonstrates the utility of both versions.
Functions in this category take a transforming function, which is then applied sequentially to each or selected elements of the input list. The results are collected in order and returned as a new list.
-map
(fn list)
-map-when
(pred rep list)
-map-first
(pred rep list)
-map-last
(pred rep list)
-map-indexed
(fn list)
-annotate
(fn list)
-splice
(pred fun list)
-splice-list
(pred new-list list)
-mapcat
(fn list)
-copy
(list)