Re: partitioning keyword arguments
Ah, great! Now I can do what works /and/ do it in good conscience!
Thanks!
On 4/8/07, Brian Downing <bdowning@lavos.net> wrote:
> On Sun, Apr 08, 2007 at 05:49:08PM -0400, Taylor, Joshua wrote:
> > Now, this allows me to do exactly what I want to do, but I have to
> > wonder whether this is considered poor style. I can see that if
> > misused, the possibilities for obfuscation are huge, but perhaps used
> > carefully this is just such a case as it was designed for? I think I'd
> > end up writing something like:
> >
> > (defun prompt-for-password
> > (&rest args &key (username "") (password "") &allow-other-keys)
> > (apply #'capi:popup-confirmer
> > (make-instance 'password-prompt
> > :username username
> > :password password)
> > "message"
> > :allow-other-keys t
> > args))
> >
> > which would make my prompt-for-password compatible with with the
> > capi:with-dialog-results as the continuation would be passed
> > correctly, and all would work correctly, so long as none of my keyword
> > arguments conflict with those that capi:popup-confirmer accepts.
> >
> > Any thoughts on style, or a better way to do this?
>
> I believe this usage is exactly why the :ALLOW-OTHER-KEYS T behavior
> was placed in the language, and the CLHS would seem to corroborate this:
>
> http://www.lispworks.com/documentation/HyperSpec/Body/03_daf.htm
>
> | As an example of the use of &allow-other-keys and :allow-other-keys,
> | consider a function that takes two named arguments of its own and also
> | accepts additional named arguments to be passed to make-array:
> |
> | (defun array-of-strings (str dims &rest named-pairs
> | &key (start 0) end &allow-other-keys)
> | (apply #'make-array dims
> | :initial-element (subseq str start end)
> | :allow-other-keys t
> | named-pairs))
> |
> | This function takes a string and dimensioning information and returns
> | an array of the specified dimensions, each of whose elements is the
> | specified string. However, :start and :end named arguments may be used
> | to specify that a substring of the given string should be used. In
> | addition, the presence of &allow-other-keys in the lambda list
> | indicates that the caller may supply additional named arguments; the
> | rest parameter provides access to them. These additional named
> | arguments are passed to make-array. The function make-array normally
> | does not allow the named arguments :start and :end to be used, and an
> | error should be signaled if such named arguments are supplied to
> | make-array. However, the presence in the call to make-array of the
> | named argument :allow-other-keys with a true value causes any
> | extraneous named arguments, including :start and :end, to be acceptable
> | and ignored.
>
> -bcd
>
--
=====================
Joshua Taylor
tayloj@rpi.edu
"A lot of good things went down one time,
back in the goodle days."
John Hartford