mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 08:44:20 +03:00
Обновлены примеры
This commit is contained in:
parent
c382c4eab6
commit
ba60a498d7
3
examples/functions/function_call_chain.own
Normal file
3
examples/functions/function_call_chain.own
Normal file
@ -0,0 +1,3 @@
|
||||
def f() = def() = def() = def() = "Function call chaining: f()()()()"
|
||||
|
||||
println f()()()()
|
9
examples/functions/function_chain.own
Normal file
9
examples/functions/function_chain.own
Normal file
@ -0,0 +1,9 @@
|
||||
def calc() = {
|
||||
"add": ::add,
|
||||
"sub": ::minus
|
||||
}
|
||||
def add(x, y) = x + y
|
||||
def minus(x, y) = x - y
|
||||
|
||||
println calc().add(77, 42)
|
||||
println calc().sub(77, 42)
|
26
examples/functions/stream.own
Normal file
26
examples/functions/stream.own
Normal file
@ -0,0 +1,26 @@
|
||||
use "std"
|
||||
use "functional"
|
||||
|
||||
println "x, square(x), cube(x) for even numbers"
|
||||
data = [1,2,3,4,5,6,7,8,9]
|
||||
stream(data)
|
||||
.filter(def(x) = x % 2 == 0)
|
||||
.map(def(x) = [x, x * x, x * x * x])
|
||||
.sortBy(def(x) = -x[2])
|
||||
.forEach(::echo)
|
||||
|
||||
|
||||
println "\nReverse custom operator"
|
||||
data = [2, 4, 6, 5, 12, 34, 0, 18]
|
||||
rev = stream(data).custom(::reverse).toArray()
|
||||
println data
|
||||
println rev
|
||||
|
||||
def reverse(container) {
|
||||
size = length(container)
|
||||
result = newarray(size)
|
||||
for i : range(size) {
|
||||
result[size - i - 1] = container[i]
|
||||
}
|
||||
return result
|
||||
}
|
5
examples/java/system_info.own
Normal file
5
examples/java/system_info.own
Normal file
@ -0,0 +1,5 @@
|
||||
use "java"
|
||||
System = newClass("java.lang.System")
|
||||
println "OS name: " + System.getProperty("os.name")
|
||||
println "OS version: " + System.getProperty("os.version")
|
||||
println "User home: " + System.getProperty("user.home")
|
Loading…
Reference in New Issue
Block a user