On Sun, Oct 20, 2019 at 9:06 PM Marc Nieper-Wißkirchen <xxxxxx@nieper-wisskirchen.de> wrote:

With respect to hygiene this looks good!

But doesn't it preclude most optimizations with respect to keyword
arguments? Assume that `f' is well-known at the call site. How can
Gauche optimize the example

(f :foo x g:foo y)

Gauche hasn't impelemented it, but the idea is as follows.

First, if the binding is constant and the value isn't ephemeral (that is, such a value that can
be serialized to compiled object), then the compiler can replace a variable with its value.
For R6RS semantics you can statically determine constant bindings.  In Gauche we have
special flags.  Keywords bound in (gauche keyword) library are such constants.

Secondly, a compiler can generate two entry points for the function that takes keyword
arguments (in this case, 'f').   The generic entry point receives all keyword-value argument
as a rest list, and the hidden entry point takes keyword arguments positionally.  It can
store the keyword names as well as default values in meta information.

The generic entry does runtime parsing of keyword-value list and calls the hidden entry point.

If the compiler statically determines the called function is f, and all keywords are constants,
then it can deconstruct keyword-value list at compile time, fills default values, and calls
the hidden entry point.