nest macro and final draft Adam Nelson (08 Aug 2020 14:34 UTC)
Re: nest macro and final draft Linus Björnstam (08 Aug 2020 14:59 UTC)
Re: nest macro and final draft John Cowan (09 Aug 2020 00:32 UTC)
Re: nest macro and final draft Marc Nieper-Wißkirchen (09 Aug 2020 09:36 UTC)
Re: nest macro and final draft Marc Nieper-Wißkirchen (09 Aug 2020 09:49 UTC)
Re: nest macro and final draft Linus Björnstam (09 Aug 2020 14:03 UTC)
Re: nest macro and final draft John Cowan (09 Aug 2020 16:19 UTC)

Re: nest macro and final draft Marc Nieper-Wißkirchen 09 Aug 2020 09:49 UTC

Three more things:

(1) The library (srfi 197) should export "<>" bound to auxiliary
syntax. SRFI 197 should contain a sentence saying that in a Scheme
system supporting as well SRFI 26 and/or SRFI 148 the identifier "<>"
is always bound to the same auxiliary syntax so that one can easily
import more than one of these SRFIs into the same module. The same
would apply to "<...>", but see (2).

(2) I would suggest replacing "<...>" by "<> ...". This makes the code
more readable and needs less new auxiliary syntax. We can always
create an amended SRFI 26 that will use "<> ..." instead of "<...>".
This would be in line with SRFI 148 as well.

The example

(chain (a) (b <> c <...>) (d))

would become

(chain (a) (b <> c <> ...) (d))

(3) Before the final finalization, I'd like to invite everyone to a
brainstorm about a good, but less misleading name of this SRFI because
this SRFI is not about expression chaining operators but about
procedure call chaining.

Am Sa., 8. Aug. 2020 um 16:34 Uhr schrieb Adam Nelson <xxxxxx@nels.onl>:
>
> It's been a while since we've discussed SRFI 197. I think the current draft could work as a final draft, since we haven't decided on any specific changes or new features (that I remember), and SRFI 197 is simple anyway.
>
> There is one new feature that I've been considering adding. I found a need for it while writing my implementation of `match` in Schemepunk.
>
> `(chain a (b) (c))` is equivalent to `(let* ((x (b a)) (x (c x))) x)`, not `(c (b a))`. This is intentional, because `chain` should enforce evaluation order. But it doesn't allow nesting of macros or special forms.
>
> I'm considering adding two new macros, `nest` and `nest-reverse`. These work like `->>` used to, literally nesting expressions, without using `let*`. `nest-reverse` nests in the same order as `chain` (deepest item first), while `nest` preserves syntax order (deepest item last). They both support `<>`, but do not support multiple `<>`s or `<...>`.
>
> As an example of how they would work, this code:
>
>     (if x
>       (parameterize ((y x))
>         (with-output-to-string
>           (lambda ()
>             (display y))))
>       (error "kaboom"))
>
> Can be rewritten with `nest` like this:
>
>     (nest
>       (if x <> (error "kaboom"))
>       (parameterize ((y x)))
>       (with-output-to-string)
>       (lambda ())
>       (display y))
>
> `nest` is particularly useful for converting a `...` expansion in a `syntax-rules` macro into a nested expression.
>
> Thoughts? I'm still undecided on adding this to SRFI 197.