Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » how to declare index variables in EOL
how to declare index variables in EOL [message #1849258] Mon, 10 January 2022 13:50 Go to next message
fang yan is currently offline fang yanFriend
Messages: 27
Registered: October 2020
Junior Member
Hi,

I am trying to define a variable within while loop as text_1, text_2, text_3, using index i in text_i.
But I didn't figure out how to build this index variable.
I tried to define an operation as follows.
But it seems not working

var i=1;
var variable_name: String;
variable_name= i.declareVar();
var variable_name: String;

operation Integer declareVar(): String{
var str: String;
str= "text_" + self ;
return str;
}


Any suggestion, please?
Many thanks.
Fang
Re: how to declare index variables in EOL [message #1849259 is a reply to message #1849258] Mon, 10 January 2022 13:53 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2165
Registered: July 2009
Location: York, UK
Senior Member

Hi Fang,

I'm not sure I understand the issue you are describing. Could you please elaborate a bit more?

Best,
Dimitris
Re: how to declare index variables in EOL [message #1849260 is a reply to message #1849259] Mon, 10 January 2022 14:08 Go to previous messageGo to next message
fang yan is currently offline fang yanFriend
Messages: 27
Registered: October 2020
Junior Member
Hi Deimitris,

My intention is to declare a variable each time the while loop runs.
For example that the size is 3 (size_source=3), then the While runs 3 times, and each time, I am hoping to declare a variable source_j, thus after 3 runs, I will have 3 variables of source_0, source_1, and source_2.
The simplified code is as follows.
I know the codes are not correct, but I don't know the right way to declare.

var size_source=inference.source.size();
var j=0;

while(size_source>0)
{
var source_j: String;
source_j= inference.source.at(j).name.content;
j=j+1;
size_source= size_source-1;
}


Hope this explains better.
Thanks
Fang
Re: how to declare index variables in EOL [message #1849261 is a reply to message #1849260] Mon, 10 January 2022 14:20 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 2165
Registered: July 2009
Location: York, UK
Senior Member

Hi Fang,

You could do this using the code below but it's an ugly hack that I'd try to avoid if at all possible.

var frame = System.context.frameStack.topFrame;

for (i in 1.to(3)) {
  frame.put((
    new Native("org.eclipse.epsilon.eol.execute.context.Variable")).
      createReadOnlyVariable("var_" + i, i));
}

var_1.println();
var_2.println();
var_3.println();


Best,
Dimitris

[Updated on: Mon, 10 January 2022 14:22]

Report message to a moderator

Re: how to declare index variables in EOL [message #1849282 is a reply to message #1849261] Tue, 11 January 2022 09:05 Go to previous message
fang yan is currently offline fang yanFriend
Messages: 27
Registered: October 2020
Junior Member
Hi Dimitris,

Thanks for the solution. You are right, this is not good option to use index variable.
I decide not to use it.

Fang
Previous Topic:Java Lifting with EMC-JDT
Next Topic:Unexpected modification of the input model
Goto Forum:
  


Current Time: Sat Apr 27 13:09:03 GMT 2024

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

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

Back to the top