[racket] Racket style question

From: Rodolfo Carvalho (rhcarvalho at gmail.com)
Date: Mon Mar 19 02:08:11 EDT 2012

Hi Joe,

On Mon, Mar 19, 2012 at 01:44, Joe Gilray <jgilray at gmail.com> wrote:

> Hi, I created the following code from some scheme I found on
> ProjectEuler.net (problem #9):
> (define (right-triangle? a b c)
>   (= (+ (* a a) (* b b)) (* c c)))

> -snip-

When I saw your code it made me think of a good chance to use for*.

This is what I got:

(define (pythagorean-triple/alt n)
  (for*/first ([a (in-range 1 n)]
               [b (in-range a n)]
               [c (in-value (- n a b))]
               #:when (right-triangle? a b c))
    (list a b c)))

The cool thing is that this is my first use of
and the docs say that "This form is mostly useful for
bindings in forms such as

One more nice thing about using *for *is that the loop becomes bounded (I
got infinite running programs when I ran your code with bad input n).


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120319/f8cb6496/attachment-0001.html>

Posted on the users mailing list.