PasteRack.org
Paste # 95048
2016-02-08 23:04:51

Forked from paste # 38830.

Fork as a new paste.

Paste viewed 120 times.


Embed:

Matrix class

  1. #lang racket
  2.  
  3. (define (matrix-fun f x-max y-max)
  4.   (λ args (match args
  5.             [(list i j)
  6.              #:when (and (< i x-max) (< j y-max))
  7.              (f i j)]
  8.             ['(rows) x-max]
  9.             ['(columns) y-max])))
  10.  
  11. (define-syntax-rule (M <num-rows> × <num-columns> (<x-tag> <y-tag>) <f>)
  12.   (matrix-fun (lambda(<x-tag> <y-tag>) <f>) <num-rows> <num-columns>))
  13.  
  14. (define M0 (M 3 × 4 (i j) (+ j (* 10 i))))
  15. (M0 2 3)
  16. (M0 'rows)
  17. (M0 'columns)

=>

23

3

4