Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Examples of def: taking OclLambda parameter?(Are there examples of OCL def: that take an OclLambda as a parameter?)
Examples of def: taking OclLambda parameter? [message #1861282] Tue, 03 October 2023 21:55 Go to next message
Steve Hickman is currently offline Steve HickmanFriend
Messages: 56
Registered: August 2017
Member
Many of the OclStdLib methods take lambda's as a parameter. I'm assuming that there is a define a def: to take a lambda as a parameter - and to call that lambda in the def.

But I haven't yet found an example of that. Can you point me to an example? I have many cases where I'd like to do that - typically where I have derived types that have attributes not in a base class so I need to cast to the appropriate type before I can access the attribute. I find myself repeating the casting code over and over. I would instead like to define lambdas that can be passed to a common method that determines the type and then applies the appropriate lambda.

Re: Examples of def: taking OclLambda parameter? [message #1861291 is a reply to message #1861282] Wed, 04 October 2023 08:40 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7665
Registered: July 2009
Senior Member
The OCLstdlib methods that take a lambda parameter are all iterations. However the intention is that a LambdaType is just another type. There has certainly been a corresponding LambdaLiteral in the grammar since 2014.

A search of master reveals no examples, which puzzles me because I know I started by testing the simple case of splitting an iteration call into a lambda-literal definition of the body passed via a variable to the iteration call. Bug 575157 shows me refining some non-null subtleties for the symbolic evaluation.

But with no examples in tests, I fear that this is another area where code development is still in a branch awaiting a merge to master.

Have you considered inheriting an interface so that the same method can be invoked on all your derived types with distinct results?
Re: Examples of def: taking OclLambda parameter? [message #1861304 is a reply to message #1861291] Wed, 04 October 2023 17:51 Go to previous messageGo to next message
Steve Hickman is currently offline Steve HickmanFriend
Messages: 56
Registered: August 2017
Member
I like the idea but I'll admit I hadn't thought to try it.

The classes in question are generated by an XText grammar. More precisely, they are generated by a stack of XText grammars where I override some rules. The metamodel behind the base XText grammar is defined by a standard so I can't change that. I don't control how the classes get generated - so I hadn't thought about that approach. I'll have to noodle to see if there is a way to do as you suggest. I'll also check the XText forum.
Re: Examples of def: taking OclLambda parameter? [message #1861324 is a reply to message #1861304] Thu, 05 October 2023 12:46 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7665
Registered: July 2009
Senior Member
I find the initially convenient autogeneration of a model by Xtext restricting, so I always maintain the *.ecore as a primary source which allows me to tweak it. Just possibly Xtext autogeneration might respect an additional manual @extends annotation. Just possibly you can do something in Xtext that will have the effect of an interface.

However if you're stuck with a standard, you're stuck, unless you add an additional manual @extends annotation. Or you run a bespoke M2M on the *.ecore.

(Or if my suggested enhancement to Complete OCL to allow additional inheritance as well as additional features, you could add in Complete OCL.)
Re: Examples of def: taking OclLambda parameter? [message #1862185 is a reply to message #1861324] Thu, 16 November 2023 15:44 Go to previous message
Steve Hickman is currently offline Steve HickmanFriend
Messages: 56
Registered: August 2017
Member
If the capability is already available, is it possibly to just paste in an example `def` signature that takes a Lambda as a parameter? And how it gets called?
Previous Topic:Current Maven/ Gradle Repository for OCL
Next Topic:OCL syntax on association ends
Goto Forum:
  


Current Time: Sun Jul 21 11:38:49 GMT 2024

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

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

Back to the top