Can I write a loop procedure in Guile?

74 views Asked by At

I was trying to write a loop procedure in Guile. I came up with the following:

(define loop
  (lambda (predicate callback)
    (when predicate)
      callback
      (loop predicate callback)))

But that of course didn't work. The compiler doesn't even start as it seems to not be a valid syntax.

1

There are 1 answers

0
Rithwik On

I am not sure what the procedure is designed to do, but it does seem like there is an error in the placement of parentheses. when evaluates the condition and executes the following statements if it's true. In the above code when doesn't see the statements at all.

Maybe you meant to write this:

(define loop
  (lambda (predicate callback)
    (when predicate
      callback
      (loop predicate callback))))