experiment with matrix-set-bang, some Rackety, fixing tests

This commit is contained in:
Matthias Felleisen 2012-11-15 10:41:16 -05:00
parent a89963d0a8
commit 2984f939ed
6 changed files with 443 additions and 462 deletions

View File

@ -1,4 +1,4 @@
#lang scheme
#lang racket
(require htdp/matrix-sig
htdp/matrix-render-sig

View File

@ -1,4 +1,4 @@
#lang scheme/signature
#lang racket/signature
;; CONVENTION:
;; [Rectangle X] = [Listof [Listof X]]

View File

@ -1,4 +1,4 @@
#lang scheme/unit
#lang racket/unit
(require htdp/matrix-sig
htdp/matrix-render-sig
@ -215,9 +215,30 @@
[(>= j* j) (matrix-ref M (+ i* 1) (+ j* 1))])]))))
#| from bug report 13264:
I have two problems with matrix-set!.
1. When I enable matrix-set!
(require htdp/matrix)
(define M (build-matrix 2 3 (λ (i j) (* (expt 2 i) (expt 3 j)))))
(matrix-set! M 1 2 'a)
(eq? (matrix-ref M 1 2) 'a)
(equal? M (build-matrix 2 3 (λ (i j) (* (expt 2 i) (expt 3 j)))))
I get the results 'true' and 'true' -- the second one should NOT be true but false.
Because I can't change the snip either, M also displays wrong.
2. I really don't want to enable it in language levels strictly below ASL.
Otherwise the functional model breaks. ** But I do not know how to make teachpacks
depend on the language into which they linked. **
|#
(define (matrix-set! M* i j x)
(define _ (when (is-a? M imatrix%)
(error 'matrix-set! "use functional updates instead")))
(when (is-a? M imatrix%)
(error 'matrix-set! "use functional updates instead"))
(define-values (M n m) (check-matrix 'matrix-ref M* i j))
(vector-set! (matrix-get-mat M) (+ (* i m) j) x)
M*)

View File

@ -1,4 +1,4 @@
#lang scheme/gui
#lang racket/gui
;; 4. integrate with snips

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
;; The first three lines of this file were inserted by DrScheme. They record metadata
;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname matrix-test) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
;(require htdp/matrix-invisible)
@ -50,7 +50,11 @@
(check-expect (matrix-ref m1-minor 0 0) 'a00)
(check-expect (matrix-ref m1-minor 0 1) 'a02)
;; --- IMPERATIVE ---
(check-expect (matrix-ref m1 0 0) 'a00)
;(define m1-modified (matrix-set! m1 0 0 'xxx)) ;; <-------- uncomment this and the test engine breaks
;(check-expect (matrix-ref m1 0 0) 'xxx)
;; --- IMPERATIVE ---
;; see comment in matrix-unit.rkt
;; ---------------------------------
;; (define M-imperative (build-matrix 2 3 (λ (i j) (* (expt 2 i) (expt 3 j)))))
;; (define M-modified (matrix-set! M-imperative 0 0 'xxx))
;; (check-expect (matrix-ref M-modified 0 0) 'xxx)
;; (check-expect (matrix-ref M-imperative 0 0) 'xxx)