[racket] idioms for abstracting over definitions

From: Patrick Mahoney (paddy.mahoney at gmail.com)
Date: Mon May 7 17:41:12 EDT 2012

#|
Hello all, in a quest for greater concision, I'm looking for a way to
abstract over the following code containing mostly definitions. Is there an
accepted practice for abstraction over definition introduction?|#

(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)))

#|How should I approach this? are my options parameters, leaving as is, a
with- macro?

Much appreciated all,
-Patrick
|#
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120507/a8a4a8ce/attachment.html>

Posted on the users mailing list.