In JM° there are only Objects, Functions, Events, Variables and Constants. That's it!
So, let's get the first Object.
The Terminal always shows you the last result after a "=>".
Okay, let's do something:
This get's the Object "5" and calls the function "print". Print is a function, that every object has, and writes the object to the output.
Okay, let's see what type this object is:
It's "Int"! If you like, you can read more about this type in the documentation under "Int".
So, now we can calculate:
Now you have a little calculator.
JM° knows also point before line and you can use brackets.
By the way, the bracket is also a Object and +,-,*,/,% are functions. But later more.
If you want to print the result, you can try:
Well ... it prints the "9". Why? An alphanumeric function, called with a dot (".print"), has the highest priority.
Let's try this:
Now it prints the 32.
Variables can store a value. They begin always with a lowercase character and are created on the fly.
a = 4
Since the Shell immediately forgets the assignment, we now hang two commands together with a ';'.
a = 4; a.print
Now you can calculate a value and store it in the variable.
a = 3*(9+20); a.print
Let's try this with two variables:
a = 3; b = 9+20; (a*b).print
To create a list, we use the -brackets.
With such a list, you can do a lot of nice things. Please take a look at the documentation under "List".
This removes doubles, sorts the list, reverse all items and prints the result.
To get one item, use the .get-Function:
Here, the list will be sorted and we got the second item.
Remember: JM° counts the position, not the index. So 1 gets the first item, 2 the second, and so on.
If you want to use all items and do something with each item, you can use the each-function:
Uhhh ... 😁
After .each, we can go on with the Int-Number. Here we print it to the screen.
Another function to print is the ".echo"-function. This writes to the screen, but without a newline:
For a better result, we use the .echo with a parameter. So it prints that value, not the Int-Number:
[4,9,5,2,8,5].each.echo.echo(" is even: ").isEven.print
Echo end Print always return the previous value.
And, here we have a new atomic type: the Str (String)
Strings are created with two quotation marks:
"This is a String!"
And yes, it is also an object and we can use it the same way like the integer numbers.
"This is a String!".lower.left(4).print
Here we transform all chars to lower case and get a copy of the first (left) 4 chars.
Later more, this article is still in progress.