guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Weird stuff with define*


From: Jorgen 'forcer' Schaefer
Subject: Re: Weird stuff with define*
Date: 19 Sep 2000 03:52:21 +0200
User-agent: Gnus/5.0807 (Gnus v5.8.7) Emacs/20.7

Maciej Stachowiak <address@hidden> writes:

> "Jorgen 'forcer' Schaefer" <address@hidden> writes:
> 
> > guile> (define* (foo #:optional bar #:key baz)
> >   (cons bar baz))
> > guile> (foo 'bar #:baz 'baz)
> > (bar . baz)
> > guile> (foo #:baz 'baz 'bar)
> > (#:baz . #<undefined>)
> 
> Hmm, it's bad to leak the undefined value, but the default value for a
> keyword, if you don't specify one, is the undefined value. Perhaps the
> default for the default value should be #f or something.

I was under the impression that keywords can be specified at any
point in the argument list.  Seems i was wrong, so this behaviour
is ok. 

A default value of #f probably would be bad -- sometimes one
actually wants every possible scheme value as possible argument
for a keyword.  But #f would be more consistent with Common
Lisp.

> > guile> (define* (foo #:key bar #:rest baz)
> >   (list bar baz))
> > guile> (foo #:bar 'bar 'the 'rest)
> > (bar (#:bar bar the rest))
> 
> This is on purpose, as other similar APIs include keyword arguments in
> the rest arg. If you didn't, it gets confusing thinking about the
> right way to parse them out. Perhaps some other clear, consistent
> behavior could be designed.

hmm.  Maybe my impression stems from the same basic understanding
problem as above.  I thought keywords as equivalent to normal
parameters, but with the possibility to be given in any order at
any place in the parameter list, in contrast to the defined order
of normal arguments, while the rest argument includes all
arguments which aren't in the normal ("ordered" or "unordered")
arguments.  I didn't check Common Lisp before mailing, though.

I haven't thought about this too much yet, but maybe this would
be a nice thing to think over to "clean up" guile, the same way
as guile now uses #:key etc. instead of #&key.

- #:optional arguments are equivlanet to normal arguments and
  position-indexed, but bound to a special value[*] if not
  given.
- #:key arguments are equivalent to normal arguments, but
  keyword-indexed instead of position-indexed, and bound to a
  special value[*] if not given.
- the #:rest / R5RS . argument includes all arguments passed to a
  function, except the normal, keyword or optional arguments.

[*] As you said, the special value maybe shouldn't be
    #<undefined>, as this is difficult to check from scheme.
    This is another point to talk about.  Should it be #f?  If
    someone needs #f as possible value, he can specify a
    different value.  In the rare case that someone needs
    *any* possible scheme value, he can define his own read
    syntax and use this as a default value.

At least it would be very educating for me to hear different
opinions on why this is "bad" (except for compatibility
reasons).

Thanks in advance,
        -- forcer

-- 
((email . "address@hidden")       (www . "http://forcix.cx/";)
 (irc   . "address@hidden (IRCnet)") (gpg .    "1024D/028AF63C"))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]