From: ······@gmail.com
Subject: named parameters in Common Lisp or Scheme Lisp
Date: 
Message-ID: <d69d94a7-fb58-47f3-a36b-96d3d023f663@k24g2000pri.googlegroups.com>
emacs lisp does not have named parameters. This is a practical pain.

Can anyone tell me how Common Lisp or Scheme Lisp solve this problem?

In particular, in CL or SL:

• does it support named parameter?

• if it supports named parameter, can the programer choose to make the
parameter a required argument, or is it always optional?

• what's the syntaxt for it?

• when it is optional, how to set default value? (or what's the
syntax)

Thanks.

  Xah
∑ http://xahlee.org/

☄

From: Dimiter "malkia" Stanev
Subject: Re: named parameters in Common Lisp or Scheme Lisp
Date: 
Message-ID: <gg4erj$dp5$1@news.motzarella.org>
(defun have (you &keyword been)
   (reading-p (the newsgroup)))

······@gmail.com wrote:
> emacs lisp does not have named parameters. This is a practical pain.
> 
> Can anyone tell me how Common Lisp or Scheme Lisp solve this problem?
> 
> In particular, in CL or SL:
> 
> • does it support named parameter?
> 
> • if it supports named parameter, can the programer choose to make the
> parameter a required argument, or is it always optional?
> 
> • what's the syntaxt for it?
> 
> • when it is optional, how to set default value? (or what's the
> syntax)
> 
> Thanks.
> 
>   Xah
> ∑ http://xahlee.org/
> 
> ☄
From: Brendan Halpin
Subject: Re: named parameters in Common Lisp or Scheme Lisp
Date: 
Message-ID: <87abbuv730.fsf@wivenhoe.ul.ie>
·······@gmail.com" <······@gmail.com> writes:

> emacs lisp does not have named parameters. This is a practical pain.

Use (require 'cl) which gives you defun*

Brendan
-- 
Brendan Halpin,  Department of Sociology,  University of Limerick,  Ireland
Tel: w +353-61-213147 f +353-61-202569 h +353-61-338562; Room F2-025 x 3147
·····················@ul.ie  http://www.ul.ie/sociology/brendan.halpin.html
From: Tassilo Horn
Subject: Re: named parameters in Common Lisp or Scheme Lisp
Date: 
Message-ID: <87myfuscj0.fsf@thinkpad.tsdh.de>
·······@gmail.com" <······@gmail.com> writes:

Hi,

> In particular, in CL or SL:
>
> • does it support named parameter?

In CL those are called keyword parameters.  Quoting the hyperspec:

    keyword parameter n. A parameter for which a corresponding keyword
    argument is optional. (There is no such thing as a required keyword
    argument.) If the argument is not supplied, a default value is
    used. See also supplied-p parameter.

> • if it supports named parameter, can the programer choose to make the
> parameter a required argument, or is it always optional?

As stated above.

> • what's the syntaxt for it?

Here's a funcall:

  (member 2 '((1 . 2) (3 . 4)) :test-not #'= :key #'cdr) =>  ((3 . 4))

Definition:

  (defun foo (normal1 normal2 &key foo (bar 'default) (baz 'default baz-p))
    ..)

The parameters normal1 and normal2 are, you guess it, normal parameters.

foo is a keyword parameter.

bar is a keyword parameter with default value "default".

baz is a keyword parameter with default value 'default and
`arg-supplied-p' variable baz-p, which will be nil only if baz was not
specified by the caller.  That way you can distinguish between being
called like

  (foo 1 2)

and being called with 

  (foo 1 2 :baz 'default),

where the given argument equals the default value.

The same works for &optional parameters.

> • when it is optional, how to set default value? (or what's the
> syntax)

See above.

Bye,
Tassilo
From: Pascal J. Bourguignon
Subject: Re: named parameters in Common Lisp or Scheme Lisp
Date: 
Message-ID: <7ck5aybdce.fsf@pbourguignon.anevia.com>
Tassilo Horn <·······@member.fsf.org> writes:
> ·······@gmail.com" <······@gmail.com> writes:
>> • does it support named parameter?
>
> In CL those are called keyword parameters.  Quoting the hyperspec:
>
>     keyword parameter n. A parameter for which a corresponding keyword
>     argument is optional. (There is no such thing as a required keyword
>     argument.) If the argument is not supplied, a default value is
>     used. See also supplied-p parameter.
>
>> • if it supports named parameter, can the programer choose to make the
>> parameter a required argument, or is it always optional?
>
> As stated above.

For the benefit of newbies other than the OP(*):

Or, Yes:

(defun f (&key (m nil mp) (o nil op))
  (assert mp (m) "M keyword argument must be provided")
  (if op (p m o) (q m)))


-- 
__Pascal Bourguignon__

(*) The OP has eaten time of readers of these newsgroups for several
years, and still doesn't know the first thing about lisp.   I'd say
we've invested enough time on him, with no ROI whatsoever.
From: Steven M. Haflich
Subject: Re: named parameters in Common Lisp or Scheme Lisp
Date: 
Message-ID: <fj5Yk.8474$Ei5.5348@flpi143.ffdc.sbc.com>
Pascal J. Bourguignon wrote:

> (defun f (&key (m nil mp) (o nil op))
>   (assert mp (m) "M keyword argument must be provided")
>   (if op (p m o) (q m)))

Simpler, and perhaps with slightly less runtime cost:

(defun f (&key (m (error ":m must be supplied.")) ...
From: Barry Margolin
Subject: Re: named parameters in Common Lisp or Scheme Lisp
Date: 
Message-ID: <barmar-B9AA89.11553429112008@mara100-84.onlink.net>
In article <··············@moon.robolove.meer.net>,
 Madhu <·······@meer.net> wrote:

> * "Steven M. Haflich" <···················@flpi143.ffdc.sbc.com> :
> Wrote on Fri, 28 Nov 2008 22:31:40 -0800:
> 
> | Pascal J. Bourguignon wrote:
> |
> |> (defun f (&key (m nil mp) (o nil op))
> |>   (assert mp (m) "M keyword argument must be provided")
> |>   (if op (p m o) (q m)))
> |
> | Simpler, and perhaps with slightly less runtime cost:
> |
> | (defun f (&key (m (error ":m must be supplied.")) ...
> 
> I'm sure pascal meant to write
>     (assert (or mp m) (m) "M keyword argument must be provided")

If that's what he meant, he wouldn't need MP, and could simply write:

(assert m (m) "M keyword argument must be provided and non-null")

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Pascal J. Bourguignon
Subject: Re: named parameters in Common Lisp or Scheme Lisp
Date: 
Message-ID: <87iqq6m413.fsf@informatimago.com>
Madhu <·······@meer.net> writes:

> * "Steven M. Haflich" <···················@flpi143.ffdc.sbc.com> :
> Wrote on Fri, 28 Nov 2008 22:31:40 -0800:
>
> | Pascal J. Bourguignon wrote:
> |
> |> (defun f (&key (m nil mp) (o nil op))
> |>   (assert mp (m) "M keyword argument must be provided")
> |>   (if op (p m o) (q m)))
> |
> | Simpler, and perhaps with slightly less runtime cost:
> |
> | (defun f (&key (m (error ":m must be supplied.")) ...
>
> I'm sure pascal meant to write
>     (assert (or mp m) (m) "M keyword argument must be provided")

If the default value is NIL, as in the example, then oring with M is
useless.

If the default value wasn't NIL, then oring with M would be wrong.

So it's better not do that.

-- 
__Pascal Bourguignon__
http://www.informatimago.com