From: Lynn Winebarger <owinebar@indiana.edu>
Subject: Re: help with define-syntax
Date: Thu, 29 Jan 2004 19:12:51 -0500 [thread overview]
Message-ID: <4019A183.2030302@indiana.edu> (raw)
In-Reply-To: 16384.15454.842037.476033@shmyh.ua
Viktor Pavlenko wrote:
> Hello,
>
> (warning: this is a newbie question, please be patient:)
>
> I'm experimenting with syntax rules and can't figure out how to
> achieve something that seems reasonable.
>
> I want to define a syntax to combine each of supplied procedures with
> `and' (well my ultimate goal is more ambitious but first things first)
> while adding some extra argument to them, and it works fine if done
> like this:
> [...]
> (define-syntax *flt*
> (syntax-rules()
> ((_ (a) (and (f1 a1 ...) (f2 a2 ...) ...))
Just to make sure, you know the above "and" is a variable for whatever
actually appears there, so the "and" below won't necessarily be 'and
after expansion.
It seems like unnecessary confusion. You should probably just match
(_ (a) (a1 ...) (a2 ...)) [because the same thing goes for "f1" and "f2"].
> (lambda (ls)
> (display "in xxx") (newline)
> (and ((f1 a a1 ...) ls) ((f2 a a2 ...) ls) ...)))))
> [...]
> --------------------------------------------------------------8<
>
> Now, I want to avoid calling f1, f2, ... each time the resulting
> procedure is called but rather make a closure with `let', something
> like
>
> --------------------------------------------------------------8<
> (define-syntax *flt*
> (syntax-rules()
> ((_ (a) (and (f1 a1 ...) (f2 a2 ...) ...))
> (let ((f1-pr (f1 a a1 ...)) (f2-pr (f2 a a2 ...)) ...)
> (lambda (ls)
> (display "in xxx") (newline)
> (and (f1-pr ls) (f2-pr ls) ...))))))
> --------------------------------------------------------------8<
>
> but it won't work: I get an "extra ellipsis" error in the last `and'
> statement, and if I comment it out, `let' will complain about
> "duplicate bound variable".
The extra ellipsis error is because neither f2-pr nor ls are bound in the
pattern. They're bound by the let, _after_ expansion.
The duplicate bound variable doesn't have anything to do with the extra ellipsis,
except that not having the extra ellipsis allows expansion of *flt* to occur.
The reason for the duplicate bound variable is still that f2-pr is not a syntax variable,
so it gets literally reproduced in your template. I.e.
(*flt* (foo) (bar (k1 x1 x2) (k2 y11 y12 y13) (k3 y21 y22))
will expand to
(let ((f1-pr (k1 x1 x2))
(f2-pr (k2 y11 y12 y13))
(f2-pr (k3 y21 y22)))
[etc])
Lynn
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user
prev parent reply other threads:[~2004-01-30 0:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-10 17:54 help with define-syntax Viktor Pavlenko
2004-01-30 0:12 ` Lynn Winebarger [this message]
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=4019A183.2030302@indiana.edu \
--to=owinebar@indiana.edu \
/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).