Email list hosting service & mailing list manager

s7 suggestion bil@xxxxxx (29 Oct 2019 13:40 UTC)
Re: s7 suggestion Lassi Kortela (29 Oct 2019 15:15 UTC)
Re: s7 suggestion bil@xxxxxx (29 Oct 2019 15:56 UTC)
Re: s7 suggestion Lassi Kortela (29 Oct 2019 16:19 UTC)
Re: s7 suggestion Lassi Kortela (29 Oct 2019 16:32 UTC)
Re: s7 suggestion bil@xxxxxx (29 Oct 2019 17:53 UTC)
Re: s7 suggestion Lassi Kortela (29 Oct 2019 18:06 UTC)
Re: s7 suggestion John Cowan (01 Nov 2019 21:26 UTC)
Re: s7 suggestion Lassi Kortela (01 Nov 2019 21:35 UTC)
Re: s7 suggestion John Cowan (01 Nov 2019 23:03 UTC)
&key vs :key in the lambda list Lassi Kortela (01 Nov 2019 23:17 UTC)
Re: &key vs :key in the lambda list John Cowan (01 Nov 2019 23:18 UTC)
Re: &key vs :key in the lambda list Lassi Kortela (01 Nov 2019 23:27 UTC)
Syntax for hygienic vs non-hygienic keywords Lassi Kortela (01 Nov 2019 23:33 UTC)
Re: allow-other-keys bil@xxxxxx (29 Oct 2019 19:51 UTC)
Re: s7 suggestion Marc Nieper-Wi├čkirchen (29 Oct 2019 16:32 UTC)
Re: s7 suggestion Lassi Kortela (29 Oct 2019 16:53 UTC)
Re: s7 suggestion bil@xxxxxx (29 Oct 2019 17:10 UTC)
Including 177 in s7? Lassi Kortela (29 Oct 2019 17:34 UTC)

Re: s7 suggestion Lassi Kortela 29 Oct 2019 15:15 UTC

> Thank you for including s7 in srfi-177.  I thought you might like an
> hygenic version of that code:

Absolutely! Thank you for contributing it.

> (define-macro (keyword-lambda formals-and-keys . body)
>    ((lambda (formals keyword-symbols)
>       `(with-let (unlet) ; or (inlet (unlet)) -- more explicit
>      (lambda* (,@formals ,@(map (lambda (sym) `(,sym #f))
>                                     keyword-symbols))
>            ,@body)))
>     (split-last formals-and-keys)))

> "with-let"
> evaluates its body in the given environment.  s7 has
> first-class environments, so it doesn't need define-syntax and
> its friends.

Very interesting! Does `unlet` get the global environment without any
lexical bindings from `let` expressions around the macro call site, and
that's why it's guaranteed to get the standard definition of `lambda*`?
In that case, how does `body` get access to variables in a closure
around the keyword lambda:

(let ((base 123))
   (keyword-lambda ((offset))
     (+ base (or offset 0))))

> I think the keyword-call macro is already hygienic.

That's my impression too since the macro doesn't add any of its own
symbols to the expansion; it only adds keywords.

> Here are tests, similar to yours:
>
> (define (writeln x) (write x) (newline))
>
> (let ((lambda* gcd)
>        (list abs)
>        (a 321)
>        (split-last 42)
>        (cond if))
>    (define y (keyword-lambda (a b (c d)) (list a b c d)))
>    (writeln (y 1 2))
>    (writeln (keyword-call y 1 2 ()))
>    (writeln (keyword-call y 1 2 (c 3)))
>    (writeln (keyword-call y 1 2 (d 4 c 3))))
>
> (set! list abs)
>
> (define z (keyword-lambda (a b (c d)) (list a b c d)))
> (writeln (z 1 2))
> (writeln (keyword-call z 1 2 ()))
> (writeln (keyword-call z 1 2 (c 3)))
> (writeln (keyword-call z 1 2 (d 4 c 3))))

Thanks a lot! I don't have Docker set up right now, but I'll run these
before submitting the next draft of the SRFI.

Did you know we have a Docker container for s7 at
<https://github.com/weinholt/scheme-docker/tree/s7>? Try `docker run -it
weinholt/s7`.