add some stuff
i am a reasonable human being
This commit is contained in:
parent
b9439a921a
commit
b3ac29fd3b
4 changed files with 56 additions and 0 deletions
23
examples/add.jt
Normal file
23
examples/add.jt
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import io
|
||||||
|
|
||||||
|
fn add (int a, int b) -> int {
|
||||||
|
a + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// return type is void by default
|
||||||
|
fn main () {
|
||||||
|
// explicit types, or
|
||||||
|
int val = add(2, 2)
|
||||||
|
|
||||||
|
// type inferred from the functions' return value
|
||||||
|
val := add(2, 2)
|
||||||
|
|
||||||
|
// variables are immutable, however, you can update them with
|
||||||
|
// the value of the old one.
|
||||||
|
val = val + 1
|
||||||
|
|
||||||
|
// a shorthand is val++, same for val--.
|
||||||
|
|
||||||
|
// string interpolation is implicit
|
||||||
|
io.puts("2 plus 2 = {val}")
|
||||||
|
}
|
22
examples/clojures.jt
Normal file
22
examples/clojures.jt
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import io
|
||||||
|
|
||||||
|
fn main () {
|
||||||
|
x := 0
|
||||||
|
|
||||||
|
// since variable are immutable but updatable, x is 1 inside clojure, but
|
||||||
|
// 0 inside main()
|
||||||
|
fn inner() {
|
||||||
|
x++
|
||||||
|
}
|
||||||
|
|
||||||
|
inner()
|
||||||
|
|
||||||
|
// shows 0
|
||||||
|
io.puts("x is {x}")
|
||||||
|
|
||||||
|
// however, if you explicitly update x:
|
||||||
|
x = inner()
|
||||||
|
|
||||||
|
// shows 1
|
||||||
|
io.puts("x is {x}")
|
||||||
|
}
|
5
examples/hello.jt
Normal file
5
examples/hello.jt
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import io
|
||||||
|
|
||||||
|
fn main () {
|
||||||
|
io.shit("pant")
|
||||||
|
}
|
6
src/main.c
Normal file
6
src/main.c
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in a new issue