Re: suggest an elt-setter for immutable collections (mostly <seq>)

"Paul Dufresne" <[email protected]> Sat, 29 Oct 2005 12:46:46 -0400
Newsgroups gmane.comp.lang.goo.general
Message-ID <[email protected]>
I have made a simple implementation of my-elt-setter for <tup>.
Also, I have revised my code for array2d.

I have revised my <array2d> code, and have made a simple implementation
of elt-setter for <tup>, called elt-setter-tup.

; Copyright Paul Dufresne, this code is released under the same
conditions as of the Expat License
; see http://www.jclark.com/xml/copying.txt

(use goo)

(dc <array2d> (<any>)) ; immutable 2d array ; indexs debutent a zero
(dp! contenu (<array2d> => <tup>))
(dp width (<array2d> => <int>))
(dp height (<array2d> => <int>))

(dm elt-setter-tup ( newval laseq i)
  (cat [laseq 0 i] (tup newval) [laseq (+ i 1) *]))

(dm creer-matrice ( hauteur|<int> largeur|<int> => <array2d>)
  (new <array2d> contenu (fab <tup> (* hauteur largeur) )
     height hauteur width largeur))

(dm from2dto1d ( i|<int> j|<int> ar|<array2d> => <int> )
  (+ (* (width ar) i) j))
  
(dm obtenir-elem (i|<int> j|<int> array|<array2d> => <any>)
  ( elt (contenu array) (from2dto1d i j array)))
  
(dm remplace (newvalue|<any> i|<int> j|<int> oldar|<array2d> =>
<array2d>)
  (set resultat (creer-matrice (height oldar) (width oldar)))
  (set (contenu resultat)
   (elt-setter-tup newvalue (contenu resultat) (from2dto1d i j oldar)))
  resultat)
  
(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 - Or how I learned to stop worrying and
                          love email again


_______________________________________________
Googoogaga mailing list
[email protected]
https://lists.csail.mit.edu/mailman/listinfo/googoogaga