blogWhen parentheses matter

Recently I've run into an issue that can be summarized by the following code snippet:

 


Question 1. Will   and   have the same value? (Before reading the answer you may want to answer the question yourself.)

Test. Let's add two lines of code   and look at the output:   Why so?

Answer. The first syntax is used to access constant attributes, so the string is the value of the attribute   of class  . In the second case there is no immediate qualified call on   and it is considered as a reference to the type object for type   and has a type  . Accidentally class   declares a feature   that returns a run-time name of the associated type. (The exclamation mark in front of it indicates that the type is attached.)


Are there other cases when enclosing types in braces affects code semantics? Yes: there are open arguments in agent declarations!

Question 2. What would be result of the code above if assignment to   and   are changed into the following?  

Test. The same print statements give us  

Answer. The first syntactical construct corresponds to the declaration of an agent with an open target and produces an agent object of type  . The actual target is then passed as an argument to the feature  . In the second case the target is closed and the agent has type  . This explains the output we get.

Final question for curious developers: what part in the second example is redundant and can be removed without affecting execution?

Syndicate content