--- On Mon, 5/7/12, Patrick Mahoney <[email protected]> wrote:

> 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?


(define (get-cell-info a-cell a-grid-plane)
  (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)
  (list col-pos row-pos cell-w cell-h cell-size))


In the future, make sure that your posts are in
plain text.

____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to