From: Ken Anderson <kanderson@bbn.com>
Cc: Timothy Hickey <timhickey@mac.com>
Subject: Re: macro like "my" in Perl
Date: Wed, 26 Jun 2002 09:15:42 -0400 [thread overview]
Message-ID: <5.0.2.1.2.20020626091345.00afe790@zima.bbn.com> (raw)
In-Reply-To: <87k7omn5do.wl@strelka.synthcode.com>
In Jscheme, not guile, i recently redefined (define) so that groups of
internal defines are turned into let* or letrec as appropriate, so you can
write code without additional indenting:
(define (graph)
(define objRoot (BranchGroup.))
(define objTrans (TransformGroup.))
(define (addToRoot obj) (.addChild objRoot obj))
(.setCapability objTrans TransformGroup.ALLOW_TRANSFORM_WRITE$)
(.addToRoot objTrans)
(.addChild objTrans (ColorCube. 0.4))
(define yAxis (Transform3D.))
(define rotationAlpha (Alpha. -1 4000L))
(define rotator
(RotationInterpolator. rotationAlpha objTrans yAxis
0.0f
(* 2.0F (.floatValue Math.PI$))))
(define bounds (BoundingSphere. (Point3d. 0.0 0.0 0.0) 100.0))
(.setSchedulingBounds rotator bounds)
(addToRoot rotator)
(.compile objRoot)
objRoot)
At 10:25 PM 6/25/2002, Alex Shinn wrote:
> >>>>> "Paul" == Paul Jarc <prj@po.cwru.edu> writes:
>
> Paul> I'm looking for something like Perl's "my":
>
> [...]
>
> Paul> (new-scope
> Paul> (my-define foo #t)
> Paul> (do-random-stuff-with foo)
> Paul> (my-define bar foo)
> Paul> (do-other-stuff-with bar))
>
>let* can do this if you want:
>
> (let* ((foo #t)
> (dummy (do-random-stuff-with foo))
> (bar foo))
> (do-other-stuff-with bar))
>
>but that's rather poor style. If you just want bar to be some function
>of foo, you can do
>
> (let* ((foo #t)
> (bar (some-random-function-of foo)))
> (do-other-stuff-with bar))
>
>or you can declare all the variables you need up front
>
> (let* ((foo #t) (bar #f))
> (do-random-stuff-with foo)
> (set! bar foo)
> (do-other-stuff-with bar))
>
>or nest let
>
> (let ((foo #t))
> (do-random-stuff-with foo)
> (let ((bar foo))
> (do-other-stuff-with bar)))
>
>I guess that's the real complaint... nested lets indent the code too
>much, but for some straight but very long procedural algorithms it's
>less clear to make all the variable decls up front when their use is
>localized.
>
>You can write new-scope as a low-level macro that walks the code,
>turning my-define into set! and accumulating all the variable names used
>into one top-level let. Something like
>
>(define-macro (new-scope . code)
> (let ((vars (map cadr (filter (lambda (x) (eq? (car x) 'my-define))
> code))))
> `(let (,@(map (lambda (x) (list x #f)) vars))
> ,@(map (lambda (x) (if (and (pair? x) (eq? (car x) 'my-define))
> (cons 'set! (cdr x))
> x))
> code))))
>
>but make it recurse (this only works if all the my-define's are at the
>top level).
>
>--
>Alex
>
>_______________________________________________
>Guile-user mailing list
>Guile-user@gnu.org
>http://mail.gnu.org/mailman/listinfo/guile-user
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
next prev parent reply other threads:[~2002-06-26 13:15 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-06-25 22:19 macro like "my" in Perl Paul Jarc
2002-06-25 23:16 ` Robert Uhl <ruhl@4dv.net>
2002-06-26 2:25 ` Alex Shinn
2002-06-26 13:15 ` Ken Anderson [this message]
2002-06-26 14:45 ` Lynn Winebarger
2002-07-02 15:34 ` Ken Anderson
2002-06-26 14:44 ` Lynn Winebarger
2002-06-27 1:28 ` Alex Shinn
2002-07-12 20:43 ` Paul Jarc
2002-07-13 0:09 ` Neil Jerram
2002-07-13 20:48 ` Paul Jarc
2002-07-16 20:49 ` Neil Jerram
2002-07-16 21:05 ` Paul Jarc
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5.0.2.1.2.20020626091345.00afe790@zima.bbn.com \
--to=kanderson@bbn.com \
--cc=timhickey@mac.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).