viatra / EMF-IncQuery

This repository is only kept for historic reasons. All development happens on eclipse.org
http://eclipse.org/viatra
13 stars 4 forks source link

Element-of-collection operator #308

Closed bergmanngabor closed 11 years ago

bergmanngabor commented 11 years ago

How about an \in / element-of operator? E.g. to iterate over elements in a list stored as a comma-separated string attribute:

Element \in eval(S.split(","))

The right hand-side is a scalar value of type collection / array, e.g. returned by an eval expression. This is NOT the way to handle multi-valued EMF references, which are "enumerated" by EMF-IncQuery automatically.

Now we can also use constant literal lists here, and even have the engine handle them more concisely and efficiently:

pattern red(Deck, Card) = {
    find contains(Deck, Card);
    Card.suite(Card, Suite);
    Suite \in {HEARTS, DIAMONDS}; 
}

This would have equivalent meaning to:

pattern red(Deck, Card) = {
    find contains(Deck, Card);
    Card.suite(Card, Suite);
    Suite == HEARTS; 
} or {
    find contains(Deck, Card);
    Card.suite(Card, Suite);
    Suite == DIAMONDS; 
}

Or perhaps even closer to this:

pattern red(Deck, Card) = {
    find contains(Deck, Card);
    Card.suite(Card, Suite);
    find diamondsOrHearts(Suite); 
}
pattern diamondsOrHearts(Suite) = {
    Suite == DIAMONDS; 
} or {
    Suite == HEARTS;
}
bergmanngabor commented 11 years ago

Priority is very low as of now, since we have not needed this yet.

bergmanngabor commented 11 years ago

Migrated to https://bugs.eclipse.org/bugs/show_bug.cgi?id=398783