Wal is lisp-inspired scripting language with really weird tokens written in rust.
❗ This language is under development and code you have written yesterday may not work today ❗
- - rewrite each function to rust function with some better argument validation (regex?)
- - split into multiple files
- - custom functions
- - all the basic functions
$ git clone https://github.com/TENMAJKL/wal
$ cargo run <file.wal>
Wal is not directly functional programming language, but everything you do its via functions.
Each function is inside []
, first word is function name and other words (separated by space) are arguments.
Lets see a quick example:
[-> 'Hello world!']
On this example we can see calling function ->
which prints all given arguments. The first argument ('Hello world!'
) is string literal, so output will be Hello world!
.
Wal currently supports only string literarls and positive integers.
For comments is used #
which ends with new line:
# demonstration of comments
[-> 'foo'] # this is print
# [-> 'bar'] this wont evaluate
Everything except literarls in wal is a function even operators, so for adding 2 numbers we use function +
:
[+ 1 2]
Function +
returns sum of given arguments, so if we want to print it:
[-> [+ 1 2]]
The same goes for -
:
[-> [- 1 2]]
And *
:
[-> [* 2 3]]
For comparing, there is function =
:
[-> [= 1 2]] # false
[-> [= 1 1]] # true
[-> [= 'foo' 'foo']] # true
And its strict:
[-> [= '1' 1]] # false
If we want to invert boolean we can use !
:
[-> [! [= 1 2]]] # true
Wal has if function =<
called "sad face operator" which works like ternary operator:
[=< [= 1 2]
[-> 'foo']
[-> 'bar']
]
If first argument is true, it evaluates and returns output of second argument, if not the same goes for third.
[->
[=< [= 1 2]
'foo'
'bar'
]
]
Why =<
? Because this operator literally looks like branch.
Wal has simple system of variables, all the manipulation is done with function $
:
[$ foo 10] # created variable called foo with value 10
[-> [$ foo]] # accessing variable
If the function has only 1 argument it returns value of given variable. If it has 2 arguments it sets the value to the variable and returns the value.
You can also access enviromet variables with $_
:
[-> [$_ 'REQUEST_METHOD']]
Function @
creates array and returns it. Its not saved:
[@ 1 2 3 'foo']
So if we want to save it we have to put it in variable explicitely
[$ array
[@ 1 2 3 'foo']
]
Arrays can be printed:
[-> [@ 1 2 'foo']] # Array: 1 2 'foo'
Function @>
pushes all arguments to the top of array given as first argument.
[-> [@> [@ 1 2] 3]] # 1 2 3
More complex example:
[$ array
[@ 1 2 3 'foo']
]
[$ array
[@>
[$ array]
1
]
]
[-> [$ array]] # 1 2 3 'foo' 1
We can also use function ..
which will create array in range from first to second argument.
[-> [.. 1 5]]
For indexing there is @$
function which returns element on index from first argument or if there is third argument it sets item on given index to the third argument value and returns the array:
[$ array
[@ 1 2 3]
]
[->
[@$
[$ array]
1
]
] ; outputs 2
[-> [@$ [$ array] 1 3]] # outputs Array: 1 3 3
In wal is implemented for loop with <>
function:
[<> item [@ 1 2 3] [-> [$ item]]]
[$ item] # here wont work
first parameter is variable that will contain each iteration, second is array that will be iterated and the rest is body which will be statement by statement executed.
Wal has function <-
which returns value from standart input:
[$ name [<-]]
[-> 'Hello ' [$ name]]