-
Notifications
You must be signed in to change notification settings - Fork 11
Reference Manual
-
echo
- print argument on a terminal -
ask
- print prefix and get input from the user -
get
- send GET HTTP request and return JSON, HTML, XML or Text depending on content-type of the response -
post
- send POST HTTP request similar toget
-
config
- configure the terminal -
prompt
- change the prompt (prefix that can be changed by using backspace) -
input
- enter text into a command like if user type it -
sleep
- pause the interpreter with given milliseconds
-
sleep*
- pause the interpreter but don't hide the cursor -
input*
- type into the command line with animation -
ask*
- get input from a user, the prefix is printed with typing animation -
echo*
- prints anything on the terminal with typing animation -
prompt*
- change the prompt with typing animation
Operator | Description |
---|---|
[] | array and object access |
() | parentheses grouping |
* / % | Multiplication, division, modulo |
+ - | Addition (or concatenation), subtraction |
< > <= >= | boolean compare |
== != | equal, not equal |
and | Boolean and |
or | Boolean or |
not | Boolean not |
# named function
def square(x)
return x * x
end
# anonymous function expression
let square = lambda(x)
return x * x
end
Functions supports splat operator:
def sum(*args)
let result = 0
for i in args do
result += i
end
return result
end
echo sum(1,2,3,4,5)
echo sum(*[1,2,3,4])
let x = 10
let y = "hello, world"
Gaiman supports standard form of numbers:
- integers
- hexadecimal
0x100
- octal
0777
- binary
0b11000111010101
- floating-point numbers
0.1e-2
or0.1e10
let x = [1,2,3,4]
it supports methods like in JavaScript map/reduce/filter/forEach/some/every/find/sort
.
let x = [1,2,3,4]
while x.length do
echo x.pop()
end
let x = {"foo" => "Hello", "bar" => "world"}
Strings allow for variable interpolation. Strings only support double-quotes.
let name = "John"
echo "Hello $name"
string methods have methods like in JavaScript e.g. replace/search/toLowerCase/toUpperCase
let x = <<<MSG
Hello
this
is
string
MSG
let x = /foo|bar/g
Parentheses around conditional are optional:
let name = ask "? "
if name == "foo" then
echo "this is FOO"
end
let name = ask "? "
if name == "foo" then
echo "is foo"
else if name == bar then
echo "is bar"
else
echo "is something else"
end
if name == "foo" then
echo "this is FOO"
end
Over array:
for i in [1, 2, 3, 4] do
echo i
end
Over key, value pair (array with index or dictionary)
let array = ["hello", "world"]
for key, value in array do
echo "$index => $value"
end
let dict = {"foo" => "hello", "bar" => "world"}
for key, value in dict do
echo "$key => $value"
end
Parentheses around conditional are optional:
while true do
let cmd = ask ">>> "
echo cmd
end
If you don't put async command like ask
inside while true
loop, you may create infinite loop.
But if something like this happen the application will detect that and stop the program.
You can use config
command to change the guard infinite loop.
To turn of the infinite loop protection use:
config {"loop_threshold" => infinity, "loop_timeout" => infinity}
You can also turn off echo newline at the end of the text, and make it explicit:
config {"newline" => false}
echo "this"
echo " is"
echo " the"
echo " text\n"
This will print "this is the text"
in a single line.
let cmd = ask "? "
if cmd =~ /echo (.+)/ then
echo $1
end
Each group in regex has $ variable defined.
Gaiman Programming Language - Copyright 2021-2022 Jakub T. Jankiewicz
Released with GNU GPL v3 License