Kary
click on it...


Arrays in Arendelle

You may know my language Arendelle, This month we officially released the first version of it for Android, currently we’re developing the language for the rest of the platforms.

There are things we’re adding to the language and one of them is “Arrays”, Array actually give the user many super powers and it’s a very necessary part of our language. However what you don’t know is it’s already coming with the language in our Android app.

Actually, I made Arendelle Language in the first place but everything about array other than its size command were Micha’s ideas. Soon there will be some chapters in Arendelle Book explaining array and some exercises about it but for now, let’s just have a quick look at it.

If you’re an Arendelle developer you may have used it without even knowing it! Because like MATLAB and Octave every single space you create is an Array! Yes! Every single space you make is an array, So when you’re doing @space you’re actually reading the very first index of that space. So now you may ask then how you add more things to it? Simple! When you do this:

( space , 4 )

Arendelle makes a space as [ 4 ] so now if you fill the next index with this code:

( space[ 1 ] , 12 )

You will have @space = [4, 12]. Something very cool about Micha’s implementation is if you do:

( space[ 5 ] , 2 )

When it comes to other languages arrays are horrible, For example, you have to create them with a limited size like when you do this in c:

int array[4] = {1, 234, 232, 34};

Which is not that cool. In some other languages like Swift, C# and so there are mutable arrays with unlimited size which you can append them whenever you want like this way in Swift:

var array = [1, 234, 232]
array.append(34)

In Arendelle spaces are mutable and you can add to them whenever you want, However, the very cool feature of these arrays is you can do this:

( space , 24 )
( space[ 4 ] , 256 )

So the cool part is when you init the @space with 24 it will be [24] as soon as you do (space[ 4 ], 256) you’re telling Arendelle to fill the fifth index, but as you know there is no second, third and fourth index and it’s no problem because Arendelle automatically fills these indexes with zero for you, So the result of the code will be [24, 0, 0, 0, 256]

One thing that remains is how you get the size of an array? It will be done using our ‘?’ operator. When you append the name of a space with ? you’re asking it’s size, So for example if you do:

( space [ 9 ] , 5 )
'Size of @space is | @space? |'

You will get the title:

Size of @space is 10

So there are many possible uses of the array and its tools. For a simple example let’s make a list of 10 random number less than 11:

( space , 0 ) ( array , 0 )
[ 20 ,
   ( array[ @space ] , floor( #rnd * 11 ) )
   ( space , +1 )
]

You can do it in a very more small system with only one space like this:

( array , 0 ) [ 20, ( array [ @array? - 1 ] , floor( #rnd * 1 ) ) ] 

So as you see it’s very simple in Arendelle, Also stored spaces and functions are working with this system. You can do:

( $space , 0 ) ( $space[ 9 ] , 1024 )
'Index 0 is: | $space |, Index 9 is: | $space[ 9 ] |, Size is: | $space? |'

And as you know Arendelle uses @return in functions for storing the return value so you can return multi values grouped in @return like:

!func()[ 0 ] // value 1
!func()[ 1 ] // value 2




NOTE: To copy a space to another space Fully as an array you can simply do:

( space2 , @space )

Arendelle won’t do:

( space2[0] , @space[0] )

It will copy the whole @space to @space2




So that’s it for now, There will be some more features added but before we officially launch it, You can have some fun with it!

Top of Stack!