[racket] idioms for abstracting over definitions
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.mahoney at 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)))
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120509/73b6f4c9/attachment.html>