good enough for now

svn: r10937
This commit is contained in:
Matthias Felleisen 2008-07-27 21:22:29 +00:00
parent 14c48aa3b5
commit d532716a51
2 changed files with 29 additions and 17 deletions

View File

@ -0,0 +1,3 @@
(module matrix mzscheme
(provide (all-from htdp/matrix))
(require htdp/matrix))

View File

@ -2,15 +2,23 @@
@(require scribble/manual "shared.ss" @(require scribble/manual "shared.ss"
(for-label scheme (for-label scheme
teachpack/htdp/image teachpack/htdp/matrix
teachpack/htdp/world lang/posn))
lang/private/imageeq))
@teachpack["matrix"]{Matrix Operations} @teachpack["matrix"]{Matrix Operations}
The teachpack supports matrices and matrix operations. A matrix is just a The experimental teachpack supports matrices and matrix operations. A
rectangle of 'objects'. It is displayed as an image, just like the images matrix is just a rectangle of 'objects'. It is displayed as an image, just
from @secref["image"]. like the images from @secref["image"]. Matrices are images and, indeed,
scenes in the sense of the @secref["world"].
The operations access a matrix in the usual (school-mathematics) manner:
row first, column second.
The operations aren't tuned for efficiency so don't expect to build
programs that process lots of data.
@declare-exporting[teachpack/htdp/matrix] @declare-exporting[teachpack/htdp/matrix]
@ -36,19 +44,20 @@ creates a rectangle from this matrix @scheme[m]}
@defproc[(make-matrix [n natural-number/c][m natural-number/c][l (Listof X)]) matrix?]{ @defproc[(make-matrix [n natural-number/c][m natural-number/c][l (Listof X)]) matrix?]{
creates an @scheme[n] by @scheme[m] matrix from @scheme[l] creates an @scheme[n] by @scheme[m] matrix from @scheme[l]
NOTE: make-matrix would consume an optional number of entries, if it were NOTE: @scheme[make-matrix] would consume an optional number of entries, if
like make-vector} it were like @scheme[make-vector]}
@defproc[(build-matrix [n natural-number/c][m natural-number/c] @defproc[(build-matrix
[f (-> natural-number/c natural-number/c any)]) [n natural-number/c][m natural-number/c]
matrix?]{ [f (-> (and/c natural-number/c (</c m)) (and/c natural-number/c (</c n)) any/c)])
creates an @scheme[n] by @scheme[m] matrix by applying @scheme[f] to (0,0), matrix?]{
(0,1), ..., (n-1,m-1)} creates an @scheme[n] by @scheme[m] matrix by applying @scheme[f] to @scheme[(0,0)],
@scheme[(0,1)], ..., (@scheme[(sub1 m),(sub1 n)])}
@defproc[(matrix-ref [m matrix?][i natural-number/c][j natural-number/c]) any]{ @defproc[(matrix-ref [m matrix?][i (and/c natural-number/c (</c (matrix-rows m)))][j (and/c natural-number/c (</c (matrix-rows m)))]) any/c]{
retrieve the item at (@scheme[i],@scheme[j]) in matrix @scheme[m]} retrieve the item at (@scheme[i],@scheme[j]) in matrix @scheme[m]}
@defproc[(matrix-set [m matrix?][i natural-number/c][j natural-number/c] @defproc[(matrix-set [m matrix?][i (and/c natural-number/c (</c (matrix-rows m)))][j (and/c natural-number/c (</c (matrix-rows m)))]
[x any/c]) [x any/c])
matrix?]{ matrix?]{
creates a new matrix with @scheme[x] at (@scheme[i],@scheme[j]) and all creates a new matrix with @scheme[x] at (@scheme[i],@scheme[j]) and all
@ -61,11 +70,11 @@ such that @scheme[(P (matrix-ref M i j))] holds}
@defproc[(matrix-render [m matrix?]) (unsyntax @tech{Rectangle})]{ @defproc[(matrix-render [m matrix?]) (unsyntax @tech{Rectangle})]{
renders this matrix @scheme[m] as a rectangle of strings} renders this matrix @scheme[m] as a rectangle of strings}
@defproc[(matrix-minor [m matrix?][i natural-number/c][j natural-number/c]) @defproc[(matrix-minor [m matrix?][i (and/c natural-number/c (</c (matrix-rows m)))][j (and/c natural-number/c (</c (matrix-rows m)))])
matrix?]{ matrix?]{
creates a matrix minor from @scheme[m] at (@scheme[i],@scheme[j])} creates a matrix minor from @scheme[m] at (@scheme[i],@scheme[j])}
@defproc[(matrix-set! [m matrix?][i natural-number/c][j natural-number/c] @defproc[(matrix-set! [m matrix?][i (and/c natural-number/c (</c (matrix-rows m)))][j (and/c natural-number/c (</c (matrix-rows m)))]
[x any/c]) [x any/c])
matrix?]{ matrix?]{
like @scheme[matrix-set] but uses a destructive update} like @scheme[matrix-set] but uses a destructive update}