[plt-scheme] A Macro question or two

From: David Einstein (deinst at gmail.com)
Date: Mon Sep 24 21:36:18 EDT 2007

OK, this macro is taunting me

(define-generator (:nested stx)
  (syntax-case stx ()
    [(:nested (var ...) gen ...)
     (with-syntax ([(tmp ...) (generate-temporaries #'(var ...))])
       #'(:do (let-values ([(fun-in done-in var ...)
                            (let/cc ret
                              (do-ec gen ... (let/cc enter
                                               (call-with-values
(lambda () (values enter #f var ...)) ret)))
                              (let ([var #f] ...)
                                (call-with-values (lambda () (values
#f #t var ...)) ret)))]))
            ((fun fun-in)(done done-in)(var var) ...)
            (not done)
            (let-values ([(fun1 done1 tmp ...) (fun)]))
            (not done1)
            (fun1 done1 tmp ...)))]))

(list-ec (:while (:nested (a b) (: a 1 10) (: b 1 10) (if (= 1 (gcd a
b)))) #t) (list a b))


This generates an error -- "syntax: incompatible ellipsis match counts
for template in: ..." -- which I do not understand.  I'm probably
missing something simple.  The error appears to be triggered by the
line (let-values ([(fun1 done1 tmp ...) (fun)])).

Also: The fragment that looks like

(let ([var #f] ...)
         (call-with-values (lambda () (values #f #t var ...)) ret))

really should look something like

(call-with-values (lambda () (values #f #t #f ...)) ret)

is there a simple way of doing this without building a list of #f by
hand converting it with datum->syntax-object and splicing it in?  Yes,
I'm lazy.  I would not be writing macros if I wasn't.


Posted on the users mailing list.