Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » EGL Development Tools » Dynamic arrays?(Does such a creature exist?)
Dynamic arrays? [message #902047] Wed, 15 August 2012 15:42 Go to next message
Dan Darnell is currently offline Dan DarnellFriend
Messages: 145
Registered: November 2011
Location: Arkansas
Senior Member
Can I dynamically size or resize an array? In my case the array is multi-dimensional...

myarray boolean[][];

...and I want to set the array size based on a variable.

Is there a way to use resize() to dynamically set the array size? Or perhaps populate the array using appendElement() inside a loop?

I've tried several things but can't seem to figure out a) whether this is possible and b) how to make it work with a multi-dimensional array.

Thoughts?

--Dan
Re: Dynamic arrays? [message #902076 is a reply to message #902047] Wed, 15 August 2012 18:16 Go to previous messageGo to next message
Brian Svihovec is currently offline Brian SvihovecFriend
Messages: 55
Registered: July 2009
Member
Dan,

It sounds like what you are asking for should be supported. Can you post a small snippet of code with your best guess at how this should be implemented? We can iterate on the EGL or the generated output from there. Also, what target language are you using for this snippet?

-Brian
Re: Dynamic arrays? [message #902267 is a reply to message #902076] Thu, 16 August 2012 16:26 Go to previous messageGo to next message
Dan Darnell is currently offline Dan DarnellFriend
Messages: 145
Registered: November 2011
Location: Arkansas
Senior Member
Hi Brian,

I'm targeting JavaScript.

The syntax that I would like to use would be simply:

foo int = 20;
bar int = 25;

myArray1 boolean[] = new boolean[foo];
myArray2 boolean[][] = new boolean[foo][bar];


If I'm not mistaken, this syntax is directly supported in Java. In generated JavaScript it might require setting up a looping structure to initialize the array.

With EGL as it exists today I tried several variations using resize() but without really understanding what resize() is intended to do. I also tried setting up my own loops and using appendElement() to dynamically expand and initialize the array dimensions.

This works:

b boolean[];
for(i int from 1 to 10)
  b.appendElement(false);
end
for(i int from 1 to 10)
  SysLib.writeStdout(b[i]);
end


But I never found a solution with appendElement() for a multi-dimensional array.

--Dan
Re: Dynamic arrays? [message #902469 is a reply to message #902267] Fri, 17 August 2012 18:31 Go to previous messageGo to next message
Brian Svihovec is currently offline Brian SvihovecFriend
Messages: 55
Registered: July 2009
Member
Dan,

I believe the following code should do what you want:

foo int = 20;
bar int = 25;

myArray2 boolean[][] = new boolean[0][0];

myArray2.resize(foo); 
for(i int from 1 to myArray2.getSize())
	myArray2[i].resize(bar);
end


While this appears to run in Java for EDT, it does not appear to run in JavaScript. I have opened the following bug for this issue - https://bugs.eclipse.org/bugs/show_bug.cgi?id=387502

The following is an alternative solution that does appear to work in JavaScript:

foo int = 20;
bar int = 25;

myArray2 boolean[][] = new boolean[0][0];

for(i int from 1 to foo)
	innerArray boolean[] = new boolean[0];
	for(j int from 1 to bar)
		innerArray.appendElement(false);
	end
	myArray2.appendElement(innerArray);
end


-Brian
Re: Dynamic arrays? [message #902509 is a reply to message #902469] Sat, 18 August 2012 02:36 Go to previous message
Dan Darnell is currently offline Dan DarnellFriend
Messages: 145
Registered: November 2011
Location: Arkansas
Senior Member

Much appreciated! I figured there must be a way to do it using appendElement but I just couldn't figure out the secret sauce.

Any chance of the simple syntax that Java supports being implemented in EGL?

--Dan
Previous Topic:IDE closes when accessing help
Next Topic:Contributing to the EDT project
Goto Forum:
  


Current Time: Wed Apr 24 15:31:44 GMT 2024

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

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

Back to the top