A dynamic language that puts C to shame. (jk, I built this to understand how langauges are designed from the ground up)
To utilize the REPL, run ./notc
, or provide it a file.
$ git clone https://github.com/EhsaanIqbal/notc
$ go build
$ ./notc examples/basic.notc
Explore: examples
notc supports the following data types: null
, bool
, int
, str
, array
,
and fn
. The int
type signifies a signed 64-bit integer, while strings are
immutable arrays of bytes, and arrays can dynamically grow.
>> let x = 10
>> let x = 10
>> let y = x * 2
>> (x + y) / 2 - 3
12
notc supports if
and else
:
>> let x = 10
>> let y = x * 2
>> if (x > y) { print("x is greater") } else { print("y is greater") }
x is greater
You can define named or anonymous functions, including functions within functions that reference outer variables (known as closures).
>> multiply := fn(x, y) { x * y }
>> multiply(50 / 2, 1 * 2)
50
>> fn(x) { x + 10 }(10)
20
>> newAdder := fn(x) { fn(y) { x + y } }
>> addTwo := newAdder(2)
>> addTwo(3)
5
>> sub := fn(a, b) { a - b }
>> applyFunc := fn(a, b, func) { func(a, b) }
>> applyFunc(10, 2, sub)
8
>> let x = "hello"
>> print(x + "mars")
hello mars
>> myArray := ["x", "y", 1, fn(x) { x * x }]
>> myArray[0]
x
>> myArray[4 - 2]
1
len(iterable)
Returns the length of the iterable (str
,array
).print(value...)
Outputs thevalue
(s) to standard output followed by a newline.push(array, value)
Returns a new array withvalue
added to the end ofarray
.