[MWForum]Dotimes (re: wish list)

Mike Sandy mwforum@lists.mathcats.com
Sun, 24 Nov 2002 16:31:22 -0000


Part of my MW wish list was:

 "ADDITIONAL PRIMITIVES:
 ..
 REPCOUNT
 FOR instead of/as well as DOTIMES though if the latter is kept,
     change the initial variable value to 1 instead of 0
     - in line with REPEAT
 "..

Daniel wrote:

"Why 1 instead of 0? If you argue that the first turtle is t1,
 I think the first turtle should be t0.

 I like these behaviours:

 dotimes [i 12] [show remainder :i 4]
 ....

 dotimes [i 12] [show remainder :i 2]
 ....
 cg dotimes [i 30] [
  ifelse 0 = remainder :i 2 [pu] [pd]
  setpos list (20 * int :i / 2) (100 - 200 * remainder :i 2)
  ]
 "..

 There will always be some programs for which the range: 0 to n-1,
 is preferable to: 1 to n, I've written both and so I'm sure have you,
 but that was not the point I was making.

 I notice that REPCOUNT was included in your group "wish list",
 but no mention of removing DOTIMES.

 If both REPCOUNT and DOTIMES are present then I am arguing
 on the basis of consistency, for the same range.

 DOTIMES is equivalent to REPEAT+REPCOUNT. In MSWlogo, Imagine (others?)
 REPCOUNT runs from 1 to n. It doesn't have to of course.

 For practised programmers it may be little effort to
 remember the different ranges but for young learners
 it is yet another item, to add to the exceptions. So make the ranges the
same.
 The reason I chose an initial value of 1, was
 I use MSWlogo as well as MW, as I'm sure do others, in which
 case a change for the range of REPCOUNT would be a disadvantage. What
 about yourself?

 You suggest changing the first turtle to t0 and indeed, how many
 programs have  we seen involving something like

 DOTIMES[i :n][...tto word "t :i+1..]?

 However, for a young learner particularly, the association of FIRST turtle
with t1,
 I guess, is more useful, but I'm in no position to judge whether this is
 important.  What was in the mind of MW originators in  choosing t1?
 MSWLogo has 0 as the first turtle but it also has turtles -1, -2, -3!

In spite of these arguments I would guess that there will be no changes to
the main
primitives, for backward compatibility, so REPCOUNT, if it appears, on my
argument should range from 0 to n-1.

 Meanwhile a program for FOR :
 e.g. for[i 1 10 1.2][pr :i * :i]
      for[i 1 10 2][for[j 1 10 1][pr :i * :j]]


to for :list :inst
 local (list first :list "q5z "v5i "v5f "d5v )
 make "q5z first :list
 make "v5i item 2 :list
 make "v5f item 3 :list
 make "d5v item 4 :list
 make :q5z :v5i
 repeat 1 + int (:v5f - :v5i) / :d5v
   [run :inst
    make :q5z :d5v + thing :q5z
   ]
end

 The variable names, hopefully won't clash with other program names.
 Anyone find conditions under which it won't work?

 Mike