all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Oliver Scholz <alkibiades@gmx.de>
Subject: Re: New to elisp, learning by doing
Date: Tue, 18 Feb 2003 11:26:26 +0100	[thread overview]
Message-ID: <u7kbxkhpp.fsf@ID-87814.user.dfncis.de> (raw)
In-Reply-To: 84of5bidgc.fsf@lucy.is.informatik.uni-duisburg.de

kai.grossjohann@uni-duisburg.de (Kai Großjohann) writes:

> Queues are not a standard Lisp datatype, I'm afraid. (Or is there an
> Emacs Lisp package for this?)

FWIW, I have the following lying around, which is stolen&adapted from
Norvig's "Paradigms of Artificial Intelligence Programming".

(defun rtfread-make-queue ()
  "Return a new, empty queue."
  (let ((queue (cons nil nil)))
    (setcar queue queue)))

(defsubst rtfread-enqueue (elt queue)
  "Put ELT to the end of QUEUE."
  (setcar queue
	  (setcdr (car queue)
		  (cons elt nil))))

(defsubst rtfread-dequeue (queue)
  "Pop the first element from the queue.
Returns the removed element."
  (prog1 (pop (cdr queue))
    (when (null (cdr queue))
      (setcar queue queue))))

(defsubst rtfread-queue-contents (queue)
  "Return the contents of QUEUE."
  (cdr queue))

(defsubst rtfread-queue-front (queue)
  "Return the first element of QUEUE."
  (car (rtfread-queue-contents queue)))

(defsubst rtfread-empty-queue-p (queue)
  "Return non-nil if QUEUE is an empty queue."
  (null (rtfread-queue-contents queue)))

(defun rtfread-queue-nconc (queue list)
  "Add the elements of LIST to the end of QUEUE."
  (setcar queue
	  (last (setcdr (car queue) list))))


    Oliver
-- 
30 Pluviôse an 211 de la Révolution
Liberté, Egalité, Fraternité!

  parent reply	other threads:[~2003-02-18 10:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-16 22:45 New to elisp, learning by doing John Rabkin
2003-02-17  2:03 ` Christopher J. White
2003-02-17  7:16 ` Kai Großjohann
2003-02-17  9:27   ` Hannu Koivisto
2003-02-18  8:02     ` Kai Großjohann
2003-02-17 18:24   ` Ehud Karni
     [not found]   ` <mailman.2034.1045507046.21513.help-gnu-emacs@gnu.org>
2003-02-17 19:50     ` Kai Großjohann
2003-02-18 10:26   ` Oliver Scholz [this message]
2003-02-17 18:47 ` Kevin Rodgers

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=u7kbxkhpp.fsf@ID-87814.user.dfncis.de \
    --to=alkibiades@gmx.de \
    /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.