This folder contains examples and docs for the Gago programming language.
This file contains the basic syntax info. For other docs:
The basic syntax for the Gago language.
The Gago programming language is based off of lines, not semicolons (;
), so expressions must be of one line, except some special expressions: such as for
if
...
To import a module, you enter the import
keyword followed by the name of the module. To import the string module for example, you would do: import string
. Now all the string
methods and globals are accessible via string.<field>
.
Defining a variable will add it to the memory map, which can be accessed or manipulated later on.
const helloworld = "Hello World"
var helloworld = "Hello World"
You can assign functions like any other result.
const name = call input("enter your name: ")
the variable name now has the value of whatever input() returned.
To reassign a variable, you must make sure that you are reassigning the same type. If you try to assign a int
to a string
, you would get a error that looks like this:
TypeError: Can not assign value of type `int` to variable of type `string`
If you are sure that the types match, you can eassign a variable via the reset
keyword. An example script would be:
var test = "test variable"
call print("test:", test)
reset test = call input("new value for test: ")
call print("test:", test)
// examples/reassignment.gago
This would get the user input and assign it to the variable test
.
To call a function, you would do it like in most languages, but you need to add the call
keyword in the beginning of the expression.
An example of printing
call print("hello world!")
This would print out hello world!
in the terminal.
print
accepts as many arguments as you like, they will be printed out seperated by a space.
An example of taking input from the user
call input("enter your name ")
You can also store the result value of a function in a variable, like so:
const name = call input("enter your name ")
You can then print the value, like so
const name = call input("enter your name ")
call print("your name is", name)
// examples/name.gago
A more compact example of this would be
call print("your name is", call input("enter your name "))
// examples/v0.4name.gago
Math in Gago is like any other language.
const mexpr = 10+20+10
call print("mexpr:", mexpr)
// this will print out 40
You can also add together variables, mixing them with numbers too.
// examples/math.gago
const num1 = 10
const num2 = 20
call print("num1 + num2", num1 + num2)
call print("num1 / num2", num1 / num2)
call print("num1 ** num2", num1 ^ num2)
// output
/*
num1 + num2 30
num1 / num2 0.500000
num1 ** num2 -9223372036854775808
*/
Now you might ask, why is the output of num1 ** num2
(num1 raised to the power of num2) -9223372036854775808
. Well, it is because the actual value of num1 ** num2
is more than the max value of int64
. This is called a integer overflow, which causes the value to wrap and become negative.
You can also use math with the float
datatype. A simple example would be
// examples/float.gago
const fl = 10.123456
call print("fl =", fl)
call print("fl+10 =", fl+10)
call print("fl*2 =", fl*2)
call print("fl**2 =", fl**2)
// output
/*
fl = 10.123456
fl+10 = 20.123456
fl*2 = 20.246912
fl**2 = 102.484361
*/
In Gago, floats have a percision of 6. Which means that there can be 6 integers after the decimal point. If there are more than 6, it is rounded.
Docs for builtin functions
Print args
seperated by a space. There can be as many args as you want. They will be printed to standard out.
They can be of any type.
To get input from a user, you run the input(message)
function, where message
is a string that will be printed to standard out in the line where the input starts.
Example:
// examples/name.gago
const name = call input("whats your name? ")
call print("your name is", name)
Now you can enter your name in the command line, and it would print out your name is <yourname>
.
To exit from the process, you can run exit()
, with an optional <int code>
argument. The code
argument must be of type int.
Example:
exit(0)