Paul Dufresne
2005-10-28 20:18:41 UTC
I am trying to make a small <array2d> module, as it seems goo have
no arrays yet. I was first thinking to make multi-dimensions arrays
quite like in Dylan, using tuples for specifying array size and indexs.
Well, that was mostly why I wanted to use zip for, and my need to map
a function over a zip. But now, I am trying to do a simple immutable 2d
array. Immutable, in the sense that when you want to replace an element
of the array, the array pass as an argument stay unchanged after the
call, but returns a new array with the element changed in it.
This is almost the same semantics as elt-setter, except that would be
an immutable one.
Then my suggestion:
I would suggest to replace the name of current elt-setter to elt-setter!
and
add a new elt-setter with signature: (v|<any> x|<col> k|<any>) => <col>
where the returned collection would have [x k] changed, but would leave
x unchanged (of course since x is immutable).
For completeness, here is my totally untested code up to date (that is
part
of pousse game of ICFP 1998 I am trying to write in Goo):
(use goo)
(dc <array2d> (<any>)) ; immutable 2d array ; indexs debutent a zero
(dp contenu (<array2d> => <vec>))
(dp width (<array2d> => <int>))
(dp height (<array2d> => <int>))
(dm creer-matrice ( hauteur|<int> largeur|<int> => <array2d>)
(make <array2d> contenu (fab <vec> (* hauteur largeur) )
height hauteur width largeur))
(df 2d-1d ( i|<int> j<int> ar|<array2d> => <int> )
(+ (* (ar width) i) j))
(dm obtenir-elem (i|<int> j|<int> array|<array> coord|<tup> => <any>)
( elt (array contenu) (2d-1d i j array)))
(df remplace ( val pos|<int> col|<seq> )
(elt-setter val col pos))
(export
creer-matrice ; ( hauteur|<int> largeur|<int>=> <array2d> )
obtenir-elem ; ( i|<int> j|<int> array|<array2d> => <any> ) ;index
debutent a zero
remplace ; ( newvalue|<any> i|<int> j|<int> oldar|<array2d>=>
<array2d> ) ; ar n'est pas modifier
)
no arrays yet. I was first thinking to make multi-dimensions arrays
quite like in Dylan, using tuples for specifying array size and indexs.
Well, that was mostly why I wanted to use zip for, and my need to map
a function over a zip. But now, I am trying to do a simple immutable 2d
array. Immutable, in the sense that when you want to replace an element
of the array, the array pass as an argument stay unchanged after the
call, but returns a new array with the element changed in it.
This is almost the same semantics as elt-setter, except that would be
an immutable one.
Then my suggestion:
I would suggest to replace the name of current elt-setter to elt-setter!
and
add a new elt-setter with signature: (v|<any> x|<col> k|<any>) => <col>
where the returned collection would have [x k] changed, but would leave
x unchanged (of course since x is immutable).
For completeness, here is my totally untested code up to date (that is
part
of pousse game of ICFP 1998 I am trying to write in Goo):
(use goo)
(dc <array2d> (<any>)) ; immutable 2d array ; indexs debutent a zero
(dp contenu (<array2d> => <vec>))
(dp width (<array2d> => <int>))
(dp height (<array2d> => <int>))
(dm creer-matrice ( hauteur|<int> largeur|<int> => <array2d>)
(make <array2d> contenu (fab <vec> (* hauteur largeur) )
height hauteur width largeur))
(df 2d-1d ( i|<int> j<int> ar|<array2d> => <int> )
(+ (* (ar width) i) j))
(dm obtenir-elem (i|<int> j|<int> array|<array> coord|<tup> => <any>)
( elt (array contenu) (2d-1d i j array)))
(df remplace ( val pos|<int> col|<seq> )
(elt-setter val col pos))
(export
creer-matrice ; ( hauteur|<int> largeur|<int>=> <array2d> )
obtenir-elem ; ( i|<int> j|<int> array|<array2d> => <any> ) ;index
debutent a zero
remplace ; ( newvalue|<any> i|<int> j|<int> oldar|<array2d>=>
<array2d> ) ; ar n'est pas modifier
)
--
http://www.fastmail.fm - Email service worth paying for. Try it for free
http://www.fastmail.fm - Email service worth paying for. Try it for free