From e07cef640bf48e5adaf58e08aed5f6c694dddc98 Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Fri, 9 Aug 2013 17:01:16 +0100 Subject: [PATCH] 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. --- dash.el | 7 +++++++ dev/examples.el | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/dash.el b/dash.el index 31e9a83..1107c21 100644 --- a/dash.el +++ b/dash.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))) diff --git a/dev/examples.el b/dev/examples.el index e035320..2f13ae1 100644 --- a/dev/examples.el +++ b/dev/examples.el @@ -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)