[racket] Racket style question

From: Eli Barzilay (eli at barzilay.org)
Date: Mon Mar 19 02:25:38 EDT 2012

20 minutes ago, Rodolfo Carvalho wrote:
> 
> (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))) 

You can also use `for*/or':

  (define (pythagorean-triple/alt n)
    (for*/or ([a (in-range 1 n)]
              [b (in-range a n)])
      (define c (- n a b))
      (and (right-triangle? a b c) (list a b c))))

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!


Posted on the users mailing list.