Programming
A musikla script is just a sequence of statements ( and expressions ). Each statement must be followed by a ;
, even if it ends in brackes {
and }
like an if
or while
.
Variables
Variables can stored and accessed by prefixing their name with a dollar sign $
.
1 2 3 |
|
Function Declarations
Functions are declared with the fun
keyword, followed by an optional function name. Function declarations are expressions that return a reference to the newly created function. This means that they can be saved in variables, passed as parameters to other functions, or otherwise used anywhere an expression could generally be used.
1 2 3 |
|
Function bodies can be multiline (like in the example above, surrounded by brackets {
}
) or single line indicated by an arrow =>
1 |
|
Reference Arguments
Function arguments can be declared as ref
, meaning that any changes done to them will be reflected on the variable outside the function. Reference
1 2 3 4 5 6 7 8 9 |
|
If/Else
Right now else if
's are not supported. The else
block is optional, of course.
1 2 3 4 5 |
|
While
1 2 3 |
|
For
1 2 3 |
|
Arrays
Arrays are a very common construct in programming languages, and they have proven very useful here as well.
Array literals can be constructed with the syntax @[]
1 2 3 4 5 6 7 8 9 |
|
Dictionaries
Similar to arrays, dictionary literals can be constructed with the syntax @{}
1 |
|
Dictionaries have four methods: has()
, get()
, set()
and delete()
. For convenience, their values can also be accessed using the regular property accessor syntax.
1 2 3 4 5 6 7 8 9 10 11 |
|
Embedding Python
It is possible to embed python code inside the language directly through the use of two directives: @py
for single python expressions and @python
for statement blocks.
The first directive can only contain python expressions, but can be used anywhere in the code. For instance, if we wanted to be able to use python list comprehensions on an array, we could simply do:
1 2 3 |
|
Note How variables in musikla are prefixed by a dollar sign
$
but in python are referenced simply by their name
The second directive @python
currently can only be used at the end of the file, since it treats everything after it as python code. It's execution is hoisted though (runs before anything else) which gives the user the possibility of defining functions or classes in python and using them in their code.
1 2 3 4 5 6 7 8 |
|