build-matrix
matrix?
matrix-rows
matrix-cols
matrix-valid-ref?
matrix-ref
matrix-set
matrix-set!
matrix-fold
display-matrix
Version: 4.1.5.3

Semi-persistent Matrices

Jay McCarthy <jay at plt-scheme dot org>

 (require (planet jaymccarthy/matrix:1:0))

This package defines matrices using semi-persistent vectors from the (planet jaymccarthy/spvector) package.

(build-matrix rows cols cell-f)  matrix?
  rows : exact-positive-integer?
  cols : exact-positive-integer?
  cell-f : (exact-nonnegative-integer? exact-nonnegative-integer? . -> . any/c)

Constructs a matrix m such that (matrix-ref m ri ci) is (cell-f ri ci).

(matrix? v)  boolean?
  v : any/c

Determines if v is a valid matrix.

(matrix-rows m)  exact-positive-integer?
  m : matrix?

Returns how many rows m has.

(matrix-cols m)  exact-positive-integer?
  m : matrix?

Returns how many cols m has.

(matrix-valid-ref? m ri ci)  boolean?
  m : matrix?
  ri : exact-nonnegative-integer?
  ci : exact-nonnegative-integer?

Determines if (matrix-ref m ri ci) would error.

(matrix-ref m ri ci)  any/c
  m : matrix?
  ri : exact-nonnegative-integer?
  ci : exact-nonnegative-integer?

Extracts the value of a cell in the matrix.

(matrix-set m ri ci v)  matrix?
  m : matrix?
  ri : exact-nonnegative-integer?
  ci : exact-nonnegative-integer?
  v : any/c

Semi-persistently modifies m.

(matrix-set! m ri ci v)  void
  m : matrix?
  ri : exact-nonnegative-integer?
  ci : exact-nonnegative-integer?
  v : any/c

Destructively modifies m.

(matrix-fold m row-f cell-f acc)  any/c
  m : matrix?
  row-f : (exact-nonnegative-integer? any/c . -> . any/c)
  cell-f : (exact-nonnegative-integer? exact-nonnegative-integer? any/c any/c . -> . any/c)
  acc : any/c

Like foldr but for matrices. row-f is called with the result of cell-f from the last column in the row. cell-f is called from left to right.

(display-matrix m)  void
  m : matrix?

displays the cells of m with (newline) separating rows.