;;; 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.
;;; Spice Lisp is currently incomplete and under active development.
;;; 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.
;;;
;;; **********************************************************************

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

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

)