ZunScript
ZunScript is a conceptual Scripting Language.
Below are some loosely-defined syntax rules.
I am borrowing and expanding upon concepts of Ruby, Python and Lua.
The main features I want to explore with ZunScript are method and parameter binding as well as a very monkeypatchable langauge.
I am trying to boil everything down to the a few very simple and concise rules and ideas with clear syntax;
On a higher level than Lua but not as polluted as Ruby is in my opinion (for example things like $1, $2, ...
are way too specific to be in a language's core for example).
I want to eliminate keywords and hardcoded things wherever possible, if possible to the point where control structures are just functions too.
Property Access
You can access an objects raw properties with the !
symbol:
object!value # obtain value of object
object!method # obtain method of object
Methods can be bound with the .
symbol:
object.method # obtain method of object (bound to object)
this will return another function that accepts one parameter less and is bound to object
instead.
Calling
You can invoke functions with the !
symbol:
method!
method! 1, 2, 3
Together with bound/unbound property access you can do various things:
object = {}
def object.trace a, b, c # => function(3)
return a, b, c
end
object.trace # => function(2)
object!trace # => function(3)
object.trace! # => <object>, nil, nil
object.trace! 1, 2 # => <object>, 1, 2
object!trace! # => nil, nil, nil
object!trace! 1, 2 # => 1, 2, nil
a = object.trace 1, 2 # => function(0)
b = object!trace 1, 2 # => function(1)
a! # => <object>, 1, 2
b! # => 1, 2, nil
b! 3 # => 1, 2, 3
Blocks
Blocks start with >
and end with end
:
do
print! "hello"
end
They can accept parmeters after the >
sign:
print_block = >a, b
print! a, b
end
Blocks can be passed as parameters (as lambdas):
for 1, 4, >a
print! a
end
Single lines can also be passed as blocks:
just_like_if = <, condition, block
if condition, <
block!
end
end
print! "value was true!" < kind_of_if value
This will:
3. bind value
to kind_of_if
2. build a Block from `print! "value was true!"
- invoke the bound
kind_of_if
with the Block as a parameter.
It is synonymous to this piece of code:
kind_of_if! value, <
print! "value was true!"
end
Single-line Block literals can also accept parameters:
print! a, b <a, b for 1, 4