[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: some more material on the Lisp data/code psychedelia
From: |
Thien-Thi Nguyen |
Subject: |
Re: some more material on the Lisp data/code psychedelia |
Date: |
Sat, 04 Jan 2014 21:13:26 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
() Emanuel Berg <embe8573@student.uu.se>
() Sat, 04 Jan 2014 20:37:15 +0100
(defun increment-last (l)
(interactive)
(if (not l) '()
(let ((hd (car l))
(tl (cdr l)) )
(if (not tl)
(list (+ 1 hd))
(cons hd (increment-last tl) )))))
You can also use ‘last’ and ‘setcar’ (via ‘incf’) for this:
(defun increment-last (ls)
(when ls
(incf (car (last ls)))
ls))
Non-recursive means less stack required for long forms. Destructive
style is sketchy but the func is already squarely in DWR territory...
--
Thien-Thi Nguyen
GPG key: 4C807502
(if you're human and you know it)
read my lisp: (responsep (questions 'technical)
(not (via 'mailing-list)))
=> nil
pgpvcQlP6lzbM.pgp
Description: PGP signature