Own-Programming-Language-Tu.../program.own

120 lines
2.2 KiB
Plaintext
Raw Normal View History

use "math"
use "std"
word = 2 + 2
word2 = PI + word
str = "a" * 5 + "ba" * 7 + "\n"
2016-01-09 14:11:15 +02:00
println str * "3" * 2
println "word = " + word
println "word2 = " + word2
println "1" > "abc"
if (1 <= 2) println "1 = 1"
else println "1 != 1"
if (40 < 50 || 50 > 60) {
2016-01-09 14:11:15 +02:00
println "true1"
println "true2"
i = 0
2016-01-09 14:11:15 +02:00
println "do while"
do {
2016-01-09 14:11:15 +02:00
println "i = " + i
i = i + 1
} while (i < 10)
i = 0
2016-01-09 14:11:15 +02:00
println "while"
while (i < 10) {
2016-01-09 14:11:15 +02:00
println "i = " + i + sin(i)
i = i + 1
}
2016-01-09 14:11:15 +02:00
println "for"
for i = 0, i < 10, i = i + 1 {
2016-01-09 14:11:15 +02:00
println "i = " + i
}
}
2015-06-15 14:45:52 +03:00
else print "false"
print "sin(PI) = " + sin(PI/2)
echo(1,2,3,"4","5","text",sin(0),cos(0),sin(PI),cos(PI),PI)
a = "print"
print a
def name(a,b) {
echo("a = ", a, " b = ", b)
}
def sum(a,b) {
a = -60
return a+b
}
name(1,"text")
print sum(10, 15)
print a + "\n"
arr = [1, "text", sum(10, 15), [], ["text", [90, [7 + 6, [50]]]]]
2016-01-09 14:11:15 +02:00
println arr + "\n"
arr[0] = arr[0] + 1000 + arr[2]
print arr + "\n"
print arr[4][1] + "\n"
arr[4][1] = "text"
2016-01-09 14:11:15 +02:00
println arr[4][1]
print "\n\n"
array = newarray(2, 2, 2, 2)
2016-01-09 14:11:15 +02:00
println array
2015-07-17 14:51:56 +03:00
add = def(a,b) = a+b
sub = def(a,b) = a-b
mul = def(a,b) = a*b
div = def(a,b) = a/b
cube = def(x) = x*mul(x, x)
2015-07-17 14:51:56 +03:00
print "\n\n"
2016-01-09 14:11:15 +02:00
println mul(8, 5)
println cube(2)
2015-07-17 14:51:56 +03:00
functions = [add, sub, mul, div]
def function(f, a, b) = f(a, b)
2015-07-17 14:51:56 +03:00
for i = 0, i < 4, i = i + 1 {
2016-01-09 14:11:15 +02:00
println functions[i]
println function(functions[i], 6, 3)
}
// map
map = {"+" : add, "-" : sub. "*" : mul, "/" : div}
map["%"] = def(x,y) = x % y
map["pow"] = def(x,y) = pow(x, y)
2016-01-09 14:11:15 +02:00
println map["+"]
println function(map["+"], 4, 5)
foreach(map, def(op, func) = echo (4, op, 5, "=", func(4,5)))
foreach(arr, ::echo)
arr1 = [1,2,3]
arr1 = arr1 :: 4
arr2 = [5,6,7]
2016-01-09 14:11:15 +02:00
println arr1
println arr1 << arr2
2016-01-09 13:13:04 +02:00
for op, func : map {
echo (4, op, 5, "=", func(4,5))
}
for v : arr1 print "" + v + ", "
print "\n"
for (v : arr1 << arr2) print "" + v + ", "
print "\n"
for v : [1,2,3,4,5,6,7,8,9] print "" + v + ", "
2016-01-09 14:00:07 +02:00
use "types"
2016-01-09 14:11:15 +02:00
println typeof(1)
println typeof("1")
println typeof(arr1)
println typeof({})
println typeof(add)
2016-01-09 14:00:07 +02:00
2016-01-09 14:11:15 +02:00
println typeof(number("1"))
println typeof(string(1))
thread(::inthread)
def inthread() = echo("this is a thread")
thread(def (str) { println str }, "this is a thread with arguments")