-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added anonymous functions using fn() syntax, classes are broken so a …
…function with inner anonymous functions could work instead. Converted functions from statements into expressions
- Loading branch information
Showing
9 changed files
with
113 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,58 @@ | ||
import "std/algorithm.jam" | ||
import "std/linkedlist.jam" | ||
|
||
let x = sort([1,2,4,5,2,5,5]) | ||
println(x) | ||
|
||
const list = LinkedList() | ||
list.add(1) | ||
list.add(2) | ||
list.add(3) | ||
list.add(4) | ||
list.add(5) | ||
list.add(6) | ||
list.add(7) | ||
list.printList() | ||
list.remove(2) | ||
list.printList() | ||
|
||
fn adder(x) { | ||
fn add(y) { | ||
return x + y | ||
fn Person(name, age) { | ||
let this = {} | ||
this.name = name | ||
this.age = age | ||
|
||
this.sayHello = fn() { | ||
println("hello") | ||
} | ||
|
||
this.getName = fn() { | ||
return this.name | ||
} | ||
|
||
this.getAge = fn() { | ||
return this.age | ||
} | ||
|
||
this.setName = fn(name) { | ||
this.name = name | ||
} | ||
|
||
this.setAge = fn(age) { | ||
this.age = age | ||
} | ||
|
||
return this | ||
} | ||
|
||
const foo = Person("foo", 20) | ||
const bar = Person("bar", 25) | ||
|
||
foo.setName("baz") | ||
|
||
println(foo.getName()) | ||
println(bar.getName()) | ||
|
||
const StringBuilder = { | ||
new: fn() { | ||
let this = {} | ||
this.str = "" | ||
|
||
this.append = fn(s) { | ||
this.str = this.str + s | ||
} | ||
|
||
this.toString = fn() { | ||
return this.str | ||
} | ||
|
||
return this | ||
} | ||
return add | ||
} | ||
|
||
let add5 = adder(5) | ||
println(add5(2)) | ||
const sb = StringBuilder.new() | ||
sb.append("hello") | ||
sb.append(" world") | ||
|
||
println(sb.toString()) |