wgg@CS.WASHINGTON.EDU (05/02/90)
Richard Goerwitz's answer is correct: data backtracking is possible only if the control backtracks to the expression involved. In the expressions z <- 1 z = 10 each has an implicit semi-colon at the end: z <- 1; z = 10; The first semicolon delimits the assignment from the comparison, and prevents backtracking back into the assignment from the comparison if it fails. Thus the assignment expression is ``bounded'' by the semicolon, and cannot be resumed once it has yielded a result. On the other hand, in the expression (z <- i) & (z = 10) The assignment itself is not bounded, and it is possible to backtrack from the comparison into the assignment, if the comparison fails. In most cases the semantics of traditional-appearing control structures in Icon is to bound an expression so that it produces only one result. This prevents ``surprises'', and also avoids the overhead of often unneeded backtracking. Hence the control structures if-then and while-do bound their control expressions (but not their bodies!). Of course, it is easy to phrase ``backtracking'' versions of these control structures: basic backtracking ------------------------------------------------------- if X then Y else Z (X & Y) | Z while X do Y every X do Y X;Y X & Y return X suspend X One could easily argue that I've chosen the wrong analogues. (Suppose that the analogue for while-do resumes X only if Y fails, otherwise X just starts over. Consider, too, its behavior when Y contains a break.) Bill Griswold