or does it ?
Hi,
I have a spline-drawing defun which accepts many keywords:
(defun spline (points-list &key
(type *spline-type*)
(line-style *line-style*)
(thickness *thickness*)
(pen-color *pen-color*)
(fill-color *fill-color*)
(depth *depth*)
...
I have a wrapper routine, that by itself does not need any keywords,
but I would like to pass keywords to spline. The only way I managed
to do it included a use of a dummy keyword:
(defun roi (points &rest spline-kwrds &key dummy &allow-other-keys)
"Defines a region of interest"
(identity dummy)
(apply #'spline
(loop for point in points ;; this part has to do with adapting the
roi argument to the spline argument
collecting (append point '(1.0)))
:type (getf *spline-types* :closed-approximated-spline)
:allow-other-keys t spline-kwrds))
If I don't include "&key dummy" in the argument list, I get an error.
(this is on SBCL). I really don't mind having to do it. I am just
curious if I am missing something. Oh, silly me. I must be. The
question should be: what am I missing?
Thank you,
Mirko
PS. um, sorry, but I seem to be hooked on loops these days -- I
promise to try harder in the near future to wean myself of them :-)
(If you don't know what I am talking about, just ignore).
On Mar 25, 9:23 pm, ·············@gmail.com wrote:
> or does it ?
>
> Hi,
>
> I have a spline-drawing defun which accepts many keywords:
>
> (defun spline (points-list &key
> (type *spline-type*)
> (line-style *line-style*)
> (thickness *thickness*)
> (pen-color *pen-color*)
> (fill-color *fill-color*)
> (depth *depth*)
> ...
>
> I have a wrapper routine, that by itself does not need any keywords,
> but I would like to pass keywords to spline. The only way I managed
> to do it included a use of a dummy keyword:
>
> (defun roi (points &rest spline-kwrds &key dummy &allow-other-keys)
> "Defines a region of interest"
> (identity dummy)
> (apply #'spline
> (loop for point in points ;; this part has to do with adapting the
> roi argument to the spline argument
> collecting (append point '(1.0)))
> :type (getf *spline-types* :closed-approximated-spline)
> :allow-other-keys t spline-kwrds))
>
> If I don't include "&key dummy" in the argument list, I get an error.
> (this is on SBCL). I really don't mind having to do it. I am just
> curious if I am missing something. Oh, silly me. I must be. The
> question should be: what am I missing?
>
You should be able to write
(defun roi (points &rest spline-kwrds &key &allow-other-keys) ...)
Marco
From: Thomas A. Russ
Subject: Re: &allow-other-keys forces me to use dummy keyword ...
Date:
Message-ID: <ymilk46o0fz.fsf@blackcat.isi.edu>
Marco Antoniotti <·······@gmail.com> writes:
> On Mar 25, 9:23��pm, ·············@gmail.com wrote:
> > or does it ?
> >
> > Hi,
> >
> > I have a wrapper routine, that by itself does not need any keywords,
> > but I would like to pass keywords to spline. �The only way I managed
> > to do it included a use of a dummy keyword:
> >
> > (defun roi (points &rest spline-kwrds &key dummy &allow-other-keys)
> > � "Defines a region of interest"
> > � (identity dummy)
> > � (apply #'spline
> > � �(loop for point in points �;; this part has to do with adapting the
> > roi argument to the spline argument
> > � � � collecting (append point '(1.0)))
> > � �:type (getf *spline-types* :closed-approximated-spline)
> > � �:allow-other-keys t spline-kwrds))
> >
> > If I don't include "&key dummy" in the argument list, I get an error.
> > (this is on SBCL). �I really don't mind having to do it. �I am just
> > curious if I am missing something. �Oh, silly me. �I must be. �The
> > question should be: what am I missing?
> >
>
> You should be able to write
>
> (defun roi (points &rest spline-kwrds &key &allow-other-keys) ...)
Or even simpler:
(defun roi (points &rest spline-kwrds) ...)
since if you don't care about keyword processing in the body and you are
allowing all keywords, you might as well just use a &rest parameter. I
guess the one thing you lose is potential compiler detection of an
odd-length keyword argument list, but otherwise it should work fine.
--
Thomas A. Russ, USC/Information Sciences Institute
On Mar 26, 1:20 am, ····@sevak.isi.edu (Thomas A. Russ) wrote:
> Marco Antoniotti <·······@gmail.com> writes:
> > On Mar 25, 9:23Ž pm, ·············@gmail.com wrote:
> > > or does it ?
>
> > > Hi,
>
> > > I have a wrapper routine, that by itself does not need any keywords,
> > > but I would like to pass keywords to spline. The only way I managed
> > > to do it included a use of a dummy keyword:
>
> > > (defun roi (points &rest spline-kwrds &key dummy &allow-other-keys)
> > > "Defines a region of interest"
> > > (identity dummy)
> > > (apply #'spline
> > > (loop for point in points ;; this part has to do with adapting the
> > > roi argument to the spline argument
> > > collecting (append point '(1.0)))
> > > :type (getf *spline-types* :closed-approximated-spline)
> > > :allow-other-keys t spline-kwrds))
>
> > > If I don't include "&key dummy" in the argument list, I get an error.
> > > (this is on SBCL). I really don't mind having to do it. I am just
> > > curious if I am missing something. Oh, silly me. I must be. The
> > > question should be: what am I missing?
>
> > You should be able to write
>
> > (defun roi (points &rest spline-kwrds &key &allow-other-keys) ...)
>
> Or even simpler:
>
> (defun roi (points &rest spline-kwrds) ...)
>
> since if you don't care about keyword processing in the body and you are
> allowing all keywords, you might as well just use a &rest parameter. I
> guess the one thing you lose is potential compiler detection of an
> odd-length keyword argument list, but otherwise it should work fine.
>
> --
> Thomas A. Russ, USC/Information Sciences Institute
Duh! Of course....
Marco
From: Edi Weitz
Subject: Re: &allow-other-keys forces me to use dummy keyword ...
Date:
Message-ID: <u63va8uqd.fsf@agharta.de>
On Tue, 25 Mar 2008 12:23:14 -0700 (PDT), ·············@gmail.com wrote:
> or does it ?
(defun foo (&key &allow-other-keys)
nil)
http://www.lispworks.com/documentation/HyperSpec/Body/03_da.htm
Edi.
--
European Common Lisp Meeting, Amsterdam, April 19/20, 2008
http://weitz.de/eclm2008/
Real email: (replace (subseq ·········@agharta.de" 5) "edi")
On Mar 25, 3:32 pm, Edi Weitz <········@agharta.de> wrote:
> On Tue, 25 Mar 2008 12:23:14 -0700 (PDT), ·············@gmail.com wrote:
> > or does it ?
>
> (defun foo (&key &allow-other-keys)
> nil)
>
> http://www.lispworks.com/documentation/HyperSpec/Body/03_da.htm
>
> Edi.
>
> --
>
> European Common Lisp Meeting, Amsterdam, April 19/20, 2008
>
> http://weitz.de/eclm2008/
>
> Real email: (replace (subseq ·········@agharta.de" 5) "edi")
Thank you (and to Marco). That works.
From: Peder O. Klingenberg
Subject: Re: &allow-other-keys forces me to use dummy keyword ...
Date:
Message-ID: <ksd4pio7pq.fsf@beto.netfonds.no>
·············@gmail.com writes:
> (defun roi (points &rest spline-kwrds &key dummy &allow-other-keys)
> "Defines a region of interest"
> (identity dummy)
> (apply #'spline
> (loop for point in points ;; this part has to do with adapting the
> roi argument to the spline argument
> collecting (append point '(1.0)))
> :type (getf *spline-types* :closed-approximated-spline)
> :allow-other-keys t spline-kwrds))
>
> If I don't include "&key dummy" in the argument list, I get an error.
> (this is on SBCL). I really don't mind having to do it. I am just
> curious if I am missing something. Oh, silly me. I must be. The
> question should be: what am I missing?
I see you have gotten good answers already. Mine is more of a
followup question, directes as much to those who replied as to you.
But since you already collect the lot into a &rest list, what's the
point of specifying &key &allow-other-keys at all?
What's wrong with simply
(defun roi (points &rest spline-kwrds)
(apply #'spline (massage points) ... spline-kwrds))
?
Maybe, with an odd number of elements in the spline-kwrds list, you'd
get an error message earlier if you use &key &allow-other-keys, but
are there other benefits that I'm missing?
...Peder...
--
I wish a new life awaited _me_ in some off-world colony.
On Mar 25, 4:43 pm, ·····@news.klingenberg.no (Peder O. Klingenberg)
wrote:
> ·············@gmail.com writes:
> > (defun roi (points &rest spline-kwrds &key dummy &allow-other-keys)
> > "Defines a region of interest"
> > (identity dummy)
> > (apply #'spline
> > (loop for point in points ;; this part has to do with adapting the
> > roi argument to the spline argument
> > collecting (append point '(1.0)))
> > :type (getf *spline-types* :closed-approximated-spline)
> > :allow-other-keys t spline-kwrds))
>
> > If I don't include "&key dummy" in the argument list, I get an error.
> > (this is on SBCL). I really don't mind having to do it. I am just
> > curious if I am missing something. Oh, silly me. I must be. The
> > question should be: what am I missing?
>
> I see you have gotten good answers already. Mine is more of a
> followup question, directes as much to those who replied as to you.
> But since you already collect the lot into a &rest list, what's the
> point of specifying &key &allow-other-keys at all?
>
> What's wrong with simply
>
> (defun roi (points &rest spline-kwrds)
> (apply #'spline (massage points) ... spline-kwrds))
>
> ?
>
> Maybe, with an odd number of elements in the spline-kwrds list, you'd
> get an error message earlier if you use &key &allow-other-keys, but
> are there other benefits that I'm missing?
>
> ...Peder...
> --
> I wish a new life awaited _me_ in some off-world colony.
I think Thomas replied to that already. I'm still too wobbly on my
skates to answer that. I'll give it a shot.
Thanks,
Mirko