Google
 

Trailing-Edge - PDP-10 Archives - clisp - clisp/upsala/keyword.clisp
There are no other files named keyword.clisp in the archive.
;;; This is a -*-Lisp-*- file.
;;;
;;; **********************************************************************
;;; This code was written as part of the Spice Lisp project at
;;; Carnegie-Mellon University, and has been placed in the public domain.
;;; If you want to use this code or any part of Spice Lisp, please contact
;;; Scott Fahlman (FAHLMAN@CMUC). 
;;; **********************************************************************
;;;
;;; Keyword parsing macro for Spice Lisp.
;;; Written by Skef Wholey.
;;; Rewritten by Walter van Roggen, 26 December 1982.
;;;
;;; This macro must be part of the compiler.
;;;
;;; **********************************************************************
;;;
;;; With-Keywords <Option-List> <Key-List> &rest <Body>		[Macro]
;;;
;;; <Option-List> is a flat list of pairs (<Name> <Value> <Name> <Value> ...)
;;; <Key-List> is a list of one or more lists of (<Name> <Var> <Default>).
;;; The <Name> is the user-visible keyword, the <Var> is the local variable
;;; to be bound to the value supplied for a given keyword, and <Default> is
;;; the value to be used if none is found in the <Option-List>. <Default>s
;;; evaluated just as they would in the variable binding part of a LET.
;;; <Option-List> is evaluated; <Key-List> is not.
;;;
;;; **********************************************************************

(in-package 'lisp)

(export '(%get-key))

;;; this is missing a check for unexpected keywords.
;;; (I have the code for it, but haven't installed it -- WvR)

;;; This is only used by TRACE now.  Don't use anywhere else.
;;; Use keyword args.  DKS

(eval-when (compile eval load)

(defmacro with-keywords (option-list key-list &rest body)
  `(let ,(mapcar #'(lambda (kl)
			`(,(cadr kl)		;var
			  (let ((rest-options (memq ',(car kl) ,option-list)))
			    (if rest-options
				(cadr rest-options)	;may return NIL
				,(caddr kl)))) )	;default
	    key-list)
	. ,body ))

)


(defun %get-key (list key)
  "Called by compiled functions with keyword args.  CDDR down List looking
  for KEY.  If it is found, return the list fragment following the keyword.
  Else, return NIL."
  (do ((l list (cddr l)))
      ((null l) nil)
    (cond ((null (cdr l))
	   (cerror "Stick a NIL on the end and go on."
		   "Unpaired item in keyword portion of call.")
	   (rplacd l (list nil))
	   (return nil))
	  ((eq (car l) key)
	   (return (cdr l))))))