Kenneth Tilton
5/12/2015 12:53:00 PM
On Monday, May 11, 2015 at 7:39:43 PM UTC-4, Kaz Kylheku wrote:
> On 2015-05-10, WJ <w_a_x_man@yahoo.com> wrote:
> > Erik Naggum wrote:
> >>
> >> (defun filtered-input (predicate prompt repeat-prompt)
> >> (loop initially (format *query-io* prompt)
> >> for local-input = (read *query-io*)
> >> until (funcall predicate local-input)
> >> do (format *query-io* repeat-prompt)
> >> finally (return local-input)))
> >
> > Why was (format *query-io* prompt) put inside of the LOOP?
> > Is it executed more than once?
>
> No; it is the argument of an initially clause, which specifies
> some evaluation to be done before the first iteration (in the "loop prologue"
> part of the expanded form).
>
> > Isn't it executed before
> > the looping starts? Why wasn't it put outside of the loop?
>
> For the same reason that i = 0 isn't put outside the loop in
>
> for (i = 0; i < n; i++) ...
>
> "outside the loop construct" isn't where "the looping starts". The looping, as
> it were, starts, roughly, when the first test is made which can determine
> whether any of the repeated parts of the loop will or will not execute.
>
> (For a simple while loop construct like (while cond body ...), this is indeed
> right inside the loop; no execution enclosed in the loop form is prior
> to the start of the looping.)
>
> > Putting it inside of the loop accomplishes nothing but
> > increasing the size of the code.
>
> It is not obvious that this would be the case, even if it were
> executed more than once. Unless you mean, "increases the size of the
> source code by the symbol 'initially'", rather than the object code.
>
> The answer to that is that Erik Naggum wasn't the type of coder who worried
> about minimizing token count in the source code.
>
> It is tidy to have everything in the loop, even if you have to pay
> for that with extra clause keywords to put it all there.
I wonder why WJ did not complain about the finally clause.
One mistake here is that the initially and finally clauses are indeed part of the loop form -- without them it don't work. The confusion is thinking that loop contains only iteration. But iteration tends to involve also initialization and finalization, so loop like any good ball of mud includes all the needed ingredients.
WJ's big mistake is taking the name of the construct literally, but tedious people tend that way.
-hk