Alternative syntax using colon symbols for portable keywords
Lassi Kortela 29 Oct 2019 22:29 UTC
>> I propose this: if you really must have hygienic keywords, then in
>> systems without keywords, a symbol beginning with ":" is treated as global.
>
> Hmm. Could this be the best of all worlds?
>
> (keyword-call 1 2 3 :foo 4 :bar 5 :baz 6)
>
> This forbids a syntax-rules based implementation. But anyway, the macro
> would scan the list until it finds either:
>
> - A keyword object (in a Scheme that has such objects).
> - A symbol whose name starts with `:`.
> - A symbol whose name ends with `:`.
>
> From that point on, it would parse keyword-value pairs.
Here's a syntax-case implementation for Kawa:
<https://misc.lassi.io/2019/srfi-177-colon-kawa.scm>.
The code is equally long as the portable syntax-rules implementation,
but twice as long as the old Kawa implementations. It's really nice to
use though:
> (load "srfi-177-colon-kawa.scm")
> (define foo (keyword-lambda (a b :key c d) (values a b c d)))
> (keyword-call foo 1 2 :c 3 :d 4)
1 2 3 4