Fwd: Re: Keywords reduced Lassi Kortela (20 Oct 2019 10:04 UTC)
Re: Fwd: Re: Keywords reduced Lassi Kortela (20 Oct 2019 10:19 UTC)

Re: Fwd: Re: Keywords reduced Lassi Kortela 20 Oct 2019 10:19 UTC

> One will now legitimately raise the concern that both numbers and
> strings as keywords are not exactly pretty. Here, SRFI 88 will come to
> our help. SRFI 88's "keyword objects" are not symbols and not
> identifiers, so they will be matched by `eq?' like numbers and strings
> and not by hygienically with `free-identifier=?'. They can be used in
> macros wherever I want to have symbol-like markers that not matched
> hygienically and could also be used in the context of procedures with
> keyword arguments when hygiene is implemented with ordinary
> identifiers.

This is a most excellent idea! Best of both worlds.

Since 177 is meant to be simple and portable, it could stick to ordinary
symbols that are treated non-hygienically. So each 177 implementation
converts the symbols to whatever non-hygienic keyword objects the
underlying Scheme has. The portable fallback implementation can use
quoted symbols for the same effect. This is what is already done.

Later we can add a standard way to define and call keyword procedures
that treats ordinary symbols as hygienic keywords. So this later way
would have a superset of the functionality of 177. Of course the syntax
has to be different since 177 uses symbols for non-hygienic keywords.

177 could use keyword objects or strings as keyword markers, but strings
are extremely un-Lispy, and there are dozens of implementations in which
keyword objects do not exist.

Yet another option is explicitly quoted symbols:

(keyword-lambda (a b ('key1 key2)) ...)

In this case, key1 would be non-hygienic (because it's quoted) and key2
would be hygienic (because it's not quoted). But I imagine most people
would want non-hygienic keywords unless they are doing something fancy,
so they should have the most obvious-looking syntax. Keyword objects
would be ideal, but it's not realistic to expect to have them in all
Schemes soon.

Yet another possibility:

(keyword-lambda (a b (key1 (hygienic key2))) ...)

This one is too complex for my taste...

Since one would probably want to generate hygienic keywords mostly from
macros, and in other special situations, there could well be separate
`hygienic-keyword-lambda` and `hygienic-keyword-call` (probably with
shorter names).

> In order to make SRFI 88 portable, I would propose a reader directive
> "#!keyword-objects", which causes the reader to subsequently parse
> identifiers ending with a colon as keyword object and not as a symbol.

That idea was part of the big keyword discussion in July. It's likely a
good one. Perhaps there should be a separate SRFI about unification of
read syntax for keyword objects. It could support all the current
syntaxes (#: prefix, as well as : prefix and postfix), maybe with #!
flag to toggle which ones are used in a particular source file.

> See my SRFI 150 with hygienic record names (relevant for inheritance),
> where I suggest to use keywords objects when one doesn't want/need the
> extra hygiene: https://srfi.schemers.org/srfi-150/srfi-150.html.

I think it's a very good idea!