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]

Re: keyword args + CLOS



chris.bitmead@misys.com.au writes:
> 
> 
> In researching the Motif interface I plan building, I've been looking at
> the optargs keyword package
> in scwm as well as a version of tclos.
> 
> Both look pretty cool. I'm thinking I might have to do some work to make a
> tclos version that supports
> both OO as well as keywords etc. But I'm also mindful that guile might
> (please let it be so) have a
> built in OO system one day - which I will naturally want to support.
> 

A CLOS-like system with a MOP was being worked on - this should be
pretty similar to STklos.

> Naturally, no-one can gurantee at this stage exactly what the future OO
> system might look like, but
> would I be on safe ground from a future compatibility point of view if I
> put together a combination
> of tclos and optargs? Do people consider that good style?
> 
> Out of curiousity, why does optargs use #:key and #&opt instead of the
> conventional :key and &opt?

Those are conventional for Common Lisp, but in Scheme they are
ordinary identifiers and it would conflict with RnRS to not treat them
as such. For #:some-keyword vs. :some-keyword, you can set a reader
option to allow reading with the latter syntax. optargs does not have
an option to allow using &optional instead of #&optional at this
time. The Scheme de facto standard for this is #!optional, which is
problematic for various reasons, and &optional as in CL seems wrong,
because I find it inappropriate for some identifiers to be reserved
only in parameter lists. So I split the difference. If it is important
to you to be able to use &optional and friends, I can add an option to
make this work.

> Also, there's something I don't like about optargs. It leaves keyword
> arguments in the rest argument
> like lisp. Scheme doesn't have a heritage of slavishly following what lisp
> does when it is a bad idea.
> I'm thinking of changing that for my usage, at least as a default. If you
> want that, I think there should be
> some other  syntax. Comments? Can anyone convince me that as a default,
> this is a good thing?

It's notably more costly to remove them. I can do it, but I am not
sure how people feel about this. Does anyone have experience with
other Scheme implementations that have keyword arguments? What
semantics do they have for combining it with a rest arg?

> As another comment, wierd things seem to happen depending on the order of
> arguments. I don't know
> what Lisp does, but this seems wierd...
> (define* (a b #&optional c d #&key e . f) (display e))
> (a 'hello 'there #:e 'foobar 'mr 'bill 'jones)
> =>undefined
> (a 'hello 'there 'mr #:e 'foobar 'bill 'jones)
> =>foobar

This is more or less a bug in the current version, I have a new
version which I am going to distribute as soon as I get a copyright
disclaimer from my employer (I'm resorting to blackmail by threatening
not to sign my employee agreement unless they sign my
papers). However, if you would like a copy for testing/evaluation
purposes, I can send one your way. It fixes this problem and adds a
number of other useful features.

 - Maciej