Re: connected?

dvanhorn <[email protected]>
Newsgroups gmane.org.ballistichelmet.lambda
Message-ID <[email protected]>
dvanhorn wrote:
> (define between?

Let me try again:

;; Returns true if any of the pieces are between x and y.
;; (row * col) * (row * col) * list of (row * col) -> bool

(define between?
  (let ((f (lambda (x y)
             (if (= x y) (circular-list x)
                 (list-tabulate (sub1 (abs (- x y)))
                                (lambda (z) ((if (< x y) + -) x z 1)))))))
    (match-lambda*
      [((x-row x-col) (y-row y-col) pieces)
       (any (lambda (x) (in? x pieces))
            (zip (f x-row y-row)
                 (f x-col y-col)))])))

Nicer?

(NB There is a bug in MzScheme's implementation of SRFI; zip on infinite lists
does not work.)

David
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.