>>>> "Clemens" == Clemens Heitzinger
<cheitzin(a)rainbow.studorg.tuwien.ac.at> writes:
Clemens> sperber(a)informatik.uni-tuebingen.de (Michael Sperber [Mr. Preprocessor])
writes:
>>
>>>> "Clemens" ==
Clemens Heitzinger <cheitzin(a)rainbow.studorg.tuwien.ac.at> writes:
>
Clemens> sperber(a)informatik.uni-tuebingen.de (Michael
Sperber [Mr. Preprocessor]) writes:
>
Clemens> On the other hand, I don't think that in
Scheme you can say
Clemens> you want this and that variable *not* to be hygienic.
>>
>
>> >> No, but (to
quote Craig in this discussion :-}) why would you want
>> >> this?
>
Clemens> One example is LOOP-FINISH. From the
HyperSpec:
>
Clemens>
----------------------------------------------------------------------
Clemens> The loop-finish macro can be used lexically within an extended loop
Clemens> form to terminate that form normally. That is, it transfers control
Clemens> to the loop epilogue of the lexically innermost extended loop form.
Clemens> This permits execution of any finally clause (for effect) and the
Clemens> return of any accumulated result.
>
Clemens> Examples:
Clemens> ;; Terminate the loop, but return the accumulated count.
Clemens> (loop for i in '(1 2 3 stop-here 4 5 6)
Clemens> when (symbolp i) do (loop-finish)
Clemens> count i)
Clemens> => 3
Clemens> ----------------------------------------------------------------------
>
Clemens> This is defined in the CL standard and I find
it quite useful.
>
>> Not that I claim to understand all the
ramifications, but what makes
>> this macro non-hygienic? You've posted a description, but no
>> definition.
Clemens> What definition do you want? Source code? You'll find it in the
Clemens> source code of your favorite CL implementation. I guess you can also
Clemens> find the source code of early implementations of the loop macro on the
Clemens> net.
I would still appreciate if you could post and explain such a
definition. You seem to be much more familiar with CL implementation
than I am.
Clemens> loop-finish is usually defined with macrolet and "pollutes" the
name
Clemens> space (i.e. makes it non-hygienic), which is useful in this case.
I don't see why. Please explain.
> But then of course, in Scheme idiomatics, you wouldn't even
need a
> macro to define this kind of thing ...
Clemens> Now you are talking about something completely different.
Sure. So what?
Clemens> But while we are at it, how would you write the loop macro and
Clemens> loop-finish in Scheme? This would really be interesting.
You use CALL-WITH-CURRENT-CONTINUATION to capture the continuation of
the loop, a global register to hold the finish handler, dynamic
assignment to manage the register, and DYNAMIC-WIND to make sure
finalization happens. It would work along the following lines:
(define *loop-finish-handler* (make-fluid #f))
(define (loop-finish)
((fluid *loop-finish-handler*) #f))
(define-syntax loop
(syntax-rules (for in stop-here finally <...>)
((loop ...)
(call-with-current-continuation
(lambda (finish-handler)
(let-fluid *loop-finish-handler* finish-handler
(lambda ()
(dynamic-wind
(lambda () <...>)
(lambda () <execute the loop>)
(lambda () <execute the finally clause>)))))))))
--
Cheers =8-} Chipsy
Friede, Völkerverständigung und überhaupt blabla