![]() |
|
Navigation |
Synopsis Annotation without a value.
Description An Rascal:Declarations/Annotation can be associated with any node value
(including any Rascal:AlgebraicDataType).
This error is generated when the value of an annotation is requested but has not been defined.
Remedies:
Examples
rascal>data Fruit = apple(int n) | orange(int n); ok rascal>anno str Fruit @ quality; ok rascal>piece = orange(13); Fruit: orange(13) rascal>piece @ quality; |stdin:///|(0,5,<1,0>,<1,5>): NoSuchAnnotation("quality")Use the unary postfix operator isDefined ? to check whether the quality annotation is set:
rascal>piece @ quality?;
bool: false
Use the ternary operator ifDefinedElse ? to compute an alternative value when the quality annotation is not set:
rascal>piece @ quality ? "no quality value";
str: "no quality value"
We can also catch the NoSuchAnnotation error. First import the Rascal exceptions (which are also included in Prelude )
and IO :
rascal>import Exception; ok rascal>import IO; ok rascal>try piece @ quality; catch NoSuchAnnotation(l): println("No such annotation: <l>"); No such annotation: quality okFinally, we can just assign a value to the quality annotation:
rascal>piece @ quality = "excellent"; Fruit: orange(13)[ @quality="excellent" ] rascal>piece @ quality; str: "excellent" ![]() |