Programming Corner from Icon Newsletter 37


November 1, 1991; Icon Versio 8

Rick Fonorow sent us this amusing tale of a strange encounter:
I have been doing a great deal of C programming lately, but at work I wrote an ICS "smart diff" in Icon. Well, the following lines made me waste over an hour!
/*if find (oldstring, line) then break */
if find(newstring, line) then break
I thought I was going nuts -- until it dawned on me that the first find() was getting executed! (Then I realized I was using the C not the Icon style comment.)

In Icon, these lines parse fine. They test to see whether the size of the first if find() ... expression is null and multiplies that by the result of the second if find() ... expression if it is null.

Here's a puzzler: Consider a chain of exchanges of the form
x1 :=: x2 :=: x3 :=:  :=: xn
Suppose, for concreteness, tha
x1 = 1, x2 = 2, x3 = 3, xn = n
before the expression above is evaluated. What are their values afterwards? Why? And can you think of a practical use for this kind of thing?

Icon home page