Axel Reichert
2024-04-18 06:02:29 UTC
Hello,
Guile has a literal syntax for vectors
#(1 2 3)
so that
(vector-ref #(1 (+ 2 3) 4) 1)
returns
(+ 2 3)
but also a "constructor"
(vector 1 (+ 2 3) 4)
so that
(vector-ref (vector 1 (+ 2 3) 4) 1)
returns
5
There is a literal syntax for arrays, too,
#2((2 1) (5 6))
so that
(array-ref #2((2 1) (5 6)) 1 1)
returns
6
But I did not find an array "constructor" syntax that allows me to
create an array such as
#2((2 1) ((+ 2 3) 6))
resulting in
#2((2 1) (5 6))
as above. How can I then create a "calculated" array, apart from filling
an array with 0 first
(define m (make-array 0 2 2))
and then changing every element with
(array-set! m 2 0 0)
(array-set! m 1 0 1)
(array-set! m (+ 2 3) 1 0)
(array-set! m 6 1 1)
?
Common Lisp's hyperspec show
(make-array '(4 2 3) :initial-contents
'(((a b c) (1 2 3))
((d e f) (3 1 2))
((g h i) (2 3 1))
((j k l) (0 0 0))))
as an example.
Pointers appreciated!
Axel
Guile has a literal syntax for vectors
#(1 2 3)
so that
(vector-ref #(1 (+ 2 3) 4) 1)
returns
(+ 2 3)
but also a "constructor"
(vector 1 (+ 2 3) 4)
so that
(vector-ref (vector 1 (+ 2 3) 4) 1)
returns
5
There is a literal syntax for arrays, too,
#2((2 1) (5 6))
so that
(array-ref #2((2 1) (5 6)) 1 1)
returns
6
But I did not find an array "constructor" syntax that allows me to
create an array such as
#2((2 1) ((+ 2 3) 6))
resulting in
#2((2 1) (5 6))
as above. How can I then create a "calculated" array, apart from filling
an array with 0 first
(define m (make-array 0 2 2))
and then changing every element with
(array-set! m 2 0 0)
(array-set! m 1 0 1)
(array-set! m (+ 2 3) 1 0)
(array-set! m 6 1 1)
?
Common Lisp's hyperspec show
(make-array '(4 2 3) :initial-contents
'(((a b c) (1 2 3))
((d e f) (3 1 2))
((g h i) (2 3 1))
((j k l) (0 0 0))))
as an example.
Pointers appreciated!
Axel