Re: Read syntax for hygienic keywords
Per Bothner 21 Oct 2019 23:27 UTC
On 10/21/19 1:27 AM, Lassi Kortela wrote:
>> (foo a b #:key1 c #:key2 d)
>>
>> could be equivalent to:
>>
>> (foo a b (symbol->keyword 'key1) c (symbol->keyword 'key2) d)
Not in Kawa (or Racket, I assume). The former has 2 positional arguments and 2 keyword arguments,
The latter has 6 positional arguments.
The latfer is perfectly, valid, and there is nothing to prevent foo
from looking for keyword values, as part of a #!rest parameter.
But foo would have to do it "by hand". (There are some backward compatibility
hacks, but it' been a while since I delved into this, so I'm not sure about the details.)
> This would work well for CL-style keyword arguments, but would it work for Kawa/Racket-style keywords-as-markers? As far as I can tell, those currently rely on the fact that the markers are read in as keywords, i.e. their bindings don't need to be looked up at all. Wouldn't the (foo a b key1 c key2 d) solution require the compiler to look up the bindings of key1 and key2 before deciding that they indicate keyword arguments?
Kawa does not depend on the value or type of the arguments to decide what is a keyword argument.
It's purely syntactic - but there are mechanisms to implement a generalized apply that handles keywords:
https://www.gnu.org/software/kawa/Application-and-Arguments-Lists.html
> If I understood correctly, the main advantage of Kawa/Racket keyword markers is that the compiler knows their interpretation cannot change based on bindings and evaluation, so it has more freedom to check and optimize things more easily.
>
> In case Per is lurking, could you explain this to us please? :)
Hope the above helps.
--
--Per Bothner
xxxxxx@bothner.com http://per.bothner.com/