I extended PS's optional and keyword arguments to handle supplied-p parameters. Patch below.<br><br>Daniel<br><br><br>From b2c6b36e0c3582be703f861170fd6d2ea9cba4c6 Mon Sep 17 00:00:00 2001<br>From: Daniel Gackle <<a href="mailto:danielgackle@gmail.com">danielgackle@gmail.com</a>><br>
Date: Fri, 8 May 2009 15:13:18 -0600<br>Subject: [PATCH 2/2] Added support for supplied-p parameters to optional and keyword arguments.<br><br>---<br> src/special-forms.lisp | 24 ++++++++++++++----------<br> 1 files changed, 14 insertions(+), 10 deletions(-)<br>
<br>diff --git a/src/special-forms.lisp b/src/special-forms.lisp<br>index a6d363f..7ac8e77 100644<br>--- a/src/special-forms.lisp<br>+++ b/src/special-forms.lisp<br>@@ -252,9 +252,11 @@ Syntax of key spec:<br> (values (if (symbolp spec) spec (first spec))<br>
(when (listp spec) (second spec))))<br> <br>-(defpsmacro defaultf (place value)<br>- `(when (=== ,place undefined)<br>- (setf ,place ,value)))<br>+(defpsmacro defaultf (name value suppl)<br>+ `(progn<br>
+ ,@(when suppl `((var ,suppl t)))<br>
+ (when (=== ,name undefined)<br>+ (setf ,name ,value ,@(when suppl (list suppl nil))))))<br> <br> (defun parse-extended-function (lambda-list body &optional name)<br> "Returns two values: the effective arguments and body for a function with<br>
@@ -264,11 +266,12 @@ the given lambda-list and body."<br> ;; list of variable names, and you have access to the arguments variable inside the function:<br> ;; * standard variables are the mapped directly into the js-lambda list<br>
;; * optional variables' variable names are mapped directly into the lambda list,<br>- ;; and for each optional variable with name v and default value d, a form is produced<br>- ;; (defaultf v d)<br>+ ;; and for each optional variable with name v, default value d, and<br>
+ ;; supplied-p parameter s, a form is produced (defaultf v d s)<br> ;; * keyword variables are not included in the js-lambda list, but instead are<br> ;; obtained from the magic js ARGUMENTS pseudo-array. Code assigning values to<br>
- ;; keyword vars is prepended to the body of the function.<br>+ ;; keyword vars is prepended to the body of the function. Defaults and supplied-p<br>+ ;; are handled using the same mechanism as with optional vars.<br>
(declare (ignore name))<br> (multiple-value-bind (requireds optionals rest? rest keys? keys allow? aux? aux<br> more? more-context more-count key-object)<br>@@ -282,8 +285,9 @@ the given lambda-list and body."<br>
(mapcar #'parse-optional-spec optionals))))<br> (opt-forms<br> (mapcar #'(lambda (opt-spec)<br>- (multiple-value-bind (var val) (parse-optional-spec opt-spec)<br>
- `(defaultf ,var ,val)))<br>+ (multiple-value-bind (var val suppl)<br>+ (parse-optional-spec opt-spec)<br>+ `(defaultf ,var ,val ,suppl)))<br>
optionals))<br> (key-forms<br> (when keys?<br>@@ -291,11 +295,11 @@ the given lambda-list and body."<br> (with-ps-gensyms (n)<br> (let ((decls nil) (assigns nil) (defaults nil))<br>
(mapc (lambda (k)<br>- (multiple-value-bind (var init-form keyword-str)<br>+ (multiple-value-bind (var init-form keyword-str suppl)<br> (parse-key-spec k)<br>
(push `(var ,var) decls)<br> (push `(,keyword-str (setf ,var (aref arguments (1+ ,n)))) assigns)<br>- (push (list 'defaultf var init-form) defaults)))<br>
+ (push (list 'defaultf var init-form suppl) defaults)))<br> (reverse keys))<br> `(,@decls<br> (loop :for ,n :from ,(length requireds)<br>
-- <br>1.6.1<br><br><br>