Toronto is a simple, general purpose programming language which compiles into javascript.
Toronto is still a work in progress.
Download Deno, which is an alternative JavaScript runtime to Node.
Then, download this repository and use it as a template, don't touch any of the files besides main.toronto
.
To make a comment, use a #
and then that entire line will be ignored.
# This is a comment.
# Use it as many times as you want.
To send data to the console, use the print
keyword.
print "Hello World!"
To get data from the console use the input
keyword.
var inp = input "What is your name?"
To make a variable use the var
keyword.
var string = "Hello World!"
To make a mutable variable use the mut
keyword.
mut string = "Hello World!"
string = "Hello, World!"
A template string allows us to substitute values in the string for something else.
var name = "John Doe"
print 'Hello ${name}!'
To make a function use the func
keyword.
func sayHello(name){
print 'Hello ${name}!'
}
Use return
to return data.
func add(x,y){
return x + y
}
Here are all the builtin functions, there arguments, and what they return.
toInt
accepts a string with a number in it, then returns that string as a integer.
print toInt("36") # >> 36
sqrt
accepts a number and returns the square root of that number.
print sqrt(25) # >> 5
exec
accepts a string containing toronto code and executes it. Does not return anything.
exec('print "Hello World"') # >> Hello World!
To make a function asynchronous, use the async
keyword.
async func add(x,y){
return x + y
}
This gives you access to the await
keyword, which can be used to resolve promises.
In toronto, the majority of your code lives inside the main
function.
If you don't use the main
function then your code will error.
async func main(){ # Main function does not have to be asynchronous.
print add(1,3)
}
func add(x,y){
return x + y
}
To create a promise, use the promise
keyword, followed by the name of the promise and the resolvable value.
promise hello = "Hello World!"
Then use the await
keyword in an asynchronous function to resolve the promise.
print await hello