Adding -first-item and -last-item. [magnars/dash.el#17]

`-first-item` is a trivial alias to `car`, so I used `defalias` so
there isn't the additional overhead of a function call. This has
broken `create_docs.sh`.

It seems that `defexamples` expects `symbol-function` to return an
elisp function definition, but `car` is implemented in C.
master
Wilfred Hughes 13 years ago
parent 2b200884ca
commit e07cef640b
  1. 7
      dash.el
  2. 8
      dev/examples.el

@ -27,6 +27,13 @@
;;; Code:
(defalias '-first-item 'car
"Returns the first item of LIST, or nil on an empty list.")
(defun -last-item (list)
"Returns the first item of LIST, or nil on an empty list."
(car (last list)))
(defmacro !cons (car cdr)
"Destructive: Sets CDR to the cons of CAR and CDR."
`(setq ,cdr (cons ,car ,cdr)))

@ -9,6 +9,14 @@
(defun square (num) (* num num))
(defun three-letters () '("A" "B" "C"))
(defexamples -first-item
(-first-item '(1 2 3)) => 1
(-first-item nil => nil))
(defexamples -last-item
(-last-item '(1 2 3)) => 3
(-last-item nil => nil))
(defexamples -map
(-map (lambda (num) (* num num)) '(1 2 3 4)) => '(1 4 9 16)
(-map 'square '(1 2 3 4)) => '(1 4 9 16)

Loading…
Cancel
Save