[plt-scheme] keywords (a backward-incompatible change)

From: Eli Barzilay (eli at barzilay.org)
Date: Sun Oct 2 06:39:54 EDT 2005

On Oct  1, Jim Blandy wrote:
> 
> If the feature isn't going to be used in MzScheme core functionality
> because it's not well-behaved enough, that argues that perhaps the
> syntax shouldn't be enabled by default in the reader.  If someone is
> using Swindle, they can always put #k+(begin ...) at the top of
> their file.

It turns out to be useful enough to be a desired feature outside of
Swindle (which manages without it).


> (How do people writing Common Lisp macros deal with this?  I mean,
> if you're operating on code, you've got keyword objects flying
> around as normal values all over the place, so they must run into
> the problem.)

What problem are you referring to here?


> If it's all up to the callee to parse its argument list, and the only
> magic associated with keywords is that they're self-quoting, I guess I
> don't see why they're so much better than quoted symbols, i.e.:
> 
>    (slide 'center? #t 'tall? #t
>           contents ...)
> 
> I don't know the slide-show syntax; if that's no good, you could
> reserve a set of symbol names:
> 
>    (slide ':center? #t ':tall? #t
>           contents ...)
> 
> or whatever suits your taste.

You get a new type that exists for this purpose.  Yes, passing values
of this type to functions that expect keywords will be problematic,
but this is why its a new type.


> In the end, since the self-quoting isn't really essential, and the
> distinct datatype isn't either, it comes down to the value of having
> a legible convention that everyone knows about.

(That too.)


> > This would be the OCaml way, I think.  It sounds like a more sane
> > approach if core functions will use keywords.  It has another
> > advantage, the fact that you can eliminate run-time costs completely,
> > but this comes at a price of being less flexible -- for example, there
> > will be no way to do something like:
> >
> >   (define (my-slide . args) (apply slide :tall? #t args))
> 
> You could get that behavior with an adapted version of apply:
> 
>       (apply-with-keywords slide '((:tall? . #t)) args)
> 
> Or maybe:
> 
>       (apply slide args :keywords '((:tall? . #t)))

No, you will not be able to use apply *at all* for this approach.
(Which is actually a hint for the way my-slide can be defined: as a
macro.)

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.