Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » creating services with lambda arguments
creating services with lambda arguments [message #1861318] Thu, 05 October 2023 11:19 Go to next message
Tom Westbury is currently offline Tom WestburyFriend
Messages: 11
Registered: December 2022
Junior Member
Hi, I am writing a few helper services for use in my sirius VSM and I was wondering if it is possible to write services that take lambdas as arguments so as to create a toolbox of useful generic services.

Some of the base AQL services in org.eclipse.acceleo.query.services use the type LambdaValue from org.eclipse.acceleo.query.runtime.impl but I am unable to find the source for this to understand how the class works.

Any help with working this one out would be greatly appreciated,

Many thanks,

Tom
Re: creating services with lambda arguments [message #1861440 is a reply to message #1861318] Thu, 12 October 2023 13:24 Go to previous messageGo to next message
Pierre-Charles David is currently offline Pierre-Charles DavidFriend
Messages: 705
Registered: July 2009
Senior Member
The sources of LambdaValue is visible here: https://github.com/eclipse-acceleo/acceleo/blob/master/query/plugins/org.eclipse.acceleo.query/src/org/eclipse/acceleo/query/runtime/impl/LambdaValue.java
Though I'm not sure it helps.

It's the runtime type of "code blocks" in AQL expression, as in:

Sequence{'a', 'b', 'c'}->collect(str | str.toUpper())

"Sequence{'a', 'b', 'c'}" evaluates to a Java List, and "str | str.toUpper()" into a LambdaValue, so AQL invokes the "collect(List<?> sequence, LambdaValue lambda)" Java service method defined here: https://github.com/eclipse-acceleo/acceleo/blob/master/query/plugins/org.eclipse.acceleo.query/src/org/eclipse/acceleo/query/services/CollectionServices.java#L596 with the list value as "sequence" and a LambdaValue representing the code block "str | str.toUpper()" as "lambda".

I've never tried it myself, but it should be possible to use the same patterns in your own Java services.
AFAIK, the ones AQL defines in its standard library like in CollectionServices have no special treatment/super-power; it's just that they are available by default.

EDITED: Actually it looks like the AQL parser will only accept this kind of code blocks (and produce LambaValue for them) for a fixed set of services (collect being one of them): https://github.com/eclipse-acceleo/acceleo/blob/079024efac839526674ae37876437037fe5b1f9c/query/plugins/org.eclipse.acceleo.query/src/org/eclipse/acceleo/query/parser/Query.g4#L71. So it seems that it is not possible to use this pattern for your own services.


Pierre-Charles David - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius

[Updated on: Thu, 12 October 2023 13:33]

Report message to a moderator

Re: creating services with lambda arguments [message #1861443 is a reply to message #1861440] Thu, 12 October 2023 13:52 Go to previous messageGo to next message
Pierre-Charles David is currently offline Pierre-Charles DavidFriend
Messages: 705
Registered: July 2009
Senior Member
The Acceleo team has opened https://github.com/eclipse-acceleo/acceleo/issues/117 to see if it would be possible to allow this kind of services.


Pierre-Charles David - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: creating services with lambda arguments [message #1861557 is a reply to message #1861443] Wed, 18 October 2023 14:51 Go to previous message
Tom Westbury is currently offline Tom WestburyFriend
Messages: 11
Registered: December 2022
Junior Member
That's understandable

Thank you very much for your reply
Previous Topic:Adding a node does not work
Next Topic:Domain/Element-based edge issue
Goto Forum:
  


Current Time: Wed Oct 09 18:59:39 GMT 2024

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

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

Back to the top