home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / misc / 2925 < prev    next >
Encoding:
Text File  |  1992-09-03  |  3.5 KB  |  91 lines

  1. Newsgroups: comp.lang.misc
  2. Path: sparky!uunet!mcsun!news.funet.fi!funic!news.cs.hut.fi!news!Ari.Huttunen
  3. From: Ari.Huttunen@hut.fi (Ari Juhani Huttunen)
  4. Subject: Sather loops (was Re: Scientists as ...
  5. In-Reply-To: bevan@cs.man.ac.uk's message of 30 Aug 92 17:25:05 GMT
  6. Message-ID: <ARI.HUTTUNEN.92Sep4021832@supergirl.hut.fi>
  7. Sender: usenet@cs.hut.fi (Uutis Ankka)
  8. Organization: Helsinki University of Technology, Finland
  9. References: <17opl4INN5gb@roundup.crhc.uiuc.edu> <17ov89INNdls@network.ucsd.edu>
  10.     <ARI.HUTTUNEN.92Aug30182130@hulk.hut.fi>
  11.     <BEVAN.92Aug30182505@tiger.cs.man.ac.uk>
  12. Date: Fri, 4 Sep 1992 00:18:32 GMT
  13. Lines: 76
  14.  
  15. ! In article <ARI.HUTTUNEN.92Aug30182130@hulk.hut.fi> Ari.Huttunen@hut.fi (Ari Juhani Huttunen) writes:
  16. !    Yes, I would myself like to see these loop-constructs in Sather:
  17.  
  18. !   loop       until <xxxx> loop   while <xxxx> loop  for <xxxx> to <yyyy> loop
  19. !     <xxxx>     <yyyy>              <yyyy>             <zzzz>
  20. !   end        end                 end                end
  21.  
  22.                    ^
  23.                    |
  24.                    | Forget that one.
  25.  
  26. ! IMHO the above are quite poor syntax for expressing the kinds of loops
  27. ! that I see in numerical code.  Quite often it is possible to work in
  28. ! parallel, and all the above do is make it harder to extract the
  29. ! parallelism (of course so does the FORTRAN notation, but there is not
  30. ! reason to make the same mistake :-).
  31.  
  32. I can't know what kinds of loops you see in numerical code, so I can't
  33. comment on that. I got the impression from the previous article that
  34. a for-loop is wanted. Now it is not wanted?
  35.  
  36. As for the parallelism... You *do not* extract parallelism from
  37. a sequential program. You design a parallel program. That is not
  38. the same thing. Extracting parallelism from a sequantial loop does
  39. not help 0.01 cents if the computer has 64000 processors and now
  40. it uses 3 of them instead of 1.
  41.  
  42. !  In the cases where it is not
  43. ! numerical, syntax like the above is often useless as it is usually
  44. ! restricted so that you can only iterate over integer indices (cf
  45. ! Oberon-2).  Note some languages get this right and let you iterate
  46. ! over whatever you want e.g. Eiffel and C (given Sather's parentage I
  47. ! guess it does to) 
  48.  
  49. Sather has the same loop construct that Eiffel has, and it is written
  50. on my list. The reason why I put the for-loop in the list is that it
  51. is so common. Take a look at this piece of code from the Sather library:
  52.  
  53.       -- Clear out the array. 
  54.       i:INT; until i=asize1 loop
  55.      j:INT; until j=asize2 loop
  56.         k:INT; until k=asize3 loop
  57.            [i,j,k]:=void;
  58.            k:=k+1;
  59.         end; -- loop
  60.         j:=j+1;
  61.      end; -- loop
  62.      i:=i+1; 
  63.       end; -- loop
  64.  
  65. With the for-loop it becomes shorter and much easier to read. To see
  66. what I mean, note that at the first sight, you look at the beginning 
  67. of the rows and see 'for ...'. You immediately notice a keyword. In
  68. contrast the above code has 'k:INT; ...' at the beginning. 
  69.  
  70.       -- Clear out the array. 
  71.       for i:INT to asize1 loop
  72.      for j:INT to asize2 loop
  73.         for k:INT to asize3 loop
  74.            [i,j,k]:=void;
  75.         end; -- loop
  76.      end; -- loop
  77.       end; -- loop
  78.  
  79. You wouldn't need the for-loop for iterating over the elements of a list
  80. (for example), so it need not be overly general. The existing loop is
  81. perfect for that. You could, however, have something like:
  82.  
  83.     for r=0.0 to 5.3 step 0.1 loop
  84.         ...
  85.     end
  86. --
  87. ...............................................................................
  88. Ari Huttunen                      Any similarity to other alien life forms
  89.                           is purely coincidental.
  90.                           <Alien 3 misquote>
  91.