array-freeze! also makes the underlying storage immutable

This commit is contained in:
Alex Shinn 2024-09-11 10:13:54 +09:00
parent 0516e62b0b
commit 2acef43da7
3 changed files with 19 additions and 0 deletions

View file

@ -334,6 +334,7 @@
(define (array-freeze! array)
(%array-setter-set! array #f)
(make-immutable! (array-body array))
array)
;; Indexing

View file

@ -46,4 +46,9 @@
specialized-getter specialized-setter
array-freeze!
)
(cond-expand
(chibi
(import (only (chibi) make-immutable!)))
(else
(begin (define-syntax make-immutable! (syntax-rules () ((_ x) #f))))))
(include "base.scm"))

View file

@ -2188,6 +2188,19 @@
(array-curry (list*->array 3 '(((4 7) (2 6)) ((1 0) (0 1))))
2)
0)))
(let* ((A (array-copy
(make-array (make-interval '#(0 0) '#(10 10))
(lambda (i j) (inexact (+ (* i 10.) j))))
f32-storage-class))
(A3 (array-ref (array-curry A 1) 3)))
(test 37. (array-ref A 3 7))
(test 37. (array-ref A3 7))
(array-set! A 0. 3 7)
(test 0. (array-ref A 3 7))
(test 0. (array-ref A3 7))
(array-freeze! A)
(test-error (array-set! A 1. 3 7))
(test-error (array-set! A3 1. 7)))
;; (test-error
;; (array-curry (make-array (make-interval '#(0 0) '#(1 1)) list) 0))