Re: Reviewing named and optional parameters Daphne Preston-Kendal 14 Oct 2021 10:42 UTC

On 9 Jun 2021, at 12:27, Marc Nieper-Wißkirchen <xxxxxx@nieper-wisskirchen.de> wrote:

>> I considered the possibility of making everything a macro, but I decided losing first-class status of procedures was too high a price to pay, on principle if nothing else. True, it's unlikely (though not impossible) that an arbitrary higher-order procedure (as in map, fold and their respective first arguments) will use keyword arguments, but I can imagine not-so-contrived situations where it would still be useful to pass them around.
>>
>> But perhaps it would be acceptable to have something where you'd define a version of a procedure with positional arguments which is first-class, then a meta-macro to get a keyword version of it? Hmm.
>
> Yes, this is exactly what I mean! So we have a general version (to be passed around) and a convenient macro version with whatever special (keyword argument) syntax.
>
> My point was just that passing around a procedure that will then be able to be called with keyword arguments won't really be needed.

I have just implemented a system like this as an experiment. <https://gitlab.com/dpk/presrfis/-/tree/master/syntax-keywords>

With a solution to the issue with first-class arguments (either identifier syntax or the additional parameter for the name of the non-keyword version), I think it could work pretty well. But it has a similar problem to KeywordArgumentsArcfide in that you need to export not only the names of your procedures but the names of any keywords they take in your library, and there may be name clashes between libraries. Also, this takes no account of existing keyword argument systems at all, which is a blessing (we don’t need to worry about what they do at all) and a curse (the colon postfixes I use in the example code won’t work in Schemes where colon postfixes create keyword datums).

It would also not be too tricky to hack the implementation to be used to define actual keyword-defining syntax, rather than a pseudo-procedure as syntax (as suggested in the ‘Keyword arguments to macros’ section of my review).

(Since this involves fairly icky syntax-rules hacking, I should note that I have only tested it in Chibi. Hopefully it should work in other R7RSes too, but you know how these things can be …)

Daphne