Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » def expression?
def expression? [message #443993] Fri, 31 July 2009 16:08 Go to next message
Joel Greenyer is currently offline Joel GreenyerFriend
Messages: 170
Registered: July 2009
Senior Member
Hi,
I'm confused whether or how the "def:" expression is supported. My intuition is that I e.g. type

def: s: String = 'Hello'

in the console and that I can use the variable s when evaluating subsequent expressions. However, that doesn't seem to work.

What am I missing?

Joel
Re: def expression? [message #444438 is a reply to message #443993] Fri, 31 July 2009 17:10 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4186
Registered: July 2009
Senior Member
Hi Joel

def defines an additional feature Property/Operation in the prevailing
context.

That feature can be used in subsequent expressions.

[Arguably it should be useable in preceding expressions too, though a
detailed reading of the OCL specification of Environment mutation seems
to imply that it can only be used in nested environments.] Anyway,
MDT-OCL currently supports subsequent expressions.

If you want to create a variable you should use let or an iterator.

As always "doesn't seem to work" is never a good way of asking for help.
What did you do? What did you expect to happen? What actually happened?
What was the context of your experience? What versions of the software
were you using?

Regards

Ed Willink


Joel Greenyer wrote:
> Hi,
> I'm confused whether or how the "def:" expression is supported. My
> intuition is that I e.g. type
>
> def: s: String = 'Hello'
>
> in the console and that I can use the variable s when evaluating
> subsequent expressions. However, that doesn't seem to work.
>
> What am I missing?
>
> Joel
Re: def expression? [message #450333 is a reply to message #444438] Sat, 01 August 2009 07:57 Go to previous messageGo to next message
Joel Greenyer is currently offline Joel GreenyerFriend
Messages: 170
Registered: July 2009
Senior Member
Ed,
thanks for your explanation.

I'll start by explaining the context of my problem: I'm developing a TGG transformation engine (remember that we've
talked at TOOLS'07) that shall now support OCL constraints/assignments, similar to QVT-R. While matching a precondition
graph, I add matched nodes as bound variables in an OCL environment/evaluationEnvironment. Those variables I can now use
in OCL expressions. Sometimes, it's useful to use let-expressions to define a variable that I can reuse multiple times
in an expression. However, in some cases, I find myself writing the same let-expression again for other constraints.
Then, instead I thought to use a def-expression to define a variable that I can reuse in other constraints. I started
out with a simple expression "def: s: String = 'Hello'" which gave me a error ""inv:" misplaced construct(s)"
So, as so often, I went back to the OCL console and tried the same expression with the same result. I can't really say
what I expected, maybe that there was so particular result and I could just reuse the variable s in subsequent expressions.

I have the feeling that I don't understand def-expressions or that I'm missing something in the way that the OCL engine
works. I'm using OCL 1.3.0.v200901271800 (in the modeling package of the Galileo release).

Thanks for helping

Joel


Ed Willink wrote:
> Hi Joel
>
> def defines an additional feature Property/Operation in the prevailing
> context.
>
> That feature can be used in subsequent expressions.
>
> [Arguably it should be useable in preceding expressions too, though a
> detailed reading of the OCL specification of Environment mutation seems
> to imply that it can only be used in nested environments.] Anyway,
> MDT-OCL currently supports subsequent expressions.
>
> If you want to create a variable you should use let or an iterator.
>
> As always "doesn't seem to work" is never a good way of asking for help.
> What did you do? What did you expect to happen? What actually happened?
> What was the context of your experience? What versions of the software
> were you using?
>
> Regards
>
> Ed Willink
>
>
> Joel Greenyer wrote:
>> Hi,
>> I'm confused whether or how the "def:" expression is supported. My
>> intuition is that I e.g. type
>>
>> def: s: String = 'Hello'
>>
>> in the console and that I can use the variable s when evaluating
>> subsequent expressions. However, that doesn't seem to work.
>>
>> What am I missing?
>>
>> Joel
Re: def expression? [message #450817 is a reply to message #450333] Sat, 01 August 2009 08:40 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4186
Registered: July 2009
Senior Member
Hi Joel

Re-useable let expressions is exactly what I use def's for.

You might find /org.eclipse.qvt/oclsrc/QVTRelation.ocl or
/org.eclipse.qvt.declarative.examples.ocl.royalandloyal/ocls rc/RoyalAndLoyal/RoyalAndLoyal.ocl
helpful. Each may be found in /cvsroot/modeling
org.eclipse.m2m/org.eclipse.qvt.declarative.

I mostly use OCL within the OCL Editor currently available from CVS for
org.eclipse.qvt.declarative. This will be migrating to MDT-OCL for
Helios. (Watch this space for an Update Site announcement).

I'm afraid that I've never used the OCL Console, so I suspect that you
may be hitting a 'multi-line' limitation of a 'single-line' interface.

Regards

Ed Willink


Joel Greenyer wrote:
> Ed,
> thanks for your explanation.
>
> I'll start by explaining the context of my problem: I'm developing a TGG
> transformation engine (remember that we've talked at TOOLS'07) that
> shall now support OCL constraints/assignments, similar to QVT-R. While
> matching a precondition graph, I add matched nodes as bound variables in
> an OCL environment/evaluationEnvironment. Those variables I can now use
> in OCL expressions. Sometimes, it's useful to use let-expressions to
> define a variable that I can reuse multiple times in an expression.
> However, in some cases, I find myself writing the same let-expression
> again for other constraints. Then, instead I thought to use a
> def-expression to define a variable that I can reuse in other
> constraints. I started out with a simple expression "def: s: String =
> 'Hello'" which gave me a error ""inv:" misplaced construct(s)"
> So, as so often, I went back to the OCL console and tried the same
> expression with the same result. I can't really say what I expected,
> maybe that there was so particular result and I could just reuse the
> variable s in subsequent expressions.
>
> I have the feeling that I don't understand def-expressions or that I'm
> missing something in the way that the OCL engine works. I'm using OCL
> 1.3.0.v200901271800 (in the modeling package of the Galileo release).
>
> Thanks for helping
>
> Joel
>
>
> Ed Willink wrote:
>> Hi Joel
>>
>> def defines an additional feature Property/Operation in the prevailing
>> context.
>>
>> That feature can be used in subsequent expressions.
>>
>> [Arguably it should be useable in preceding expressions too, though a
>> detailed reading of the OCL specification of Environment mutation
>> seems to imply that it can only be used in nested environments.]
>> Anyway, MDT-OCL currently supports subsequent expressions.
>>
>> If you want to create a variable you should use let or an iterator.
>>
>> As always "doesn't seem to work" is never a good way of asking for help.
>> What did you do? What did you expect to happen? What actually happened?
>> What was the context of your experience? What versions of the software
>> were you using?
>>
>> Regards
>>
>> Ed Willink
>>
>>
>> Joel Greenyer wrote:
>>> Hi,
>>> I'm confused whether or how the "def:" expression is supported. My
>>> intuition is that I e.g. type
>>>
>>> def: s: String = 'Hello'
>>>
>>> in the console and that I can use the variable s when evaluating
>>> subsequent expressions. However, that doesn't seem to work.
>>>
>>> What am I missing?
>>>
>>> Joel
Re: def expression? [message #460200 is a reply to message #450817] Sun, 02 August 2009 08:21 Go to previous messageGo to next message
Joel Greenyer is currently offline Joel GreenyerFriend
Messages: 170
Registered: July 2009
Senior Member
Hi Ed,
I took a def expression from the royal-and-loyal example

def :
initial : String = self.name.substring(1, 1)

and execute it (in the context of an object that has a "name" attribute). I did that in the OCL console as well as in my
transformation rules. Either way, I get

org.eclipse.ocl.SyntaxException: "inv:" misplaced construct(s)

Any idea? The OCL interpreter/environment does really not have to be set up in any certain way to support def-expressions?

Joel


Ed Willink wrote:
> Hi Joel
>
> Re-useable let expressions is exactly what I use def's for.
>
> You might find /org.eclipse.qvt/oclsrc/QVTRelation.ocl or
> /org.eclipse.qvt.declarative.examples.ocl.royalandloyal/ocls rc/RoyalAndLoyal/RoyalAndLoyal.ocl
>
> helpful. Each may be found in /cvsroot/modeling
> org.eclipse.m2m/org.eclipse.qvt.declarative.
>
> I mostly use OCL within the OCL Editor currently available from CVS for
> org.eclipse.qvt.declarative. This will be migrating to MDT-OCL for
> Helios. (Watch this space for an Update Site announcement).
>
> I'm afraid that I've never used the OCL Console, so I suspect that you
> may be hitting a 'multi-line' limitation of a 'single-line' interface.
>
> Regards
>
> Ed Willink
>
>
> Joel Greenyer wrote:
>> Ed,
>> thanks for your explanation.
>>
>> I'll start by explaining the context of my problem: I'm developing a
>> TGG transformation engine (remember that we've talked at TOOLS'07)
>> that shall now support OCL constraints/assignments, similar to QVT-R.
>> While matching a precondition graph, I add matched nodes as bound
>> variables in an OCL environment/evaluationEnvironment. Those variables
>> I can now use in OCL expressions. Sometimes, it's useful to use
>> let-expressions to define a variable that I can reuse multiple times
>> in an expression. However, in some cases, I find myself writing the
>> same let-expression again for other constraints. Then, instead I
>> thought to use a def-expression to define a variable that I can reuse
>> in other constraints. I started out with a simple expression "def: s:
>> String = 'Hello'" which gave me a error ""inv:" misplaced construct(s)"
>> So, as so often, I went back to the OCL console and tried the same
>> expression with the same result. I can't really say what I expected,
>> maybe that there was so particular result and I could just reuse the
>> variable s in subsequent expressions.
>>
>> I have the feeling that I don't understand def-expressions or that I'm
>> missing something in the way that the OCL engine works. I'm using OCL
>> 1.3.0.v200901271800 (in the modeling package of the Galileo release).
>>
>> Thanks for helping
>>
>> Joel
>>
>>
>> Ed Willink wrote:
>>> Hi Joel
>>>
>>> def defines an additional feature Property/Operation in the
>>> prevailing context.
>>>
>>> That feature can be used in subsequent expressions.
>>>
>>> [Arguably it should be useable in preceding expressions too, though a
>>> detailed reading of the OCL specification of Environment mutation
>>> seems to imply that it can only be used in nested environments.]
>>> Anyway, MDT-OCL currently supports subsequent expressions.
>>>
>>> If you want to create a variable you should use let or an iterator.
>>>
>>> As always "doesn't seem to work" is never a good way of asking for help.
>>> What did you do? What did you expect to happen? What actually happened?
>>> What was the context of your experience? What versions of the
>>> software were you using?
>>>
>>> Regards
>>>
>>> Ed Willink
>>>
>>>
>>> Joel Greenyer wrote:
>>>> Hi,
>>>> I'm confused whether or how the "def:" expression is supported. My
>>>> intuition is that I e.g. type
>>>>
>>>> def: s: String = 'Hello'
>>>>
>>>> in the console and that I can use the variable s when evaluating
>>>> subsequent expressions. However, that doesn't seem to work.
>>>>
>>>> What am I missing?
>>>>
>>>> Joel
Re: def expression? [message #467843 is a reply to message #443993] Mon, 03 August 2009 06:58 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4186
Registered: July 2009
Senior Member
Hi Joel

I've loaded up the Interpreter example. (We really must move this to a
non-example UI feature). I got it working under Ganymede by copying
UML.ecore to the UMLPackageImpl folder - wierd.

It is clear that the Console is there solely to evaluate a single query
that does not change the model. A def: is not a query.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=259922 suggests a variety
of improvements.

Regards

Ed Willink
Re: def expression? [message #468430 is a reply to message #443993] Wed, 05 August 2009 13:46 Go to previous messageGo to next message
Joel Greenyer is currently offline Joel GreenyerFriend
Messages: 170
Registered: July 2009
Senior Member
So, the def-expression is no query and createQuery(String expression) does not work. Instead, I have to use
OCLHelper.defineAttribute(String defExpression), right?
The problem is that I can't find any examples of using the OCL API in the right way to handle different cases of
expressions (queries and def-expression) that I have in my transformation rules.
Could anyone please provide a snippet how to do that or point me to some example that demonstrates how to do it?

Thanks a lot

Joel

Joel Greenyer wrote:
> Hi,
> I'm confused whether or how the "def:" expression is supported. My
> intuition is that I e.g. type
>
> def: s: String = 'Hello'
>
> in the console and that I can use the variable s when evaluating
> subsequent expressions. However, that doesn't seem to work.
>
> What am I missing?
>
> Joel
Re: def expression? [message #479596 is a reply to message #460200] Tue, 11 August 2009 16:40 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 846
Registered: July 2009
Senior Member
--=-U6F5mCtO3V5LduTGHT6X
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi, Joel,

The current "official" OCL Console example does not support def:
expressions by any means. It only supports query expressions (in "M2"
mode) or constraints (in "M1" mode; invariants on classifier selection,
post-conditions on operation selection, derive on attribute selection).
In particular, there is no support for any of the concrete syntax of
context declaration (which includes the "def:" keyword) and the console
internal always constructs this context declaration according to the
selected object.

In your case, the console is prepending to your 'expression' (which
includes the "def:" keyword) a context declaration ending with "inv:"
because it thinks you want to define an invariant constraint or a query.

Cheers,

Christian


On Sun, 2009-08-02 at 10:21 +0200, Joel Greenyer wrote:

> Hi Ed,
> I took a def expression from the royal-and-loyal example
>
> def :
> initial : String = self.name.substring(1, 1)
>
> and execute it (in the context of an object that has a "name" attribute). I did that in the OCL console as well as in my
> transformation rules. Either way, I get
>
> org.eclipse.ocl.SyntaxException: "inv:" misplaced construct(s)
>
> Any idea? The OCL interpreter/environment does really not have to be set up in any certain way to support def-expressions?
>
> Joel
>



--=-U6F5mCtO3V5LduTGHT6X
Content-Type: text/html; charset="utf-8"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.24.1.1">
</HEAD>
<BODY>
Hi, Joel,<BR>
<BR>
The current &quot;official&quot; OCL Console example does not support def: expressions by any means.&nbsp; It only supports query expressions (in &quot;M2&quot; mode) or constraints (in &quot;M1&quot; mode; invariants on classifier selection, post-conditions on operation selection, derive on attribute selection).&nbsp; In particular, there is no support for any of the concrete syntax of context declaration (which includes the &quot;def:&quot; keyword) and the console internal always constructs this context declaration according to the selected object.<BR>
<BR>
In your case, the console is prepending to your 'expression' (which includes the &quot;def:&quot; keyword) a context declaration ending with &quot;inv:&quot; because it thinks you want to define an invariant constraint or a query.<BR>
<BR>
Cheers,<BR>
<BR>
Christian<BR>
<BR>
<BR>
On Sun, 2009-08-02 at 10:21 +0200, Joel Greenyer wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
Hi Ed,
I took a def expression from the royal-and-loyal example

def :
initial : String = self.name.substring(1, 1)

and execute it (in the context of an object that has a &quot;name&quot; attribute). I did that in the OCL console as well as in my
transformation rules. Either way, I get

org.eclipse.ocl.SyntaxException: &quot;inv:&quot; misplaced construct(s)

Any idea? The OCL interpreter/environment does really not have to be set up in any certain way to support def-expressions?

Joel

</PRE>
</BLOCKQUOTE>
<BR>
</BODY>
</HTML>

--=-U6F5mCtO3V5LduTGHT6X--
Re: def expression? [message #479597 is a reply to message #468430] Tue, 11 August 2009 16:42 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. DamusFriend
Messages: 846
Registered: July 2009
Senior Member
--=-N7nqXePYbegdqjxfyRQe
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi, Joel,

If the SDK documentation doesn't provide examples, then your best bet is
to look into the JUnit tests. Search for invocations of the OCLHelper
methods in the org.eclipse.ocl.ecore.tests plug-in, for example. They
should all be covered, IIRC.

HTH,

Christian


On Wed, 2009-08-05 at 15:46 +0200, Joel Greenyer wrote:

> So, the def-expression is no query and createQuery(String expression) does not work. Instead, I have to use
> OCLHelper.defineAttribute(String defExpression), right?
> The problem is that I can't find any examples of using the OCL API in the right way to handle different cases of
> expressions (queries and def-expression) that I have in my transformation rules.
> Could anyone please provide a snippet how to do that or point me to some example that demonstrates how to do it?
>
> Thanks a lot
>
> Joel
>
> Joel Greenyer wrote:
> > Hi,
> > I'm confused whether or how the "def:" expression is supported. My
> > intuition is that I e.g. type
> >
> > def: s: String = 'Hello'
> >
> > in the console and that I can use the variable s when evaluating
> > subsequent expressions. However, that doesn't seem to work.
> >
> > What am I missing?
> >
> > Joel

--=-N7nqXePYbegdqjxfyRQe
Content-Type: text/html; charset="utf-8"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.24.1.1">
</HEAD>
<BODY>
Hi, Joel,<BR>
<BR>
If the SDK documentation doesn't provide examples, then your best bet is to look into the JUnit tests.&nbsp; Search for invocations of the OCLHelper methods in the org.eclipse.ocl.ecore.tests plug-in, for example.&nbsp; They should all be covered, IIRC.<BR>
<BR>
HTH,<BR>
<BR>
Christian<BR>
<BR>
<BR>
On Wed, 2009-08-05 at 15:46 +0200, Joel Greenyer wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
So, the def-expression is no query and createQuery(String expression) does not work. Instead, I have to use
OCLHelper.defineAttribute(String defExpression), right?
The problem is that I can't find any examples of using the OCL API in the right way to handle different cases of
expressions (queries and def-expression) that I have in my transformation rules.
Could anyone please provide a snippet how to do that or point me to some example that demonstrates how to do it?

Thanks a lot

Joel

Joel Greenyer wrote:
&gt; Hi,
&gt; I'm confused whether or how the &quot;def:&quot; expression is supported. My
&gt; intuition is that I e.g. type
&gt;
&gt; def: s: String = 'Hello'
&gt;
&gt; in the console and that I can use the variable s when evaluating
&gt; subsequent expressions. However, that doesn't seem to work.
&gt;
&gt; What am I missing?
&gt;
&gt; Joel
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>

--=-N7nqXePYbegdqjxfyRQe--
Re: def expression? [message #480234 is a reply to message #479597] Fri, 14 August 2009 13:32 Go to previous messageGo to next message
Joel Greenyer is currently offline Joel GreenyerFriend
Messages: 170
Registered: July 2009
Senior Member
Hi Christian,
thanks for pointing me to the JUnit tests. However, I am still a bit lost. Or, maybe, my problem is bit more tricky than
just using def-expressions.

What I am doing is the following: I have a graph matcher that matches typed nodes to eObjects. When named nodes are
bound in the matching process, I add a variable with the node's name and the bound eObject to the OCL
environment/evaluationenvironment. The graph matcher also backtracks at times, and when it does, I remove those
variables corresponding to the back-tracked nodes again from the OCL environment/evaluationenvironment.

Before nodes can be bound, I check OCL constraints that are attached to them. Those constraints
may contain variables that already exist (when the corresponding nodes were bound) or not (when the corresponding nodes
are not yet bound). In the latter case, I catch a parseException and try evaluating the expression again when matching
the next node and so on, until I can successfully evaluate the expression. I put all successfully evaluated expressions
in a map (node where evaluation was successful->expression) and upon backtracking, I put them back into a list of
yet-to-be-evaluated expressions.

Now I'd like to use expressions that allow me to define reusable values (and also operations in the long term).

One general thing that confuses me is that the def-expressions define attributes of some context classifier. In
let-expressions, for example, I just define a variable that I can reuse in the in-expression. That is rather what I
want. I'd just like to create a variable to reuse.

Right now I am thinking of processing the "def: <varname> : <typename> = " part of the def-expression in my own code,
let the OCL-helper evaluate the subsequent expression, and define a variable in the same way I do for my nodes.
Then again I wonder whether the OCL fragmework could help me do that? Or do you have any better idea to define my variables?
Mind, that I also have to "undefine" those variables again when I backtrack past the point of where I successfully
evaluated it.

Thanks for helping

Joel




Christian W. Damus wrote:
> Hi, Joel,
>
> If the SDK documentation doesn't provide examples, then your best bet is
> to look into the JUnit tests. Search for invocations of the OCLHelper
> methods in the org.eclipse.ocl.ecore.tests plug-in, for example. They
> should all be covered, IIRC.
>
> HTH,
>
> Christian
>
>
> On Wed, 2009-08-05 at 15:46 +0200, Joel Greenyer wrote:
>> So, the def-expression is no query and createQuery(String expression) does not work. Instead, I have to use
>> OCLHelper.defineAttribute(String defExpression), right?
>> The problem is that I can't find any examples of using the OCL API in the right way to handle different cases of
>> expressions (queries and def-expression) that I have in my transformation rules.
>> Could anyone please provide a snippet how to do that or point me to some example that demonstrates how to do it?
>>
>> Thanks a lot
>>
>> Joel
>>
>> Joel Greenyer wrote:
>> > Hi,
>> > I'm confused whether or how the "def:" expression is supported. My
>> > intuition is that I e.g. type
>> >
>> > def: s: String = 'Hello'
>> >
>> > in the console and that I can use the variable s when evaluating
>> > subsequent expressions. However, that doesn't seem to work.
>> >
>> > What am I missing?
>> >
>> > Joel
Re: def expression? [message #480245 is a reply to message #480234] Fri, 14 August 2009 14:34 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4186
Registered: July 2009
Senior Member
Hi Joel

I'm not sure about your whole problem but when you mention removing
variables from environments I get very uncomfortable. It is much easier
to created a nested environment for the nested scope and revert to the
outer ebvironment when you want to recover context.

I know Let and Iterate current use dynamically changing environments,
but that is likely to change to nested environments in the next MDT-OCL
release.

Regards

Ed Willink

Joel Greenyer wrote:
> Hi Christian,
> thanks for pointing me to the JUnit tests. However, I am still a bit
> lost. Or, maybe, my problem is bit more tricky than just using
> def-expressions.
>
> What I am doing is the following: I have a graph matcher that matches
> typed nodes to eObjects. When named nodes are
> bound in the matching process, I add a variable with the node's name and
> the bound eObject to the OCL
> environment/evaluationenvironment. The graph matcher also backtracks at
> times, and when it does, I remove those variables corresponding to the
> back-tracked nodes again from the OCL environment/evaluationenvironment.
>
> Before nodes can be bound, I check OCL constraints that are attached to
> them. Those constraints
> may contain variables that already exist (when the corresponding nodes
> were bound) or not (when the corresponding nodes are not yet bound). In
> the latter case, I catch a parseException and try evaluating the
> expression again when matching the next node and so on, until I can
> successfully evaluate the expression. I put all successfully evaluated
> expressions in a map (node where evaluation was successful->expression)
> and upon backtracking, I put them back into a list of
> yet-to-be-evaluated expressions.
>
> Now I'd like to use expressions that allow me to define reusable values
> (and also operations in the long term).
>
> One general thing that confuses me is that the def-expressions define
> attributes of some context classifier. In
> let-expressions, for example, I just define a variable that I can reuse
> in the in-expression. That is rather what I want. I'd just like to
> create a variable to reuse.
>
> Right now I am thinking of processing the "def: <varname> : <typename> =
> " part of the def-expression in my own code, let the OCL-helper evaluate
> the subsequent expression, and define a variable in the same way I do
> for my nodes.
> Then again I wonder whether the OCL fragmework could help me do that? Or
> do you have any better idea to define my variables?
> Mind, that I also have to "undefine" those variables again when I
> backtrack past the point of where I successfully evaluated it.
>
> Thanks for helping
>
> Joel
>
>
>
>
> Christian W. Damus wrote:
>> Hi, Joel,
>>
>> If the SDK documentation doesn't provide examples, then your best bet
>> is to look into the JUnit tests. Search for invocations of the
>> OCLHelper methods in the org.eclipse.ocl.ecore.tests plug-in, for
>> example. They should all be covered, IIRC.
>>
>> HTH,
>>
>> Christian
>>
>>
>> On Wed, 2009-08-05 at 15:46 +0200, Joel Greenyer wrote:
>>> So, the def-expression is no query and createQuery(String expression)
>>> does not work. Instead, I have to use
>>> OCLHelper.defineAttribute(String defExpression), right?
>>> The problem is that I can't find any examples of using the OCL API in
>>> the right way to handle different cases of expressions (queries and
>>> def-expression) that I have in my transformation rules.
>>> Could anyone please provide a snippet how to do that or point me to
>>> some example that demonstrates how to do it?
>>>
>>> Thanks a lot
>>>
>>> Joel
>>>
>>> Joel Greenyer wrote:
>>> > Hi,
>>> > I'm confused whether or how the "def:" expression is supported. My
>>> > intuition is that I e.g. type
>>> > > def: s: String = 'Hello'
>>> > > in the console and that I can use the variable s when evaluating
>>> > subsequent expressions. However, that doesn't seem to work.
>>> > > What am I missing?
>>> > > Joel
>
Re: def expression? [message #480364 is a reply to message #480245] Sun, 16 August 2009 08:26 Go to previous messageGo to next message
Joel Greenyer is currently offline Joel GreenyerFriend
Messages: 170
Registered: July 2009
Senior Member
Hi Ed,
comments below

Ed Willink wrote:
> Hi Joel
>
> I'm not sure about your whole problem but when you mention removing
> variables from environments I get very uncomfortable.

Why is that?

> It is much easier
> to created a nested environment for the nested scope and revert to the
> outer ebvironment when you want to recover context.

I haven't worked with these nested environments yet, but I'll keep it in mind. However, I'd have to create a nested
environment for each variable that I add. Adding and removing variables is easy and works well for me so far.

>
> I know Let and Iterate current use dynamically changing environments,
> but that is likely to change to nested environments in the next MDT-OCL
> release.
>
> Regards
>
> Ed Willink
>
> Joel Greenyer wrote:
>> Hi Christian,
>> thanks for pointing me to the JUnit tests. However, I am still a bit
>> lost. Or, maybe, my problem is bit more tricky than just using
>> def-expressions.
>>
>> What I am doing is the following: I have a graph matcher that matches
>> typed nodes to eObjects. When named nodes are
>> bound in the matching process, I add a variable with the node's name
>> and the bound eObject to the OCL
>> environment/evaluationenvironment. The graph matcher also backtracks
>> at times, and when it does, I remove those variables corresponding to
>> the back-tracked nodes again from the OCL
>> environment/evaluationenvironment.
>>
>> Before nodes can be bound, I check OCL constraints that are attached
>> to them. Those constraints
>> may contain variables that already exist (when the corresponding nodes
>> were bound) or not (when the corresponding nodes are not yet bound).
>> In the latter case, I catch a parseException and try evaluating the
>> expression again when matching the next node and so on, until I can
>> successfully evaluate the expression. I put all successfully evaluated
>> expressions in a map (node where evaluation was
>> successful->expression) and upon backtracking, I put them back into a
>> list of yet-to-be-evaluated expressions.
>>
>> Now I'd like to use expressions that allow me to define reusable
>> values (and also operations in the long term).
>>
>> One general thing that confuses me is that the def-expressions define
>> attributes of some context classifier. In
>> let-expressions, for example, I just define a variable that I can
>> reuse in the in-expression. That is rather what I want. I'd just like
>> to create a variable to reuse.
>>
>> Right now I am thinking of processing the "def: <varname> : <typename>
>> = " part of the def-expression in my own code, let the OCL-helper
>> evaluate the subsequent expression, and define a variable in the same
>> way I do for my nodes.
>> Then again I wonder whether the OCL fragmework could help me do that?
>> Or do you have any better idea to define my variables?
>> Mind, that I also have to "undefine" those variables again when I
>> backtrack past the point of where I successfully evaluated it.
>>
>> Thanks for helping
>>
>> Joel
>>
>>
>>
>>
>> Christian W. Damus wrote:
>>> Hi, Joel,
>>>
>>> If the SDK documentation doesn't provide examples, then your best bet
>>> is to look into the JUnit tests. Search for invocations of the
>>> OCLHelper methods in the org.eclipse.ocl.ecore.tests plug-in, for
>>> example. They should all be covered, IIRC.
>>>
>>> HTH,
>>>
>>> Christian
>>>
>>>
>>> On Wed, 2009-08-05 at 15:46 +0200, Joel Greenyer wrote:
>>>> So, the def-expression is no query and createQuery(String
>>>> expression) does not work. Instead, I have to use
>>>> OCLHelper.defineAttribute(String defExpression), right?
>>>> The problem is that I can't find any examples of using the OCL API
>>>> in the right way to handle different cases of expressions (queries
>>>> and def-expression) that I have in my transformation rules.
>>>> Could anyone please provide a snippet how to do that or point me to
>>>> some example that demonstrates how to do it?
>>>>
>>>> Thanks a lot
>>>>
>>>> Joel
>>>>
>>>> Joel Greenyer wrote:
>>>> > Hi,
>>>> > I'm confused whether or how the "def:" expression is supported. My
>>>> > intuition is that I e.g. type
>>>> > > def: s: String = 'Hello'
>>>> > > in the console and that I can use the variable s when evaluating
>>>> > subsequent expressions. However, that doesn't seem to work.
>>>> > > What am I missing?
>>>> > > Joel
>>
Re: def expression? [message #480375 is a reply to message #480364] Sun, 16 August 2009 12:03 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4186
Registered: July 2009
Senior Member
Hi Joel
>> I'm not sure about your whole problem but when you mention removing
>> variables from environments I get very uncomfortable.
>
> Why is that?

It means that the Environment has a very clear locality. Nested
environments are always valid for the context that initialised them.

Note that OCL 2.0 does not support remove of elements from an Environment.
>
>> It is much easier
>> to created a nested environment for the nested scope and revert to the
>> outer ebvironment when you want to recover context.

You'll find nested environments are easy too, and you cannot forget to
match your adds with removes.
>
> I haven't worked with these nested environments yet, but I'll keep it in
> mind. However, I'd have to create a nested environment for each variable
> that I add. Adding and removing variables is easy and works well for me
> so far.

If it works for you fine. Just beware that if you start to do more
interesting things, it might bite later.

Regards

Ed Willink
Re: def expression? [message #481244 is a reply to message #480375] Thu, 20 August 2009 08:58 Go to previous messageGo to next message
Joel Greenyer is currently offline Joel GreenyerFriend
Messages: 170
Registered: July 2009
Senior Member
Ed,
I've been trying to get familiar with nested environments, You promised that they were easy to use ;), but unfortunately
I can't find code examples--at least not any that point in the direction that I need to go.

In short, my problem is that I match a graph pattern to a model and, during the matching process, I need a scope that
constantly reflects the bound nodes by bound variables, i.e. the scope must contain a bound variable per named node that
is currently bound.

While I backtrack, I need to remove variables from my environment/scope that will possibly be added again. So, you
suggest to do this with nested environments--How do I create a nested environment (I think I understood that...) and how
to I go back to an outer environment when I backtrack?

Thanks for helping!

Joel


Ed Willink wrote:
> Hi Joel
>>> I'm not sure about your whole problem but when you mention removing
>>> variables from environments I get very uncomfortable.
>>
>> Why is that?
>
> It means that the Environment has a very clear locality. Nested
> environments are always valid for the context that initialised them.
>
> Note that OCL 2.0 does not support remove of elements from an Environment.
>>
>>> It is much easier
>>> to created a nested environment for the nested scope and revert to the
>>> outer ebvironment when you want to recover context.
>
> You'll find nested environments are easy too, and you cannot forget to
> match your adds with removes.
>>
>> I haven't worked with these nested environments yet, but I'll keep it
>> in mind. However, I'd have to create a nested environment for each
>> variable that I add. Adding and removing variables is easy and works
>> well for me so far.
>
> If it works for you fine. Just beware that if you start to do more
> interesting things, it might bite later.
>
> Regards
>
> Ed Willink
Re: def expression? [message #481397 is a reply to message #481244] Thu, 20 August 2009 19:12 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4186
Registered: July 2009
Senior Member
Hi Joel

The following snippets all come from org.eclipse.qvt.declarative.parser
or org.eclipse.qvt.declarative.parser.qvtrelation with added C++-style
class names for clarity.

/**
* Overridden to provided a nested scope for nested variables.
*/
@Override
protected OCLExpression<EClassifier> AbstractQVTAnalyzer::letExp(
LetExpCS letExpCS,
Environment<EPackage, EClassifier, EOperation,
EStructuralFeature, EEnumLiteral, EParameter, EObject,
CallOperationAction, SendSignalAction, Constraint, EClass,
EObject> env) {
return super.letExp(letExpCS,
createdNestedEnvironment(letExpCS, env));
}


@Override
protected IQVTrNodeEnvironment
AbstractQVTrAnalyzer::createdNestedEnvironment(CSTNode cstNode,
Environment<EPackage, EClassifier, EOperation,
EStructuralFeature, EEnumLiteral, EParameter, EObject,
CallOperationAction, SendSignalAction, Constraint, EClass,
EObject> env) {
return new
QVTrNestedEnvironment((IQVTrNodeEnvironment)env,
cstNode);
}


public class QVTrNestedEnvironment extends
QVTrEnvironment<IQVTrNodeEnvironment, EModelElement, CSTNode>
{
public QVTrNestedEnvironment(IQVTrNodeEnvironment env, CSTNode cstNode) {
super(env, null, cstNode);
}
}

the construction just propagates down through 7 level of inheritance to
an EcoreEnvironment.

The initial letExp override for AbstractOCLAnalyzer::letExp just ensures
that the let body has a nested environment, which is instantly forgotten
about when proceeding past the let.

Regards

Ed Willink


Joel Greenyer wrote:
> Ed,
> I've been trying to get familiar with nested environments, You promised
> that they were easy to use ;), but unfortunately I can't find code
> examples--at least not any that point in the direction that I need to go.
>
> In short, my problem is that I match a graph pattern to a model and,
> during the matching process, I need a scope that constantly reflects the
> bound nodes by bound variables, i.e. the scope must contain a bound
> variable per named node that is currently bound.
>
> While I backtrack, I need to remove variables from my environment/scope
> that will possibly be added again. So, you suggest to do this with
> nested environments--How do I create a nested environment (I think I
> understood that...) and how to I go back to an outer environment when I
> backtrack?
>
> Thanks for helping!
>
> Joel
>
>
> Ed Willink wrote:
>> Hi Joel
>>>> I'm not sure about your whole problem but when you mention removing
>>>> variables from environments I get very uncomfortable.
>>>
>>> Why is that?
>>
>> It means that the Environment has a very clear locality. Nested
>> environments are always valid for the context that initialised them.
>>
>> Note that OCL 2.0 does not support remove of elements from an
>> Environment.
>>>
>>>> It is much easier
>>>> to created a nested environment for the nested scope and revert to the
>>>> outer ebvironment when you want to recover context.
>>
>> You'll find nested environments are easy too, and you cannot forget to
>> match your adds with removes.
>>>
>>> I haven't worked with these nested environments yet, but I'll keep it
>>> in mind. However, I'd have to create a nested environment for each
>>> variable that I add. Adding and removing variables is easy and works
>>> well for me so far.
>>
>> If it works for you fine. Just beware that if you start to do more
>> interesting things, it might bite later.
>>
>> Regards
>>
>> Ed Willink
Re: def expression? [message #481476 is a reply to message #481397] Fri, 21 August 2009 08:07 Go to previous messageGo to next message
Joel Greenyer is currently offline Joel GreenyerFriend
Messages: 170
Registered: July 2009
Senior Member
Hi Ed,
I'm afraid that that doesn't help me yet...

Again: I want to be able to evaluate constraints in an environment/evaluationEnvironment where I can specifically define
the available variables and their bindings.


What I extract from the code snippets is that you create a nested environment by using the appropriate constructor of
the ECoreEnvironment that takes the parent environment as parameter--okay.

My question is, however:
1. How do I make sure that this nested environment is used when I call
ocl.evaluate(context, expression)
the next time.

2. And, how can I control to again evaluate an expression with an outer environment?

3. And, probably I have to create nested evaluationEnvironments also. How do I deal with those?


Is it maybe easier to just dispose the old OCL and create new one and initialize it with the variables+bindings every
time I evaluate a constraint?--That doesn't seem to be the way to use OCL though...


Thanks for helping

Joel



Ed Willink wrote:
> Hi Joel
>
> The following snippets all come from org.eclipse.qvt.declarative.parser
> or org.eclipse.qvt.declarative.parser.qvtrelation with added C++-style
> class names for clarity.
>
> /**
> * Overridden to provided a nested scope for nested variables.
> */
> @Override
> protected OCLExpression<EClassifier> AbstractQVTAnalyzer::letExp(
> LetExpCS letExpCS,
> Environment<EPackage, EClassifier, EOperation,
> EStructuralFeature, EEnumLiteral, EParameter, EObject,
> CallOperationAction, SendSignalAction, Constraint, EClass,
> EObject> env) {
> return super.letExp(letExpCS,
> createdNestedEnvironment(letExpCS, env));
> }
>
>
> @Override
> protected IQVTrNodeEnvironment
> AbstractQVTrAnalyzer::createdNestedEnvironment(CSTNode cstNode,
> Environment<EPackage, EClassifier, EOperation,
> EStructuralFeature, EEnumLiteral, EParameter, EObject,
> CallOperationAction, SendSignalAction, Constraint, EClass,
> EObject> env) {
> return new
> QVTrNestedEnvironment((IQVTrNodeEnvironment)env,
> cstNode);
> }
>
>
> public class QVTrNestedEnvironment extends
> QVTrEnvironment<IQVTrNodeEnvironment, EModelElement, CSTNode>
> {
> public QVTrNestedEnvironment(IQVTrNodeEnvironment env, CSTNode
> cstNode) {
> super(env, null, cstNode);
> }
> }
>
> the construction just propagates down through 7 level of inheritance to
> an EcoreEnvironment.
>
> The initial letExp override for AbstractOCLAnalyzer::letExp just ensures
> that the let body has a nested environment, which is instantly forgotten
> about when proceeding past the let.
>
> Regards
>
> Ed Willink
>
>
> Joel Greenyer wrote:
>> Ed,
>> I've been trying to get familiar with nested environments, You
>> promised that they were easy to use ;), but unfortunately I can't find
>> code examples--at least not any that point in the direction that I
>> need to go.
>>
>> In short, my problem is that I match a graph pattern to a model and,
>> during the matching process, I need a scope that constantly reflects
>> the bound nodes by bound variables, i.e. the scope must contain a
>> bound variable per named node that is currently bound.
>>
>> While I backtrack, I need to remove variables from my
>> environment/scope that will possibly be added again. So, you suggest
>> to do this with nested environments--How do I create a nested
>> environment (I think I understood that...) and how to I go back to an
>> outer environment when I backtrack?
>>
>> Thanks for helping!
>>
>> Joel
>>
>>
>> Ed Willink wrote:
>>> Hi Joel
>>>>> I'm not sure about your whole problem but when you mention removing
>>>>> variables from environments I get very uncomfortable.
>>>>
>>>> Why is that?
>>>
>>> It means that the Environment has a very clear locality. Nested
>>> environments are always valid for the context that initialised them.
>>>
>>> Note that OCL 2.0 does not support remove of elements from an
>>> Environment.
>>>>
>>>>> It is much easier
>>>>> to created a nested environment for the nested scope and revert to the
>>>>> outer ebvironment when you want to recover context.
>>>
>>> You'll find nested environments are easy too, and you cannot forget
>>> to match your adds with removes.
>>>>
>>>> I haven't worked with these nested environments yet, but I'll keep
>>>> it in mind. However, I'd have to create a nested environment for
>>>> each variable that I add. Adding and removing variables is easy and
>>>> works well for me so far.
>>>
>>> If it works for you fine. Just beware that if you start to do more
>>> interesting things, it might bite later.
>>>
>>> Regards
>>>
>>> Ed Willink
Re: def expression? [message #481485 is a reply to message #481476] Fri, 21 August 2009 08:28 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4186
Registered: July 2009
Senior Member
Hi Joel

Nested environments are appropriate for nested parsing and possibly
evaluation of a complex expression. My recommendations were for parsing.

It seems that you have some bigger application that provides context
across OCL evaluations.

You have described a push-model whereby the application continually
pushes its context to OCL.

You might find it worthwhile to create a derived EcoreEnvironment
that reimplements at least lookupLocal so that you can reuse the
environment and just pull your application resolutions when you want them.

Regards

Ed Willink

Joel Greenyer wrote:
> Hi Ed,
> I'm afraid that that doesn't help me yet...
>
> Again: I want to be able to evaluate constraints in an
> environment/evaluationEnvironment where I can specifically define the
> available variables and their bindings.
>
>
> What I extract from the code snippets is that you create a nested
> environment by using the appropriate constructor of the ECoreEnvironment
> that takes the parent environment as parameter--okay.
>
> My question is, however:
> 1. How do I make sure that this nested environment is used when I call
> ocl.evaluate(context, expression)
> the next time.
>
> 2. And, how can I control to again evaluate an expression with an outer
> environment?
>
> 3. And, probably I have to create nested evaluationEnvironments also.
> How do I deal with those?
>
>
> Is it maybe easier to just dispose the old OCL and create new one and
> initialize it with the variables+bindings every time I evaluate a
> constraint?--That doesn't seem to be the way to use OCL though...
>
>
> Thanks for helping
>
> Joel
>
>
>
> Ed Willink wrote:
>> Hi Joel
>>
>> The following snippets all come from
>> org.eclipse.qvt.declarative.parser or
>> org.eclipse.qvt.declarative.parser.qvtrelation with added C++-style
>> class names for clarity.
>>
>> /**
>> * Overridden to provided a nested scope for nested variables.
>> */
>> @Override
>> protected OCLExpression<EClassifier> AbstractQVTAnalyzer::letExp(
>> LetExpCS letExpCS,
>> Environment<EPackage, EClassifier, EOperation,
>> EStructuralFeature, EEnumLiteral, EParameter, EObject,
>> CallOperationAction, SendSignalAction, Constraint, EClass,
>> EObject> env) {
>> return super.letExp(letExpCS,
>> createdNestedEnvironment(letExpCS, env));
>> }
>>
>> @Override
>> protected IQVTrNodeEnvironment
>> AbstractQVTrAnalyzer::createdNestedEnvironment(CSTNode cstNode,
>> Environment<EPackage, EClassifier, EOperation,
>> EStructuralFeature, EEnumLiteral, EParameter, EObject,
>> CallOperationAction, SendSignalAction, Constraint, EClass,
>> EObject> env) {
>> return new
>> QVTrNestedEnvironment((IQVTrNodeEnvironment)env,
>> cstNode);
>> }
>>
>>
>> public class QVTrNestedEnvironment extends
>> QVTrEnvironment<IQVTrNodeEnvironment, EModelElement, CSTNode>
>> {
>> public QVTrNestedEnvironment(IQVTrNodeEnvironment env, CSTNode
>> cstNode) {
>> super(env, null, cstNode);
>> } }
>>
>> the construction just propagates down through 7 level of inheritance
>> to an EcoreEnvironment.
>>
>> The initial letExp override for AbstractOCLAnalyzer::letExp just
>> ensures that the let body has a nested environment, which is instantly
>> forgotten about when proceeding past the let.
>>
>> Regards
>>
>> Ed Willink
>>
>>
>> Joel Greenyer wrote:
>>> Ed,
>>> I've been trying to get familiar with nested environments, You
>>> promised that they were easy to use ;), but unfortunately I can't
>>> find code examples--at least not any that point in the direction that
>>> I need to go.
>>>
>>> In short, my problem is that I match a graph pattern to a model and,
>>> during the matching process, I need a scope that constantly reflects
>>> the bound nodes by bound variables, i.e. the scope must contain a
>>> bound variable per named node that is currently bound.
>>>
>>> While I backtrack, I need to remove variables from my
>>> environment/scope that will possibly be added again. So, you suggest
>>> to do this with nested environments--How do I create a nested
>>> environment (I think I understood that...) and how to I go back to an
>>> outer environment when I backtrack?
>>>
>>> Thanks for helping!
>>>
>>> Joel
>>>
>>>
>>> Ed Willink wrote:
>>>> Hi Joel
>>>>>> I'm not sure about your whole problem but when you mention
>>>>>> removing variables from environments I get very uncomfortable.
>>>>>
>>>>> Why is that?
>>>>
>>>> It means that the Environment has a very clear locality. Nested
>>>> environments are always valid for the context that initialised them.
>>>>
>>>> Note that OCL 2.0 does not support remove of elements from an
>>>> Environment.
>>>>>
>>>>>> It is much easier
>>>>>> to created a nested environment for the nested scope and revert to
>>>>>> the
>>>>>> outer ebvironment when you want to recover context.
>>>>
>>>> You'll find nested environments are easy too, and you cannot forget
>>>> to match your adds with removes.
>>>>>
>>>>> I haven't worked with these nested environments yet, but I'll keep
>>>>> it in mind. However, I'd have to create a nested environment for
>>>>> each variable that I add. Adding and removing variables is easy and
>>>>> works well for me so far.
>>>>
>>>> If it works for you fine. Just beware that if you start to do more
>>>> interesting things, it might bite later.
>>>>
>>>> Regards
>>>>
>>>> Ed Willink
Re: def expression? [message #481499 is a reply to message #481485] Fri, 21 August 2009 10:01 Go to previous message
Joel Greenyer is currently offline Joel GreenyerFriend
Messages: 170
Registered: July 2009
Senior Member
I'll have a look at that,

thanks

Joel

Ed Willink wrote:
> Hi Joel
>
> Nested environments are appropriate for nested parsing and possibly
> evaluation of a complex expression. My recommendations were for parsing.
>
> It seems that you have some bigger application that provides context
> across OCL evaluations.
>
> You have described a push-model whereby the application continually
> pushes its context to OCL.
>
> You might find it worthwhile to create a derived EcoreEnvironment
> that reimplements at least lookupLocal so that you can reuse the
> environment and just pull your application resolutions when you want them.
>
> Regards
>
> Ed Willink
Previous Topic:Problem with Link Constraint (OCL)
Next Topic:changing context of existing query
Goto Forum:
  


Current Time: Thu Dec 18 22:27:05 GMT 2014

Powered by FUDForum. Page generated in 0.14579 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software