# Spaces

Spaces are somehow the most important part of programming. In some languages like Assembly you will understand this however their actual name outside Arendelle is not spaces, but “Variables”. As I hate that name we have this much more pretty name “Space”.

# Why we call them space? What are they anyway?

Think of when someone asks: What is the 2 + 3?

While the answer is obvious, the path you take to get into that answer has some points to think about how this thing actually happens in your mind?

In your mind, you create a memory box called “the first number” and then another box with the name “the second number”. Now you put 2 in your first box and then 3 in your second box of memory.

Now your mind creates a new memory box called “Result” and then it reads the 2 and 3 from those boxes, calculates the sum of them and then it creates the 5 and stores the 5 into the result box.

This is the way that our minds memory works. And as the computer systems are based on our minds they have memory too! We can store data and well this is the definition of a computer: A device that does an operation based on instructions by the user on some data in this section we will learn how to work with datas.

# Computer memories

A space is a memory space in your computer’s temporary data storage called a RAM, Just like the way our mind has two separated memories our computers got them two, This two memory systems are “Temporary Memory” and “Long-time Memory”. What are those? Well, the temporary memory is a small memory which is fast so when your system is thinking it uses that memory. This memory erases each time you shutdown your system. There is also another memory which stores your large amount of data as long as you want and those data stays there till you manually delete them. This memory is much slower than RAM but it can keep large data and those data remains there while your system is turned down. There are many different kinds of this memories but Hard Disk Drives and SSD (flash drives) are the most well-known.

Till today you have used the long time memory for storing your files, applications, anything. But from now on you will learn how to use RAM to create your blueprints.

# Data

You have learned how to use sources in your blueprints. They are prepended with a hash ( `#` ) that represents data. Now spaces are like sources but they start with an `@` instead of `#` so a space name may looks like:

@space @spaceName @spaceNumber12

The difference between space and source is a source is a data that your system gives you but space is a data that you enter its value, Now you should ask how can I create a space and then how can I add some data to it. Well, in Arendelle we have this rule:

`​( spaceName , value ) `

Now you may say what? Look at this examples:

`​( age , 19 ) ( year , 2014 ) ( size , 42 ) `

Now as you see we have created a space with the name of @age and the value of 19 so `@age = 19` and then we have `@year = 2014` and then `@size = 42`.

A good question is : “Why should I name a number and write something like `[ @size , pr ]` when I can write [ 19 , pr ]` well yes but now imagine this code:

`​[ 5 ,​    [ 5 , pr ]     [ 5 , pd ]     [ 5 , pl ]     [ 5 , pu ]    ] `

Now imagine you want to change the 5 to 10 you have to replace all the 5s, but you can write a code like this:

`​( number , 10 ) [ @number ,​    [ @number , pr ]     [ @number , pd ]     [ @number , pl ]     [ @number , pu ]    ] `

So now you want to change 10 to 1000 just all you need is to change the 10 in the `( number , 10 )`.

# Is that what sources are all about?

No! The whole point of spaces is this fact that you can edit the information inside them, Look at this code:

`​( space , 12 ) `

As you see we have defined a space with the value of 12. If we write one more line like this :

`​( space , 12 ) ( space , 24 ) `

When Arendelle sees your code it first creates a space with the value of 12, Now in line 2, The we have created the space for second time! Is it possible? Hell yes! It’s not about creating the space for the second time! Once `@space` is defined the code: `( space , 24)` just changes the value of `@space`.

You can even write mathematical expressions in the value side, Look at this:

`​( halfOfScreen , #width / 2 ) `

You can use a spaces in expressions of course:

`​( spaceNo1 , 12 ) ( spaceNo2 , @spaceNo1 + 3 ) `

Now imagine you have created a space with value of 12 like this:

`​( space , 12 ) `

Now imagine you want to add 5 units to @space, you can change the current value using:

`​( space , 12 ) ( space , @space + 5 ) `

So when Arendelle evaluates the code, It creates @space with the value of 12 and then when it’s going to run `( space , @space + 5 )` It first reads the `@space + 5` and as the `@space` is signed with `12` it changes the expression to `12 + 5`, After it evaluates the code it gives `17` back from the math engine and then changes the `@space` value to `17`.

Now sometimes you want to add some numbers to your space like when you’re counting and you want to add one unit to the code, So you have to write :

`​( space , @space + 1 ) `

There are some shortcuts for this operations but Arendelle only comes with the five basic arithmetic operations :

`+     -     /     *     ^    %`

And to do so all you have to do is to write them with a Polish notation style as follows :

`​( space , + 5 ) `

And you should know the fact that :

`​( space , + 5 ) = ( space , @space + 5 )`

And so :

`​( space , - 5 ) = ( space , @space - 5 )( space ,  5 ) = ( space , @space  5 )( space , 5 ) = ( space , @space 5 )( space , ^ 5 ) = ( space , @space ^ 5 )`

# Doing something with what we’ve learned

You still may don’t understand why you should have spaces and what you can do with them! Look at this image: To go and create this thing you need to create random sized lines and how can you create a random number in Arendelle? We do the job using `#rnd` source. How? Each time you write a `#rnd` Arendelle generates a random number in format of `0.XXXXX` Like:

`0.023430.345340.008350.65789`

Now you may ask how to create a line with random size? All you need is to do :

#rnd * #width

And this way you get a random number to draw a line with random size! Now to draw this image you have to first move to the right line but how can you remember the right line? There will be another solution and it’s when you draw a line you back to it’s first and then move to the next line. But in both ways we have a problem in the first one we need to know what line we are and in the second one we have to remember what random number we generated right? As you see this is possible to do it with a space look at this code :

Way one:

`​( line , 0 ) [ #height ,​    i    [ @line , d ]     [ #rnd * #width , pr ]     ( line , +1 )    ] `

Way two:

`​[ #height ,​    ( randomSize , #rnd * #width )     [ @randomSize , pr ]     [ @randomSize , l ]     d   ] `

You can do so much magic with spaces! Look at this example: `​// First spacings    [ #i / 2 , r ]    [ #j / 2 , d ] ​// Starting dot    p​// Level counter    ( level , 2 ) ​// How many times?    ( times , #j / 4 ) ​// Main body    [ @times ,​         [ @level - 1 , rp ]          [ @level , dp ]        ( level , + 2 )        [ @level -1 , lp ]        [ @level , up ]        ( level , + 2 )       ] ​// Cleaning up    ( level , + 2 )    [ @level -1 , rp ]    [ 4 , cl ] ​// done `

As you observed this blueprints are more advanced then what you have seen till now. Its like you get super hero powers when you use spaces!

So now its time for you to practice!

Exercise Okay let’s begin with something easy. Code the following image: 