tau

command module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2022 License: GPL-3.0 Imports: 15 Imported by: 0

README

τ

Tau is a dynamically-typed open source programming language designed to be minimal, fast and efficient.

Installation

In order to install Tau, you'll need Go.

Once done, running the following command will successfully install the tau interpreter:

go install github.com/NicoNex/tau@latest

You can try it out in the terminal by simply running $ tau, alternatively to take advantage of the builtin virtual machine and gain a lot of performance run it with $ tau -vm. The flag -vm works when executing files too. For additional info run $ tau --help.

Syntax

Hello World

We all start from here...

println("Hello World")
Examples
File

As every interpreter Tau supports files either by passing the path to the interpreter or by using the shebang.

#!/path/to/tau

println("hello world")
$ tau helloworld.tau
hello world
if-else blocks
if 1 > 0 {
	println("yes")
} else {
	println("no")
}
myVar = 10

if myVar > 10 {
	println("more than 10")
} else if myVar == 10 {
	println("it's exactly 10")
} else {
	println(myVar)
}
Declaring a function
loop = fn(times, function) {
	if times > 0 {
		function()
		loop(times-1, function)
	}
}

loop(5, fn() { println("Hello World") })
Noteworthy features

The return value can be implicit:

add = fn(x, y) { x + y }
sum = add(9, 1)
println(sum)
>>> 10

Also you can inline the if expressions:

a = 0
b = 1

minimum = if a < b { a } else { b }

The semicolon character ; is implicit on a newline but can be used to separate multiple expressions on a single line.

printData = fn(a, b, c) { println(a); println(b); println(c) }

Functions are first-class and treated as any other data type.

min = fn(a, b) {
	if a < b {
		return a
	}
	b
}

var1 = 1
var2 = 2

m = min(var1, var2)
println(m)
>>> 1
Error handling
# errtest.tau

div = fn(n, d) {
	if d == 0 {
		return error("zero division error")
	}
	n / d
}

if failed(result1 = div(16, 2)) {
	exit(result1)
}
println("the result of 16 / 2 is", result1)

if failed(result2 = div(32, 0)) {
	exit(result2)
}
println("the result of 32 / 0 is", result2)
$ tau errtest.tau
the result of 16 / 2 is 8
error: zero division error
$
REPL

Tau also supports REPL:

>>> add = fn(a, b) { a + b }
>>> string(add)
fn(a, b) { (a + b) }
>>> string(21)
21
>>> recursive_loop = fn(n, func) { if n != 0 { func(n); recursive_loop(n-1, func) } }
>>> recursive_loop(10, fn(n) { println("hello", n) })
hello 10
hello 9
hello 8
hello 7
hello 6
hello 5
hello 4
hello 3
hello 2
hello 1
Data types

Tau is a dynamically-typed programming language and it supports the following primitive types:

Integer
my_var = 10
Float
my_var = 2.5
String
str = "My string here"
Boolean
t = true
f = false
Function
pow = fn(base, exponent) {
	if exponent > 0 {
		return base * pow(base, exponent-1)
	}
	1 # You could optionally write 'return 1', but in this case the return is implicit.
}
List
empty = []
stuff = ["Hello World", 1, 2, 3, true]
Map
empty = {}
stuff = {"Hello": "World", 123: true}
Loop
for i = 0; i < 10; ++i {
	println("hello world", i)
}

lst = [0, 1, 2, 3, 4]

println(lst)
for len(lst) > 0 {
	println(lst = tail(lst))
}
Objects
obj = new()
obj.value1 = 123
obj.value2 = 456

obj.sum_values = fn() {
	obj.value1 + obj.value2
}

obj.child = new()
obj.child.value = obj.sum_values()
Dog = fn(name, age) {
	dog = new()

	dog.name = name
	dog.age = age

	dog.humanage = fn() {
		dog.age * 7
	}

	return dog
}

snuffles = Dog("Snuffles", 8)
println(snuffles.humanage())
>>> 56
Modules
Plugin

Tau plugin system makes it possible to import and use Go plugins in Tau seamlessly. To run your Go code in Tau just compile it with:

go build -buildmode=plugin -o myplugin.so

then you can import it in Tau with the plugin builtin function.

myplugin = plugin("path/to/myplugin.so")
Example

Go code:

package main

import "fmt"

func Hello() {
	fmt.Println("Hello World")
}

func Sum(a, b int) int {
	return a + b
}

Tau code:

myplugin = plugin("myplugin.so")

myplugin.Hello()
println("The sum is", myplugin.Sum(3, 2))

Output:

>>> Hello World
>>> The sum is 5

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL