[racket-dev] split-for-body from syntax/for-body

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Fri Sep 6 11:15:50 EDT 2013

Is this function ever particularly necessary?  Its intended use seems to be
like so:

(define-syntax (for/print stx)
  (syntax-parse stx
    [(_ clauses . body)
     (with-syntax ([([pre ...] [post ...]) (split-for-body #'body)])
         (for clauses
           pre ...
           (printf "~v/n" (let () post ...)))))]))

That way any #:break or #:final from the body ends up in pre ..., where the
enclosing for loop will interpret them, and post ... will only include
normal definitions and expressions.

But it seems to me there's a much easier way that should always work:

(define-syntax-rule (for/print clauses pre ... result)
  (for clauses
    pre ...
    (printf "~v\n" result)))

This not only puts all #:break and #:final clauses in pre ..., it should
guarantee result is an expression.  Perhaps one should still write (let ()
result) in case result is (begin defn expr), but that's still simpler than
using split-for-body.

My question is -- have I overlooked some clever subtlety here that makes
split-for-body necessary, or is it usually easier to just decompose pre ...
result rather than bothering with split-for-body?

Carl Eastlund
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20130906/c632c1fd/attachment.html>

Posted on the dev mailing list.