all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Thien-Thi Nguyen <ttn@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: some more material on the Lisp data/code psychedelia
Date: Sat, 04 Jan 2014 21:13:26 +0100	[thread overview]
Message-ID: <87ob3rpkt5.fsf@zigzag.favinet> (raw)
In-Reply-To: <87sit31qt7.fsf@nl106-137-194.student.uu.se> (Emanuel Berg's message of "Sat, 04 Jan 2014 20:37:15 +0100")

[-- Attachment #1: Type: text/plain, Size: 840 bytes --]

() 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

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

  reply	other threads:[~2014-01-04 20:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-04 19:37 some more material on the Lisp data/code psychedelia Emanuel Berg
2014-01-04 20:13 ` Thien-Thi Nguyen [this message]
     [not found] ` <mailman.11016.1388866201.10748.help-gnu-emacs@gnu.org>
2014-01-04 20:24   ` Emanuel Berg
2014-01-04 23:40     ` Emanuel Berg
2014-01-17  1:29       ` Emanuel Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ob3rpkt5.fsf@zigzag.favinet \
    --to=ttn@gnu.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.