Re: Self-evaluating keywords or not? Per Bothner 16 Mar 2020 16:46 UTC

> Am Mo., 16. März 2020 um 16:38 Uhr schrieb Marc Feeley <xxxxxx@iro.umontreal.ca <mailto:xxxxxx@iro.umontreal.ca>>:
>
>     The point of the foo: (or :foo) syntax for keywords and the self-evaluation is to provide a lightweight and “visually” agreable syntax for calling a procedure with keyword arguments.  In this respect I find the following visually disagreable:
>
>         (bar 42 'foo: 88 'baz: 99)
>         (bar 42 '#:foo 88 '#:baz 99)
>
>     Self-evaluating keywords make the code more lightweight:
>
>         (bar 42 foo: 88 baz: 99)
>         (bar 42 #:foo 88 #:baz 99)

>On 3/16/20 8:59 AM, Marc Nieper-Wißkirchen wrote:
> My original post in this thread was not about the exact form of the lexical syntax, be it `foo:', `:foo', or `#:foo'.  (The latter, which you find visually less pleasant, has the advantage of not clashing with R7RS-small.)

To put it more concretely: Kawa does not have self-evaluating keywords,
but it does use the syntax:
    (bar 42 foo: 88 baz: 99)

The keyword foo: is part of the application syntax. It is not an expression that is evaluated.

Advantages: Avoid semantic ambiguity.  Potentially robust compile-time keyword matching and checking.
For example, the implementation (compiler or run-time) can reject as an error:
   (cons a: 12)

Also, potentially faster and more compact keyword-passing: Kawa sorts the keywords at both the function
definition and the call sites.  (This is easier and more robust when you can syntactically
distinguish keywords. ) That means means keyword matching is O(0) without the overhead
(space and time) of using hash tables; instead you can use compact cache-friendly vectors.

Disadvantage: A bit more complicated than plain self-evaluating keywords.  You need to
decide how to generalize apply, how to deal with "other" keywords (those not explicitly
listed in the procedure definition), and how to handle "argument list" (#!rest) objects.

This is Kawa's solution:
https://www.gnu.org/software/kawa/Application-and-Arguments-Lists.html
--
	--Per Bothner
xxxxxx@bothner.com   http://per.bothner.com/