<div dir="ltr">Right, that's the issue with needing the (let () result) in my define-syntax-rule version. I still didn't need split-for-body, which doesn't guarantee there are no definitions in the post ... part. All it guarantees to eliminate are #:final and #:break.<br>
</div><div class="gmail_extra"><br clear="all"><div>Carl Eastlund</div>
<br><br><div class="gmail_quote">On Fri, Sep 6, 2013 at 12:09 PM, Matthew Flatt <span dir="ltr"><<a href="mailto:mflatt@cs.utah.edu" target="_blank">mflatt@cs.utah.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The issue is `begin` splicing. The `result` form could be a `begin`<br>
form that contains definitions that are referenced by a preceding<br>
forms.<br>
<br>
For example, given<br>
<br>
(define (fish? v) (or (red? v) (blue? v)))<br>
(begin<br>
(define (red? v) ....)<br>
(define (blue? v) ....)<br>
5)<br>
<br>
With `begin` splicing, that turns into<br>
<br>
(define (fish? v) (or (red? v) (blue? v)))<br>
(define (red? v) ....)<br>
(define (blue? v) ....)<br>
5<br>
<br>
which is different than<br>
<br>
(define (fish? v) (or (red? v) (blue? v)))<br>
(let ()<br>
(define (red? v) ....)<br>
(define (blue? v) ....)<br>
5)<br>
<div><div class="h5"><br>
At Fri, 6 Sep 2013 11:15:50 -0400, Carl Eastlund wrote:<br>
> Is this function ever particularly necessary? Its intended use seems to be<br>
> like so:<br>
><br>
> (define-syntax (for/print stx)<br>
> (syntax-parse stx<br>
> [(_ clauses . body)<br>
> (with-syntax ([([pre ...] [post ...]) (split-for-body #'body)])<br>
> (syntax<br>
> (for clauses<br>
> pre ...<br>
> (printf "~v/n" (let () post ...)))))]))<br>
><br>
> That way any #:break or #:final from the body ends up in pre ..., where the<br>
> enclosing for loop will interpret them, and post ... will only include<br>
> normal definitions and expressions.<br>
><br>
> But it seems to me there's a much easier way that should always work:<br>
><br>
> (define-syntax-rule (for/print clauses pre ... result)<br>
> (for clauses<br>
> pre ...<br>
> (printf "~v\n" result)))<br>
><br>
> This not only puts all #:break and #:final clauses in pre ..., it should<br>
> guarantee result is an expression. Perhaps one should still write (let ()<br>
> result) in case result is (begin defn expr), but that's still simpler than<br>
> using split-for-body.<br>
><br>
> My question is -- have I overlooked some clever subtlety here that makes<br>
> split-for-body necessary, or is it usually easier to just decompose pre ...<br>
> result rather than bothering with split-for-body?<br>
><br>
> Carl Eastlund<br>
</div></div>> _________________________<br>
> Racket Developers list:<br>
> <a href="http://lists.racket-lang.org/dev" target="_blank">http://lists.racket-lang.org/dev</a><br>
<br>
</blockquote></div><br></div>