From: Bruno H. <br...@cl...> - 2017-12-31 21:40:51
|
Hi Jörg, > Here's some vocabulary I made up: > > Driver Variable(s) > The main variable(s) that permit iteration, e.g. the array index FOR # ACROSS. > One may or not consider the vector that is constant through the iteration as a > driver variable too. > > Derived Variables > Those are derived from driver variables, e.g. all variables in a true destructuring pattern. > A "true" destructuring pattern is a list, i.e. either nil or a cons, not another symbol. > > Named variables > Those explicitly named by the user of LOOP. > Note that this also includes collecting INTO # etc. but that's irrelevant for now. > > Clearly in FOR x IN ..., x is nevertheless a derived variable of some internal > driver variable necessary to hold the list whose CAR is set to x during iteration. > > FOR x ON ... is peculiar, because users expect x to *be* the driver variable. So we > shall meet that expectation as a special rule. > > Regarding for-as-arithmetic, it can be debated whether we should make driver and named variable collapse. I don't think we have much of a choice. The wording in CLHS 6.1.2.1.1 matters. It says: "The variable var is bound to the value of form1 in the first iteration and is stepped[1] by the value of form3 in each succeeding iteration, or by 1 if form3 is not provided." So "stepping" means to modify the value of var. Case UPTO: (loop for i from 0.5 upto 10 finally (return i)) The text is clear: "the loop terminates when the variable var passes the value of form2". So, in your terms, the driver variable is the named variable. The expected result is 10.5. clisp and sbcl get this right. Case BELOW: (loop for i from 0.5 below 10 finally (return i)) The text is clear: "These keywords stop iteration just before the value of the variable var reaches the value supplied by form2". So, either the driver variable is different from the named variable, or the addition during each stepping is performed twice. The expected result is 9.5. clisp and sbcl both get this wrong. Case TO: (loop for i from 0.5 to 10 finally (return i)) The wording is not clear, but it is probably meant to execute like UPTO. clisp and sbcl return the expected value 10.5. Bruno |