Skip to main content



      Home
Home » Eclipse Projects » Sirius » creating services with lambda arguments
creating services with lambda arguments [message #1861318] Thu, 05 October 2023 07:19 Go to next message
Eclipse UserFriend
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 09:24 Go to previous messageGo to next message
Eclipse UserFriend
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.

[Updated on: Thu, 12 October 2023 09:33] by Moderator

Re: creating services with lambda arguments [message #1861443 is a reply to message #1861440] Thu, 12 October 2023 09:52 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: creating services with lambda arguments [message #1861557 is a reply to message #1861443] Wed, 18 October 2023 10:51 Go to previous message
Eclipse UserFriend
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: Sun Jul 13 21:08:09 EDT 2025

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

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

Back to the top