[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: New to elisp, learning by doing
From: |
Oliver Scholz |
Subject: |
Re: New to elisp, learning by doing |
Date: |
Tue, 18 Feb 2003 11:26:26 +0100 |
User-agent: |
Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.2 (i386-msvc-nt5.1.2600) |
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é!
- New to elisp, learning by doing, John Rabkin, 2003/02/16
- Re: New to elisp, learning by doing, Christopher J. White, 2003/02/16
- Re: New to elisp, learning by doing, Kai Großjohann, 2003/02/17
- Re: New to elisp, learning by doing, Hannu Koivisto, 2003/02/17
- Re: New to elisp, learning by doing,
Oliver Scholz <=
- Re: New to elisp, learning by doing, Kevin Rodgers, 2003/02/17