Diddy Arrays.CreateArray?

Monkey Forums/Monkey Programming/Diddy Arrays.CreateArray?

Amon(Posted 2013) [#1]
How do I access Diddys Arrays? I prefer Diddy's method than my own hack version but I get 'Arrays not found'.

I'm just trying to access the 2D arrays feature for setting up a 2D array.


therevills(Posted 2013) [#2]
Hmmm... try this:

Strict

Import diddy

Function Main:Int()
	' create the array
	Local arr:Int[][] = Arrays<Int>.CreateArray(128,64)
	
	' populate the array
	For Local x:Int = 0 Until 128
		For Local y:Int = 0 Until 64
			arr[x][y] = x + y
		Next
	Next
	
	' print out the array
	For Local x:Int = 0 Until 128
		For Local y:Int = 0 Until 64
			Print arr[x][y]
		Next
	Next
	Return 0
End



Amon(Posted 2013) [#3]
Thanks! Works Fine! :)


Jesse(Posted 2013) [#4]
Don't you have something like that in your code libray you posted a few days ago? It works exactly in the same way.


Amon(Posted 2013) [#5]
Don't you have something like that in your code libray you posted a few days ago?


I do but it's not the same. The code is muddyshoes' code. This method is built in to Diddy with all the nice features!

In a sense it doesn't work exactly the same! Diddy's is better.

Plus I only use the code library I have when quickly prototyping. I use Diddy for the main projects.


Jesse(Posted 2013) [#6]
if you look at the source code you will find out that it is the same with some extra method for extra functionality.

but what ever puts you in your comfort zone. :)


Nobuyuki(Posted 2013) [#7]
Honk honk! Resurrecting a dead thread

I'm attempting to port TimSort<T> to Monkey. Since Monkey doesn't appear to have built in Array copy methods, I'm planning on using diddy.arrays to do this. Would it be useful to have an Arrays<T>.Sort method built directly into diddy.arrays? The class would probably also require importing a Comparator<T> Interface (and due to the lack of wildcards, this might be a bit limited)...

Edit: trans: "Interfaces can't be generic." hnnnnng.


Samah(Posted 2013) [#8]
Hmm I could probably do this. The current Comparator stuff in the collections module doesn't use generics (obviously) so you need to cast it yourself. Limitation of the language, unfortunately. I'll see if I can clean it up a bit.


Nobuyuki(Posted 2013) [#9]
Samah: I'd encourage you to check this out if you haven't already. I attempted to port the aforementioned sort (which is now Java's new default sort, because in theory it should be fast) to Monkey over the past couple days, but ran into some strange stuff that I figured you or revills might be particularly interested in, if not for the bug itself, then for the class (if someone can get the damn thing to compile!)

http://www.monkeycoder.co.nz/Community/posts.php?topic=4931

I didn't realize that diddy already had a comparator class and comparable interface. Not having generic interfaces may be a limitation, but it doesn't seem like a huge/crippling one, or one that can't be worked around. I should probably check out the code that's been done to that framework since I last took a look at it!