In reply to Chang Y. Chung.

Yes, you're correct. This combines two issues: nuances of the LAG function and the way logic can be "short-circuited" in an IF/THEN statement. Many programming languages have similar behaviors for only partially evaluating a logical statement, and knowing how it works can help you to create more efficient programs. However, it's often unwise to include a function that can *change* a value within a logical test (ex in C/C++/Java: if x==null && c++>3). LAG is one of those functions that changes the state of the queue by invoking it, and that's not always obvious, is it?