Not sure this answers exactly to the specs, but it does avoid the
duplication:

(define get-pos
  (lambda (pos a-grid-plane a-cell)

    (match-define (cell row-pos col-pos) a-cell)

    (define cell-size (grid-plane->cell-size a-grid-plane))

    (match-define (size cell-w cell-h) cell-size)

    (case pos
      [(top-right-x)
       (+ cell-w
          (* col-pos cell-w))]
      [(top-right-y)
       (* row-pos cell-w)]
      ....)))


Laurent

On Mon, May 7, 2012 at 11:41 PM, Patrick Mahoney <paddy.maho...@gmail.com>wrote:

> (define top-right-x
>   (lambda (a-grid-plane a-cell)
>
> ;;The next three definitions are what I am looking to abstract over, as
> they show up in many similarly defined functions.|#
>     (match-define (cell row-pos col-pos) a-cell)
>
>     (define cell-size (grid-plane->cell-size a-grid-plane))
>
>     (match-define (size cell-w cell-h) cell-size)
>
>     (+ cell-w
>        (* col-pos cell-w))))
>
> (define top-right-y
>   (lambda (a-grid-plane a-cell)
>
>     (match-define (cell row-pos col-pos) a-cell)
>
>     (define cell-size (grid-plane->cell-size a-grid-plane))
>
>     (match-define (size cell-w cell-h) cell-size)
>
>     (* row-pos cell-w)))
>
____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to