Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,2 @@
func foo() { }
foo()

View file

@ -0,0 +1,3 @@
//There is no difference between subroutines and functions:
func foo() { } //doesn't explicitly return something (but in fact returns nil)
func bar(x) { return x * 2 } //explicitly returns value (keyword "return" can be omitted)

View file

@ -0,0 +1 @@
//All arguments are passed by reference

View file

@ -0,0 +1,15 @@
//Using a closure:
func apply(fun, fst) { snd => fun(fst, snd) }
//Usage:
func sum(x, y) { x + y }
var sum2 = apply(sum, 2)
var x = sum2(3) //x is 5
//By second argument
func flip(fun) { (y, x) => fun(x, y) }
func sub(x, y) { x - y }
var sub3 = apply(flip(sub), 3)
x = sub3(9) //x is 6

View file

@ -0,0 +1,2 @@
func foo(x, y, z) { }
foo(1, 2, 3)

View file

@ -0,0 +1,2 @@
func foo(x, y = 0, z = 1) { }
foo(1)

View file

@ -0,0 +1,2 @@
func foo(args...) { }
foo(1, 2, 3)

View file

@ -0,0 +1,2 @@
func foo(x, y, z) { }
foo(z: 3, x: 1, y: 2)

View file

@ -0,0 +1,4 @@
func foo() { }
if true {
foo()
}

View file

@ -0,0 +1,6 @@
func foo() { }
var x = if foo() {
1
} else {
2
}

View file

@ -0,0 +1,3 @@
func foo(x) { x * 2 }
var x = 2
var y = foo(x)

View file

@ -0,0 +1,11 @@
//Built-in functions are regular functions from an implicitly imported "lang" module
//There is no actual difference between these functions and user-defined functions
//You can however write a function that would check if a given function is declared in "lang" module:
func isBuiltin(fn) =>
fn.Name is not nil && fn.Name in lang && lang[fn.Name] == fn
//Usage:
func foo() { } //A user-defined function
print(isBuiltin(foo)) //Prints: false
print(isBuiltin(assert)) //Prints: true