From: <Joe...@t-...> - 2017-11-24 15:09:15
|
Hi, The following two loops produce identical results and side-effects. Surprise? (loop for x across "abc" and for z on (list 1) do (princ x) finally (return (cons x z))) (loop for x across "abc" for z on (list 1) do (princ x) finally (return (cons x z))) a -> (#\b) One *might* have expected "AND", implying parallel stepping, to assign either all values, or nothing when iteration terminates. However, in the above case, x clearly has the value #\b from a second round, but there's only one iteration -- one would think. This contributes to the topic of non-obvious values of variables within FINALLY clauses. So the question IMHO is: when, if ever, shall termination tests be combined, such that all tests (from FOR clauses) are performed prior to assigning new values? Testing varying inputs with clisp's LOOP macro, I've seen tests sometimes combined, others not. The picture is not yet clear to me. Combined test & stepping might look like this: (when (OR (<= (length vector) index) (atom z)) (LOOP-FINISH)) (PSETQ x (AREF vector index) z (cdr z)) ... (INCF index) [From an implementation POV, combined tests might require more internal variables (cf. e.g. internals of FOR HASH), thus be slower.] Regards, Jörg |