Future directions of the nest macro Marc Nieper-Wißkirchen (31 Aug 2020 18:12 UTC)
Re: Future directions of the nest macro Adam Nelson (01 Sep 2020 01:05 UTC)
Re: Future directions of the nest macro Marc Nieper-Wißkirchen (01 Sep 2020 06:20 UTC)
Re: Future directions of the nest macro Dr. Arne Babenhauserheide (01 Sep 2020 05:26 UTC)
Re: Future directions of the nest macro Marc Nieper-Wißkirchen (01 Sep 2020 06:05 UTC)
Re: Future directions of the nest macro Adam Nelson (01 Sep 2020 17:39 UTC)
Re: Future directions of the nest macro Marc Nieper-Wißkirchen (02 Sep 2020 07:12 UTC)

Future directions of the nest macro Marc Nieper-Wißkirchen 31 Aug 2020 18:11 UTC

In the current definition of the nest macro, each step has to be of
the form (<datum> ... _ <datum> ...) and the single underscore is
replaced by the result of the nesting the later steps.

This is the best one can do if nest is supposed to be implementable
with syntax-rules (which is, I think, the intent of SRFI 197), but it
also limits its applicability (and may not always yield what one may
expect).

For example, the following does not work

(nest
  (let ((x _))
    (* x x x))
  <complicated init expression>)

because nest replaces the underscore purely textually at the top-level.

With a more powerful macro system, more satisfying versions of nest
are possible:

(define-syntax nest
  (lambda (stx)
    (syntax-case stx ()
      ((k step init)
       (with-syntax ((_ (datum->syntax #'k '_)))
         #'(let-syntax ((_ (identifier-syntax init)))
             step))))))

Unfortunately, a Scheme system powerful enough so that the latter
version can be implemented cannot ship that version together with SRFI
197 because it is not in all cases a conservative extension.

The same holds for R7RS-large, which may get a macro system powerful
enough, and for which it would then probably make more sense to
standardize the latter version of nest.

There are three ways to proceed:

(1) Underspecify "nest" in SRFI 197 so that the latter version is
still a faithful implementation (and so that we can write a
conservative extension of SRFI 197 one day).

(2) Call "nest" in SRFI 197 slightly different (maybe indicating that
just the top-level is substituted), so that this sweet and short name
is not already taken once the more satisfying version of nest becomes
possible.

(3) Stick to the name of "nest" in SRFI 197, but then we would have to
find another natural name for the more natural latter version.

Marc