[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: loop translations (was: Re: language translator help)

From: Clinton Ebadi
Subject: Re: loop translations (was: Re: language translator help)
Date: Mon, 29 Apr 2002 16:07:40 -0400

On Sunday 28 April 2002 14:48, Marius Vollmer wrote:
> Marius Vollmer <address@hidden> writes:
> > A good solution would be to make the continue feature optional and
> > let the user choose the name of the function.  Much like
> > 'with-exit', where the name of the exiting function is determined by
> > the user, not the macro.
> And, of course, to use (ice-9 syncase) instead of define-macro.

Which brings me to my problem...I tried to redefine the for macro as a 
syncase macro (so I could add (break) and (continue) inside of the macro, 
which wasn't working with define-macro)...and I have a problem:

(define-syntax for 
  (syntax-rules ()
    ((for (var start end) ....)
     (catch 'break
       (lambda ()
         (let loop ((var start))
           (catch 'continue
             (lambda ()
               (cond ((<= var end)
                      (throw 'continue))))
             (lambda ignored
               (loop (+ var 1))))))
       (lambda ignored
         (if #f #f #f))))))

(well, I had one problem before that--with-mutex wasn't defined, and yes, I 
did remember the --with-threads and I do have threading support, but I had to 
add :use-module (ice-9 threads) to syncase.scm to work with Guile 1.7...maybe 
this is a bug that others will experience?).

But when I try to load for.scm, I get this error:
ERROR: missing ellipsis in syntax form (syntax (catch (quote break) (lambda 
() (let loop ((var start)) (catch (quote continue) (lambda () (cond ((<= var 
end) ... (throw (quote continue))))) (lambda ignored (loop (+ var 1)))))) 
(lambda ignored (if #f #f #f))))
ABORT: (misc-error)

So, what are the rules for using ... exactly ? If I remove the parens around 
(var start end), it almost works, instead I get:

guile> (load "for.scm")
guile> (for i 1 10 (display i))
In current input:
   3: 0* (for i 1 10 (display i))
   3: 1  [catch break #<procedure #f ()> #<procedure #f syntmp-ignored-18>]
   ?: 2* [#<procedure #f ()>]
   ?: 3* [syntmp-loop-15 1]
   ?: 4  [catch continue #<procedure #f ()> #<procedure #f syntmp-ignored-17>]
   ?: 5* [#<procedure #f ()>]
   ?: 6* (cond ((<= syntmp-i-16 #) (<= syntmp-i-16 #) (throw #)))
   ?: 7* [<= 1 #<unspecified>]

<unnamed port>: In procedure <= in expression (<= syntmp-i-16 (display 
<unnamed port>: Wrong type argument in position 2: #<unspecified>
ABORT: (wrong-type-arg)

so it works for the first time, but then fails...the lack of documentation 
about "new" macros doesn't help me either :-)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]