Email list hosting service & mailing list manager


Re: Alternative formulations of keywords John Cowan 12 Apr 2006 12:16 UTC

Marc Feeley scripsit:

> If you try to formalize the cases in which it does work and the cases
> in which it doesn't you will realize that it is very hard to specify
> precisely.  You have to assume a particular set of powerful analyzes
> that are performed by the compiler, and your semantics will depend on
> the existence of these analyzes.  This places difficult constraints
> on the Scheme implementation.

It's syntactic sugar, so I'm fine with it not working in any case that's
at all tricky.

> For example can your proposed approach work in this case:
>
>    (define (f g)
>      (g foo: 11 bar: 22))

Plainly no.  The compiler should cough with "keywords in call of unknown
function".

> or in this case:
>
>    (define (f #!key (x 11) (y 22)) (+ x y))
>    (define (g z) (f y: z))
>    (define (h) (set! f (lambda (#!key (y 33) (z 44)) (* y z))))

Again, plainly no.  I might have said "only if the compiler can prove
that h is always called before g is", but that's precisely the sort
of tricky analysis neither of us would want to depend on.

Here the error is "keyword y: not known for function f."

In short, the definition of a function must be either global or
lexically apparent for it to be callable with keywords.

--
John Cowan    http://ccil.org/~cowan    xxxxxx@ccil.org
Mr. Henry James writes fiction as if it were a painful duty.  --Oscar Wilde