Email list hosting service & mailing list manager

Simpler implementation with R7RS parameters? Adam Nelson (27 Apr 2020 20:50 UTC)
(missing)
Re: Simpler implementation with R7RS parameters? Adam Nelson (04 Jun 2020 18:13 UTC)
Re: Simpler implementation with R7RS parameters? Marc Nieper-Wißkirchen (04 Jun 2020 18:16 UTC)
Re: Simpler implementation with R7RS parameters? Shiro Kawai (05 Jun 2020 01:05 UTC)
Re: Simpler implementation with R7RS parameters? Marc Nieper-Wißkirchen (05 Jun 2020 06:16 UTC)
Re: Simpler implementation with R7RS parameters? Shiro Kawai (05 Jun 2020 07:07 UTC)
Re: Simpler implementation with R7RS parameters? Marc Nieper-Wißkirchen (05 Jun 2020 07:37 UTC)
Re: Simpler implementation with R7RS parameters? Shiro Kawai (05 Jun 2020 09:14 UTC)
Re: Simpler implementation with R7RS parameters? Marc Nieper-Wißkirchen (28 Apr 2020 06:27 UTC)
Re: Simpler implementation with R7RS parameters? Marc Nieper-Wißkirchen (05 May 2020 14:56 UTC)

Re: Simpler implementation with R7RS parameters? Marc Nieper-Wißkirchen 05 Jun 2020 06:16 UTC

Am Fr., 5. Juni 2020 um 03:05 Uhr schrieb Shiro Kawai <xxxxxx@gmail.com>:
>
> I agree with the rationale of using identifier syntax, but is it _allowed_ to implement it as an ordinary variable?
> It does make the optimization described in srfi difficult, but functionally it works the same in ordinary use cases.
> Currently the srfi states yield to be bound to syntax, so it excludes such choice, though.

A variable reference *is* syntax, so this doesn't preclude `yield'
bound to a variable instead of a transformer.

> Here's my take.  It works with the examples and tests.
>
> https://github.com/shirok/Gauche/blob/master/lib/srfi-190.scm
>
> Are there any use cases that reveal the difference between variable and syntax implementations?

It is the lexical scoping that doesn't work if you replace
`syntax-parameterize' with `parameterize'.

As replacing lexical with dynamic scoping often simply works
(especially, when there are no higher-order procedures involved), your
solution will mostly work. But not always:

(define-coroutine-generator f
  (yield (lambda () (yield 1))))

(define-coroutine-generator g
  (yield
   (let ((x (f)))
     (if (proc? x) (x) x)))))

(g) ;=> 1

This won't work with dynamic scoping of `yield'. (One can probably
think of a much simpler example.)

For most uses cases, though, dynamic scoping does not seem to make a
difference (only in efficiency). However, it is probably better to
implement syntax parameters (maybe a bit of work; I don't know
Gauche's syntax expander) and identifier syntax (trivial to implement)
in Gauche. Alternatively, one may try to implement `yield' with
unhygienic macros instead of syntax parameters (which is exactly why
syntax parameters are so great because they make the dangerous
examples of unhygienic macros unnecessary; see [1]).

Marc

[1] http://scheme2011.ucombinator.org/papers/Barzilay2011.pdf