Say I have a data type defined as follows:
data Constraint=type1(Lab al,Lab a2)| type2(Lab a1,TypeRoot tt)|....
where the general pattern is that the first argument of each constructor is of type 'Lab'. Is there then, an efficient/clear way of expressing a pattern match to do the following?
for (Constraint cc <- constraints)
if( type1(Lab label,_):= cc || type2(Lab label,_):=cc || .... )
//do something useful with label. Infact, this snippet of code appears within
//a function body, and I need to perform the match for a specific label; as follows:
if(label==labelOfInterest) return cc;
While I'm at this, and against StackOverflow's recommendation of asking one question/thread, does Rascal support simple Java-like recursions?
You can check for the presence of a field by way of the
has
operator. See the Rascal Tutor for details.Your code would then become something like:
or even better: