[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Proposed Common LISP Function (forwarded)

Please return your comments on the enclosed proposal no later
than February 30.  A ballot is enclosed for your convenience.

	O f f i c i a l   B a l l o t  -  F e b r u a r y   1 9 8 3

		( )  Yes		( )  No


- - - - Begin forwarded message - - - -
Mail-From: CMUFTP host CMU-CS-PT received by CMU-CS-A at 21-Feb-83 14:14:47-EST
Received: from CMU-CS-C by CMU-CS-PT; 21 Feb 83 14:02:55 EST
Received: ID <WHOLEY@CMU-CS-C>; 21 Feb 83 14:12:15 EST
Date: Mon, 21 Feb 1983 18:12:00 -0000
From: Skef Wholey <Wholey@CMU-CS-C>
To:   Slisp@CMU-CS-C
Subject: Newly proposed Common Lisp Function: NMapDelAssCarQ

Gee, I've been writing tons of code recently in which I've been destructively
MapCar'ing and DelAssQ'ing at the same time.  Common Lisp has neither NMapCar
(which destructively modifies the list passed to it to build the result) nor
DelAssQ (a good old MacLisp function).  But NMapDelAssCarQ is essential to my
work.  Here's a proposed definition (which comiles into less than 50 Spice Lisp

;;; -*- Lisp -*-
;;; NMapDelAssCarQ for Common Lisp.

(defun nmapdelasscarq (function item list)
  "NMapDelAssCarQ cdrs down the given List.  If the car of the car of the list
  is EQ to the given Item, the car is spliced out of the list, and the Function
  is called with it's car.  A result is built from those function calls using
  the deleted conses.  This result and the altered List are returned as
  multiple values."
  (let ((map-result (list nil))
	(del-result list))
    (do ((list list (cdr list))
	 (map-splice map-result)
	 (del-splice ()))
	((atom list)
	 (rplacd map-splice nil))
      (cond ((eq item (car list))
	     (cond ((null del-splice)
		    (setq map-splice
			  (cdr (rplacd map-splice
				       (rplaca (car list)
					       (funcall function (car list))))))
		    (setq list (cdr list)))
		    (rplacd del-splice (cdr list)))))
	    (t (setq del-splice list))))
    (values (cdr map-result) del-result)))

In addition, it might be useful to define NMapDelAssCarQ*, which is like
NMapDelAssCarQ, but returns the values in reverse order.


- - - - End forwarded message - - - -