Renamed 'scripts' directory to 'examples'

Also allowed assignment within conditionals
This commit is contained in:
2026-05-26 23:40:18 +10:00
parent bbb1e38649
commit 92e4a41662
14 changed files with 34 additions and 110 deletions
+11
View File
@@ -0,0 +1,11 @@
//fibonacci sequence
fn fib(n) {
if (n < 2) return n;
return fib(n-1) + fib(n-2);
}
print fib(12);
//Note to my future self: yes, the base case in 'fib()' is 'n < 2', stop second guessing yourself!
//Note to my past self: don't tell me what to do!
//Note to both of you: keep it down you young whipper snappers!
+24
View File
@@ -0,0 +1,24 @@
//standard example, using 'while' instead of 'for', because it's not ready yet
var counter: Int = 0;
while (++counter <= 100) {
var result: String = "";
if (counter % 3 == 0) {
result = result .. "fizz";
}
if (counter % 5 == 0) {
result = result .. "buzz";
}
//finally
if (result != "") {
print result;
}
else {
print counter;
}
}
+2
View File
@@ -0,0 +1,2 @@
//the semicolon is super important
print "Hello world!";
+18
View File
@@ -0,0 +1,18 @@
//is 'n' a leap year
fn isLeapYear(n: Int) {
if (n % 400 == 0) return true;
if (n % 100 == 0) return false;
return n % 4 == 0;
}
{
print isLeapYear(1999);
}
{
print isLeapYear(2000);
}
{
print isLeapYear(2004);
}
+10
View File
@@ -0,0 +1,10 @@
var randi: Int = 69420;
fn rand() {
//a quick and dirty random number generator
return randi = randi * 1664525 + 1013904223;
}
print rand();
print rand();
print rand();
+21
View File
@@ -0,0 +1,21 @@
fn makeCounter() {
var counter: Int = 0;
fn increment() {
return ++counter;
}
return increment;
}
//'tally' becomes a closure
var tally = makeCounter();
var result = 0;
while (result = tally()) {
print result;
if (result >= 10) {
break;
}
}