This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Optional Arguments (was Re: CVS script)



jimb@red-bean.com writes:
> 
> > (define (find-files dir . arg-ls)
> >   "Return a list of files within directory DIR.  Two optional arguements
> > are supported, PREDICATE and RECURSE?.  PREDICATE should be a procedure
> > of one argument that determines whether a particular file should be include
> d
> > in the returned list.  As a special case, if PREDICATE is a string, it is
> > compiled into a regular expression, and a predicate is generated that appli
> es
> > this regular expression to the filename.  RECURSE? determines whether the
> > procedure descends into subdirectories, and it defaults to #t.  Symbolic
> > links are not followed."


I just had another thought about this somewhat old post: it's time to
try to sell my optinal argument package for inclusion in Guile
again. Every procedure having to do it's own optional argument
handling by hand is a severe waste of coding time and effort, IMO.

My optargs package (currently distributed with scwm) provides
scsh-compatible `let-optional' and `let-optional*' forms, analogous
`let-keywords' and `let-keywords*' which handle keyword arguments, and
`lambda*', `define*' and `define*-public' forms which offer extended
lambda lists in the Common Lisp style, with #&optional and #&key as
special markers for the start of the optional and keyword args. The
macros are a bit hairy, but IMO generate pretty good code - about as
efficient as what you'd get doing it by hand, but with better error
checking.

The last time this was discussed, there were two sticking points that
I recall. One was that maybe optional arguments should eventually be
implemented in the core interpreter as part of the lambda special
form. While I'm sure this would be a fine idea, I think the all-scheme
macro-based solution works decently well, and would at least be a good
interim solution until someone feels like hacking up support in the
interpreter itself.

Another concern was that DSSSL (and, as I've since learned, MIT
Scheme) use special #!optional, #!key and #!rest keywords. This is a
problem for Guile because #! is used as the syntax for opening a block
comment. Some people suggested various compromise solutions, such as
making #! only introduce a block comment when followed by a slash, or
only when it begins a line or some such. IMO such a solution would be
hackish and confusing; one hash syntax should only mean one
thing. 

Since #! _must_ be used as a block comment specifier at least at the
start of scripts, I think #&optional and #&key are good compromises
which are reminiscent of both the MIT Scheme/DSSSL #!optional/#!key
and the Common Lisp &optional/&key.

 - Maciej