Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [XPAND2] Learning basic(need helps on a simple question)
[XPAND2] Learning basic [message #1703397] Fri, 31 July 2015 09:41 Go to next message
Valentin Edai is currently offline Valentin EdaiFriend
Messages: 1
Registered: July 2015
Junior Member

I'm learning XPAND2 and I'm trying to do something...
I have a list of elements :

- string name
- double age
- string adress.

In a FOREACH loop, I would like to do something once, just ONCE even if I found the same type after, when the type is a string, once when it's a double. How should I do?

Now, I have something like this but I can't do nothing with it...
 «FOREACH str.member AS mbr-»
            «LET mbr.type.toString() AS type-»
            «LET "true" AS value_str-»                        <==== How can I use this variable? comparing and change value...
                              «IF type == "string"-»
                                     DO SOMETHING()
                                «IF type == "double"-»
                                     DO SOMETHING2()

I'm not sure that my problem is comprehensible but wel...

Re: [XPAND2] Learning basic [message #1703570 is a reply to message #1703397] Mon, 03 August 2015 08:38 Go to previous message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

You can create a Set and add the already processed types into it:
«LET {}.toSet() AS types»
   «IF !types.contains(type)»
     «types.add(type) -> ""»
            		DO ONCE

The expression ->"" will suppress the output of the add operation result into the text.

Note that LET defines a final variable, you can't change the value. It is supposed to be used to evaluate (complex) statements once and cache the result within a block where the result is used multiple times (e.g. collect all fields that meet a certain criteria).

Need professional support for Xtext, EMF, Eclipse IDE?
Go to:
Twitter : @kthoms
Blog :
Previous Topic: [Acceleo] Undefined "Let" expression
Next Topic:how to delete a file using a template
Goto Forum:

Current Time: Wed Nov 29 00:28:03 GMT 2023

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

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

Back to the top