guile-devel
[Top][All Lists]
Advanced

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

Re: Weird stuff with define*


From: Maciej Stachowiak
Subject: Re: Weird stuff with define*
Date: 18 Sep 2000 21:44:08 -0700
User-agent: Gnus/5.0802 (Gnus v5.8.2) Emacs/20.4

"Jorgen 'forcer' Schaefer" <address@hidden> writes:

> Maciej Stachowiak <address@hidden> writes:
> 
> 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.

Keywrod arguments can only be specified after all of the fixed and
optional positional arguments (since a keyword is also a valid value,
you need this constraint to make unambiguous interpretation of the
argument list possible).
 
> 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.

That's how they work now, essentially.

> - #:key arguments are equivalent to normal arguments, but
>   keyword-indexed instead of position-indexed, and bound to a
>   special value[*] if not given.

That's also how they work now

> - the #:rest / R5RS . argument includes all arguments passed to a
>   function, except the normal, keyword or optional arguments.

Stripping things out of the rest arg is fairly inefficient, and tricky
to get right. Specifying both a rest arg and keyword args is bound to
have confusing results, so it's best not to do it if absolutely
necessary. Note also that you can implement the stripping behavior in
terms of the non-stripping, but not vice versa.

> [*] 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.

The optargs package includes a defined? macro for testing for a value
being undefined; you can also specify your own default with,
e.g. (define* (foo #:optional (arg 'default-value)) (display arg))

 - Maciej


reply via email to

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