unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* help with define-syntax
@ 2004-01-10 17:54 Viktor Pavlenko
  2004-01-30  0:12 ` Lynn Winebarger
  0 siblings, 1 reply; 2+ messages in thread
From: Viktor Pavlenko @ 2004-01-10 17:54 UTC (permalink / raw)


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:

--------------------------------------------------------------8<
(use-syntax (ice-9 syncase))

(define (f1 a b c)
  (lambda (ls)
    (format #t "in proc made by f1: ~A/~A~%" (list a b c) ls)
    #t))

(define (f2 a b)
  (lambda (ls)
    (format #t "in proc made by f2: ~A/~A~%" (list a b) ls)
    #t))

(define (f3 a)
  (lambda (ls)
    (format #t "in proc made by f3: ~A/~A~%" (list a) ls)
    #t))

(define-syntax *flt*
  (syntax-rules()
    ((_ (a) (and (f1 a1 ...) (f2 a2 ...) ...))
     (lambda (ls)
       (display "in xxx") (newline)
       (and ((f1 a a1 ...) ls) ((f2 a a2 ...) ls) ...)))))

(define pr
  (*flt* ("arg-a")
	 (and (f3) (f1 "arg-f1-1" "arg-f1-2") (f3) (f2 "arg-f2-1"))))

(pr '(1 2 3))
(pr '(11 22 33))
--------------------------------------------------------------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".

A hint how to do it properly would be much appreciated.

TIA

-- 
Viktor


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-01-30  0:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-01-10 17:54 help with define-syntax Viktor Pavlenko
2004-01-30  0:12 ` Lynn Winebarger

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).