The Cool FAQ



A few questions seem to come up often in the implementation of Cool compilers.
Q. Will someone please explain the semi-colon syntax to me?!

A. Semi-colons do not play the same role in Cool as in Pascal and C. A semi-colon is used to terminate expressions that appear in expression lists, such as in a begin-end block or in a case. You cannot put a semi-colon any place you like; see Section 11 of the CoolAid.

Q. The following Cool program goes into an infinite loop. Is this a bug in the compiler?

class Main is a : Main <- new Main; ... end;

A. No, this is not a bug. This program has an infinite loop in the initialization of objects of class Main: to initialize an object of class Main, another object of class Main must be allocated and initialized, etc.

Q. Why doesn't the following assignment change the value of x?

x = 1

A. Because it isn't an assignment. "=" tests for equality in Cool; "<-" is the assignment operator.