Re: Keywords reduced Marc Nieper-Wißkirchen 20 Oct 2019 21:04 UTC

Am So., 20. Okt. 2019 um 12:12 Uhr schrieb Shiro Kawai <xxxxxx@gmail.com>:
>
>
>
> On Sat, Oct 19, 2019 at 10:39 PM Marc Nieper-Wißkirchen <xxxxxx@nieper-wisskirchen.de> wrote:
>>
>>
>> Think of a procedure `loggable' on may want to implement with keyword
>> arguments. `loggable' shall take a procedure `f' and return a new
>> procedure `g', which shall have the same interface as `f' except that
>> `g' takes an extra keyword argument, say `logger:'. When `g' is called
>> without the `logger:' argument, it shall foward the call to `f''.
>> However, when the `logger.' argument is provided, `g' shall log to
>> this logger that it is calling `f' before it is doing the actual call.
>>
>> As `f' may already be a procedure taking keyword arguments, it is here
>> where hygiene is helpful because the symbol (!) `logger:' may clash
>> with an already existing argument to `f'.
>
>
> Using hygiene only solves part of the problem.
>
> These are the cases hygiene can't help:
>
> (1) Suppose 'g' wants to "peek" logger argument, that is,  'g' tries to read the
>     value of 'logger:' argument, but want to pass it to inner 'f'.
>     The caller imports two procedures, f1 and f2, both takes 'logger:' keyword argument,
>     from different library.  So it must rename at least one of them.
>       (import (rename (f1-library) (logger: f1:logger:))
>                   (rename (f2-library) (logger: f2:logger:))
>                   (g-library))
>
>       (g f1 f1:logger: foo)
>       (g f2 f2:logger: foo)
>
>    How can 'g' peek 'logger:' keyword argument?

This wouldn't work. But it is not surprising, is it? If `f1' and `f2'
both take `logger:' keyword arguments, but both come from different
sources, `f1' and `f2' effectively use different, incompatible
protocols.

>
> (2) 'g' want to call inner 'f' adding 'test:' keyword argument; it only knows 'f' accepts 'test:'.
>      The caller imports f1 and f2 from different libraries.  How 'g' can pass both f1 and f2
>      the 'test:' arguments, not knowing which library they are imported?

There must a third library defining the `test' keyword, which is then
imported by all the other libraries.

>
> (3) You want to read a list of arguments from file and pass them to 'z'.  'z' takes keyword
>      arugments.  If keywords should be identifiers, how you can convert symbols read from
>      the file to appropriate identifiers?
>
> Besides, in your example, the implementor of 'g' *knows* it can shadow 'logger:', so it is
> a part of API.  Either the API states you can't pass 'logger:' to 'f', or it can provide
> an alternative way (e.g. 'extra-arguments:' keyword that takes a list of arguments to be passed
> to 'f').
>
> I claim hygiene isn't a right tool to solve the given problem.
>
>> Scheme is not CL and has hygienic macros. Its keyword-system shouldn't
>> be less elegant and beautiful than its `syntax-rules' system.
>
>
> You don't need to persuade me the beauty of hygiene here.

I'm sorry if it sounded like it.

-- Marc