TPL
- This article is not detailed enough and needs to be expanded. Please help us by adding some more information.
This is an idea that I had, that I really think is cool.
In TPL, each variable actually holds 3 different objects, depending on usage and keywords. It can hold a table, a function, and a variable.
To define a variable, you use var hello = "world"
. Tables can be defined with table objects = [1, "two", "three"]
, and functions with func double(x) = { return x * 2 }
.
TPL includes automatic type parsing for variables, so you don't have to use the keywords for definition. To quickly define multiple, use double square brackets like tpl = [[19, func (x) {print(x)}, [1, 2, 3]]]
In TPL, semicolons are permitted under normal rules, but you can also use line feeds. Comments are denoted with // this is a comment
.
Builtins
Function | Usage | Explanation |
---|---|---|
print() | print("hello") | Prints the argument. If printing a table or function, prints the definition. |
input() | input() | Takes user input as a string. |
inputnum() | inputnum() | Takes user input as a number. If any characters are not in [0,1,2,3,4,5,6,7,8,9,-,.], it returns an error. |
assert() | assert(1 + 2 == 3) | Errors if the argument is falsy. Falsy objects include empty tables, "", False, 0, and functions with no input, output, or returns. |
I honestly can't think of any more, except the obvious ones.
Examples
Hello world
print("Hello world")
99 bottles of beer
for (i = 99, 1) { if (i == 1) { print("1 bottle of beer on the wall,"); print("1 bottle of beer!") } else { print(i + " bottles of beer on the wall,"); print(i + " bottles of beer!") } print("Take one down, pass it around,") if (i == 2) { print("1 bottle of beer on the wall!") } else { print(i + " bottles of beer on the wall!") } }
fizzbuzz
i = 1 while True { if (i % 15 == 0) { print("fizzbuzz") } elif (i % 5 == 0) { print("buzz") } elif (i % 3 == 0) { print("fizz") } else { print(i) } i++ }
recursive fibonacci function
fib(x) = {if (x <= 2) {return 1} else {return fib(x-1) + fib(x-2)}}
truth machine
in = inputnum(); if (in == 0) {print(0)} else {while (True) {print(in)}}