home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / scheme / 2050 < prev    next >
Encoding:
Internet Message Format  |  1992-08-19  |  2.1 KB

  1. Path: sparky!uunet!grebyn!pyrdc!gossip.pyramid.com!decwrl!elroy.jpl.nasa.gov!usc!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!nigel.msen.com!math.fu-berlin.de!zrz.tu-berlin.de!cs.tu-berlin.de!lenin!mfx
  2. From: mfx@cs.tu-berlin.de (lala)
  3. Newsgroups: comp.lang.scheme
  4. Subject: Re: Initializing vector elements
  5. Message-ID: <MFX.92Aug19102656@lenin.cs.tu-berlin.de>
  6. Date: 19 Aug 92 08:27:30 GMT
  7. References: <PK.92Aug19100516@talitiainen.cs.tut.fi>
  8. Sender: news@cs.tu-berlin.de
  9. Distribution: comp
  10. Organization: Technical University of Berlin, Germany
  11. Lines: 47
  12. In-Reply-To: pk@cs.tut.fi's message of Wed, 19 Aug 1992 08:05:16 GMT
  13.  
  14. In article <PK.92Aug19100516@talitiainen.cs.tut.fi> pk@cs.tut.fi (Kellom{ki Pertti) writes:
  15. [...problems with make-vector...]
  16.    Has there been discussion about what the second argument of
  17.    make-vector should be? I would like to see make-vector to take a
  18.    procedure that would be called for every element of the vector. Thus
  19.    the example would be written as
  20.  
  21.      (define m (make-vector 10 (lambda () (make-vector 10 0))))
  22.  
  23.    This seems like a Scheme way of doing things. I know it is possibly
  24.    too late to change it, but I thought I'd bring it up just for the sake
  25.    of discussion.
  26.  
  27.    If anyone can prove me wrong by giving an elegant way of defining m
  28.    within R4RS Scheme, I'll be delighted.
  29.  
  30. You are nearly right -- IMHO, the Right Way is to give the init
  31. procedure the index of the element to create:
  32.  
  33.      (define m (make-vector 10 (lambda (i) (make-vector 10 0))))
  34.  
  35. like, in,
  36.  
  37.    (make-vector 10 identity) => #(0,1,2,3,4,5,6,7,8,9)
  38.  
  39. or,
  40.  
  41.    (make-vector 3 (lambda(x) (make-vector 3 (lambda (y)(if (= x y) 1 0)))))
  42.  
  43. => #(#(1,0,0)
  44.      #(0,1,0)
  45.      #(0,0,1))
  46.  
  47.    --
  48.    Pertti Kellom\"aki (TeX format)  #       These opinions are mine, 
  49.      Tampere Univ. of TeXnology     #              ALL MINE !
  50.      Software Systems Lab       #  (but go ahead and use them, if you like)
  51.  
  52.  
  53. (Just my humble contribution to creeping featurism)
  54.  
  55. Markus
  56. -- 
  57. Markus Freericks    | email: mfx@cs.tu-berlin.de    
  58. TU Berlin Sekr.FR 2-2     | phone: +49-30-314-21390
  59. Franklinstr.28/29    | priv.: +49-30-872523
  60. D-1000 Berlin 10    |"Inertia makes the world go 'round."
  61.