Last active
April 23, 2024 04:47
-
-
Save lfnoise/8ab785f2cc4bd1aafb992d6a39e53384 to your computer and use it in GitHub Desktop.
unit tests for new audio-oriented scripting language.
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
RUN TESTS | |
>============================================================================ | |
fn foo(x,y) { | |
"A" println | |
\a,b{ print(a,b,"; ") }(x@,y@) | |
"B" println | |
} | |
foo([2,3,4,5],[9,8,7,6]) | |
"done" println | |
A | |
2 9 ; 3 8 ; 4 7 ; 5 6 ; B | |
done | |
test output: | |
RESULT: | |
done | |
<============================================================================ | |
>============================================================================ | |
\a,b{print(a,b,"; ")}([2,3,4,5]@, [9,8,7,6]@) | |
println() | |
2 9 ; 3 8 ; 4 7 ; 5 6 ; | |
test output: | |
RESULT: | |
nil | |
<============================================================================ | |
>============================================================================ | |
Class class println === Class_class | |
Class_class | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
Class_class class println === Class | |
Class | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
Obj class println === Obj_class | |
Obj_class | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
Obj_class class println === Class | |
Class | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
Class directSuperclasses println | |
[Scalar] | |
test output: | |
RESULT: | |
[Scalar] | |
<============================================================================ | |
>============================================================================ | |
Obj directSuperclasses println | |
[] | |
test output: | |
RESULT: | |
[] | |
<============================================================================ | |
>============================================================================ | |
Class_class directSuperclasses println | |
[Obj_class] | |
test output: | |
RESULT: | |
[Obj_class] | |
<============================================================================ | |
>============================================================================ | |
Obj_class directSuperclasses println | |
[Class] | |
test output: | |
RESULT: | |
[Class] | |
<============================================================================ | |
>============================================================================ | |
Class allSuperclasses println | |
[Class, Scalar, Obj] | |
test output: | |
RESULT: | |
[Class, Scalar, Obj] | |
<============================================================================ | |
>============================================================================ | |
Obj allSuperclasses println | |
[Obj] | |
test output: | |
RESULT: | |
[Obj] | |
<============================================================================ | |
>============================================================================ | |
Class_class allSuperclasses println | |
[Class_class, Obj_class, Class, Scalar, Obj] | |
test output: | |
RESULT: | |
[Class_class, Obj_class, Class, Scalar, Obj] | |
<============================================================================ | |
>============================================================================ | |
Obj_class allSuperclasses println | |
[Obj_class, Class, Scalar, Obj] | |
test output: | |
RESULT: | |
[Obj_class, Class, Scalar, Obj] | |
<============================================================================ | |
>============================================================================ | |
var x={a:1,b:2,c:3};x.c = x; x | |
test output: | |
RESULT: | |
{a: 1, b: 2, c: { ⟘^1 }} | |
<============================================================================ | |
>============================================================================ | |
--this is a comment | |
"xyz" println -- this is too | |
xyz | |
test output: | |
RESULT: | |
xyz | |
<============================================================================ | |
>============================================================================ | |
"xyz" println | |
"abc" println | |
xyz | |
abc | |
test output: | |
RESULT: | |
abc | |
<============================================================================ | |
>============================================================================ | |
"xyz" println | |
xyz | |
test output: | |
RESULT: | |
xyz | |
<============================================================================ | |
>============================================================================ | |
"xyz" println | |
xyz | |
test output: | |
RESULT: | |
xyz | |
<============================================================================ | |
>============================================================================ | |
"xyz" println -- a comment | |
xyz | |
test output: | |
RESULT: | |
xyz | |
<============================================================================ | |
>============================================================================ | |
(1,2,3) println -- a tuple | |
(1, 2, 3) | |
test output: | |
RESULT: | |
(1, 2, 3) | |
<============================================================================ | |
>============================================================================ | |
[1,2,3] println -- an array | |
[1, 2, 3] | |
test output: | |
RESULT: | |
[1, 2, 3] | |
<============================================================================ | |
>============================================================================ | |
("xyz") println -- string | |
xyz | |
test output: | |
RESULT: | |
xyz | |
<============================================================================ | |
>============================================================================ | |
("xyz" $ "abc") println -- string concatenation | |
xyzabc | |
test output: | |
RESULT: | |
xyzabc | |
<============================================================================ | |
>============================================================================ | |
("xyz" * 3) println -- string repetition | |
xyzxyzxyz | |
test output: | |
RESULT: | |
xyzxyzxyz | |
<============================================================================ | |
>============================================================================ | |
"xyz" * 3 |> println -- string repetition with pipe operator | |
xyzxyzxyz | |
test output: | |
RESULT: | |
xyzxyzxyz | |
<============================================================================ | |
>============================================================================ | |
\x,y[y](3,-4) -- apply arguments to lambda | |
test output: | |
RESULT: | |
-4 | |
<============================================================================ | |
>============================================================================ | |
7 typeName println | |
Int | |
test output: | |
RESULT: | |
Int | |
<============================================================================ | |
>============================================================================ | |
7 typeName print | |
Inttest output: | |
RESULT: | |
Int | |
<============================================================================ | |
>============================================================================ | |
7 typeName print; " that was a test." println | |
Int that was a test. | |
test output: | |
RESULT: | |
that was a test. | |
<============================================================================ | |
>============================================================================ | |
("abc" * 5) println | |
abcabcabcabcabc | |
test output: | |
RESULT: | |
abcabcabcabcabc | |
<============================================================================ | |
>============================================================================ | |
("xyz" $ 9 str) println | |
xyz9 | |
test output: | |
RESULT: | |
xyz9 | |
<============================================================================ | |
>============================================================================ | |
let (nl, sp, tb) = ("\n", " ", "\t") | |
tb $ "x" $ sp $ "y" $ nl $ "z" $ nl |> print | |
x y | |
z | |
test output: | |
RESULT: | |
x y | |
z | |
<============================================================================ | |
>============================================================================ | |
("\U1f600" * 3) println -- unicode hex syntax | |
😀😀😀 | |
test output: | |
RESULT: | |
😀😀😀 | |
<============================================================================ | |
>============================================================================ | |
("\U01f600" * 3) println | |
😀😀😀 | |
test output: | |
RESULT: | |
😀😀😀 | |
<============================================================================ | |
>============================================================================ | |
("\U001f600" * 3) println | |
😀😀😀 | |
test output: | |
RESULT: | |
😀😀😀 | |
<============================================================================ | |
>============================================================================ | |
("\U0001f602" * 3) println | |
😂😂😂 | |
test output: | |
RESULT: | |
😂😂😂 | |
<============================================================================ | |
>============================================================================ | |
("\U00001f602" * 3) println | |
ὠ2ὠ2ὠ2 | |
test output: | |
RESULT: | |
ὠ2ὠ2ὠ2 | |
<============================================================================ | |
>============================================================================ | |
(1, 2, -3, 4) len println -- tuple length | |
4 | |
test output: | |
RESULT: | |
4 | |
<============================================================================ | |
>============================================================================ | |
[1, 2, -3, 4] len println -- array length | |
4 | |
test output: | |
RESULT: | |
4 | |
<============================================================================ | |
>============================================================================ | |
[-1, 2, 3] len println | |
3 | |
test output: | |
RESULT: | |
3 | |
<============================================================================ | |
>============================================================================ | |
[1] len println | |
1 | |
test output: | |
RESULT: | |
1 | |
<============================================================================ | |
>============================================================================ | |
(& -1) println -- & creates a reference | |
-1 | |
test output: | |
RESULT: | |
-1 | |
<============================================================================ | |
>============================================================================ | |
let x = &1; x println | |
1 | |
test output: | |
RESULT: | |
1 | |
<============================================================================ | |
>============================================================================ | |
let x = &1; x setRef(2); x println -- set a reference | |
2 | |
test output: | |
RESULT: | |
2 | |
<============================================================================ | |
>============================================================================ | |
(2π + 1) println -- Pi as a numeric suffix | |
7.283185307179586 | |
test output: | |
RESULT: | |
7.283185307179586 | |
<============================================================================ | |
>============================================================================ | |
(complex(3,2.) + 1.) println -- complex number | |
x64(4., 2.) | |
test output: | |
RESULT: | |
x64(4., 2.) | |
<============================================================================ | |
>============================================================================ | |
(3 complex(-2.) + 1.) println | |
x64(4., -2.) | |
test output: | |
RESULT: | |
x64(4., -2.) | |
<============================================================================ | |
>============================================================================ | |
let cx = complex; (3 cx(2.) + 1.) println | |
x64(4., 2.) | |
test output: | |
RESULT: | |
x64(4., 2.) | |
<============================================================================ | |
>============================================================================ | |
let cx = complex; (3 cx 2. + 1.) println | |
x64(4., 2.) | |
test output: | |
RESULT: | |
x64(4., 2.) | |
<============================================================================ | |
>============================================================================ | |
[1+2, 2+3., 4.+5, 6.+7., complex(1,2)+3., 8µ, 9u] println -- µ is a numeric suffix (micro, 1e-6) | |
[3, 5., 9., 13., x64(4., 2.), 8e-06, 9e-06] | |
test output: | |
RESULT: | |
[3, 5., 9., 13., x64(4., 2.), 8e-06, 9e-06] | |
<============================================================================ | |
>============================================================================ | |
-2.1 println | |
-2.1 | |
test output: | |
RESULT: | |
-2.1 | |
<============================================================================ | |
>============================================================================ | |
-2.1 asInt println -- conversions | |
-2 | |
test output: | |
RESULT: | |
-2 | |
<============================================================================ | |
>============================================================================ | |
2 asFloat println | |
2. | |
test output: | |
RESULT: | |
2. | |
<============================================================================ | |
>============================================================================ | |
2 asComplex println | |
x64(2., 0.) | |
test output: | |
RESULT: | |
x64(2., 0.) | |
<============================================================================ | |
>============================================================================ | |
3. asComplex println | |
x64(3., 0.) | |
test output: | |
RESULT: | |
x64(3., 0.) | |
<============================================================================ | |
>============================================================================ | |
2 asRational println | |
2/1 | |
test output: | |
RESULT: | |
2/1 | |
<============================================================================ | |
>============================================================================ | |
-7 + 3 |> asComplex println | |
x64(-4., 0.) | |
test output: | |
RESULT: | |
x64(-4., 0.) | |
<============================================================================ | |
>============================================================================ | |
(1) println -- parenthesized value | |
1 | |
test output: | |
RESULT: | |
1 | |
<============================================================================ | |
>============================================================================ | |
(1,) println -- trailing comma creates a mono-tuple | |
(1) | |
test output: | |
RESULT: | |
(1) | |
<============================================================================ | |
>============================================================================ | |
() println -- empty tuple | |
() | |
test output: | |
RESULT: | |
() | |
<============================================================================ | |
>============================================================================ | |
[1] println | |
[1] | |
test output: | |
RESULT: | |
[1] | |
<============================================================================ | |
>============================================================================ | |
[1,] println -- trailing comma is OK | |
[1] | |
test output: | |
RESULT: | |
[1] | |
<============================================================================ | |
>============================================================================ | |
[] println -- empty array | |
[] | |
test output: | |
RESULT: | |
[] | |
<============================================================================ | |
>============================================================================ | |
let (x,y,(_,z))=(1+2.,-3,(9,"Z")); [y,z,y,x] println -- pattern matching assignment | |
[-3, Z, -3, 3.] | |
test output: | |
RESULT: | |
[-3, Z, -3, 3.] | |
<============================================================================ | |
>============================================================================ | |
let [x,y,(_,z)]=[1+2.,-3,(9,"Z")]; (y,z,y,x) println | |
(-3, Z, -3, 3.) | |
test output: | |
RESULT: | |
(-3, Z, -3, 3.) | |
<============================================================================ | |
>============================================================================ | |
let [x,y,(_,z)]=[1+2.,-3,[9,"Z"]]; (y,z,y,x) println | |
error: 1 Assignment pattern match failed. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
let [x,y,[_,z]]=[1+2.,-3,[9,"Z"]]; (y,z,y,x) println | |
(-3, Z, -3, 3.) | |
test output: | |
RESULT: | |
(-3, Z, -3, 3.) | |
<============================================================================ | |
>============================================================================ | |
let [x,y,[_,z]]=[1+2.,-3,[9,"Z"]]; [y,z,y,x] println | |
[-3, Z, -3, 3.] | |
test output: | |
RESULT: | |
[-3, Z, -3, 3.] | |
<============================================================================ | |
>============================================================================ | |
let [x,y,(_,z)]=[1+2.,-3,[9,"Z"]]; [y,z,y,x] println | |
error: 1 Assignment pattern match failed. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
let [err, val] = try { let [x,y,[_,z]]=[1+2.,-3,[9,"Z"]]; [y,z,y,x] println } -- error returns | |
[-3, Z, -3, 3.] | |
test output: | |
RESULT: | |
[nil, [-3, Z, -3, 3.]] | |
<============================================================================ | |
>============================================================================ | |
let [err, val] = try { 9 crashme } -- error returns | |
test output: | |
RESULT: | |
[Error{code: 3, what: Undefined global variable 'crashme'}, nil] | |
<============================================================================ | |
>============================================================================ | |
Float allSuperclasses println | |
[Float, Real, Complex, Number, Scalar, Obj] | |
test output: | |
RESULT: | |
[Float, Real, Complex, Number, Scalar, Obj] | |
<============================================================================ | |
>============================================================================ | |
Float directSuperclasses println | |
[Real] | |
test output: | |
RESULT: | |
[Real] | |
<============================================================================ | |
>============================================================================ | |
[1, 2, 3] asTuple println -- List to Tuple | |
(1, 2, 3) | |
test output: | |
RESULT: | |
(1, 2, 3) | |
<============================================================================ | |
>============================================================================ | |
(1, 2, 3) asList println -- Tuple to List | |
[1, 2, 3] | |
test output: | |
RESULT: | |
[1, 2, 3] | |
<============================================================================ | |
>============================================================================ | |
lcm(6,9) println | |
18 | |
test output: | |
RESULT: | |
18 | |
<============================================================================ | |
>============================================================================ | |
18 gcd 30 + 1 |> println | |
7 | |
test output: | |
RESULT: | |
7 | |
<============================================================================ | |
>============================================================================ | |
gcd 18 30 + 1 |> println | |
7 | |
test output: | |
RESULT: | |
7 | |
<============================================================================ | |
>============================================================================ | |
gcd 18 30 println | |
6 | |
test output: | |
RESULT: | |
6 | |
<============================================================================ | |
>============================================================================ | |
-2.1 asInt println | |
-2 | |
test output: | |
RESULT: | |
-2 | |
<============================================================================ | |
>============================================================================ | |
complex(3,2) re println -- get real part | |
3. | |
test output: | |
RESULT: | |
3. | |
<============================================================================ | |
>============================================================================ | |
complex(3,2) im println -- get imaginary part | |
2. | |
test output: | |
RESULT: | |
2. | |
<============================================================================ | |
>============================================================================ | |
rational(3,2) nu println -- get numerator | |
3 | |
test output: | |
RESULT: | |
3 | |
<============================================================================ | |
>============================================================================ | |
rational(3,2) de println -- get denominator | |
2 | |
test output: | |
RESULT: | |
2 | |
<============================================================================ | |
>============================================================================ | |
complex(3,2.) + 1. |> println | |
x64(4., 2.) | |
test output: | |
RESULT: | |
x64(4., 2.) | |
<============================================================================ | |
>============================================================================ | |
"\U1f608\U1f606" * 3 |> println | |
😈😆😈😆😈😆 | |
test output: | |
RESULT: | |
😈😆😈😆😈😆 | |
<============================================================================ | |
>============================================================================ | |
5. isa(Float) println | |
true | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
5. isa(Obj) println | |
true | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
5. isa(Class) println | |
false | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
5. is 5. println | |
true | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
5. is 3. println | |
false | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
5. is 5 println | |
false | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
5 is 5 println | |
true | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
let x = complex(5,3); x is(x) println | |
true | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
let x = 5 complex 3; x is 7 println | |
false | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
3 id println | |
3 | |
test output: | |
RESULT: | |
3 | |
<============================================================================ | |
>============================================================================ | |
\x[x] id println | |
<Lambda> | |
test output: | |
RESULT: | |
<Lambda> | |
<============================================================================ | |
>============================================================================ | |
\x[x+x](3) println | |
6 | |
test output: | |
RESULT: | |
6 | |
<============================================================================ | |
>============================================================================ | |
id() \x[x] println | |
<Lambda> | |
test output: | |
RESULT: | |
<Lambda> | |
<============================================================================ | |
>============================================================================ | |
id \x[x] println | |
<Lambda> | |
test output: | |
RESULT: | |
<Lambda> | |
<============================================================================ | |
>============================================================================ | |
3 complex 2 + 1 println | |
1 | |
test output: | |
RESULT: | |
x64(4., 2.) | |
<============================================================================ | |
>============================================================================ | |
3 complex 2 + 1 |> println | |
x64(4., 2.) | |
test output: | |
RESULT: | |
x64(4., 2.) | |
<============================================================================ | |
>============================================================================ | |
3 complex 2 pointer hexstr println | |
0x1232ae080 | |
test output: | |
RESULT: | |
0x1232ae080 | |
<============================================================================ | |
>============================================================================ | |
let x = (?(3 complex 2), ?(5 complex 4), 2, 3) | |
let (a, _, _, _) = x | |
a println | |
x64(3., 2.) | |
test output: | |
RESULT: | |
x64(3., 2.) | |
<============================================================================ | |
>============================================================================ | |
let x = (?(\[#now println; 3 complex 2]()), ?(5 complex 4), 2, 3) | |
#A println | |
let (a, _, _, _) = x | |
#B println | |
a println | |
A | |
B | |
now | |
x64(3., 2.) | |
test output: | |
RESULT: | |
x64(3., 2.) | |
<============================================================================ | |
>============================================================================ | |
let 😀 = 121; 😀 sqrt println -- unicode identifier | |
11. | |
test output: | |
RESULT: | |
11. | |
<============================================================================ | |
>============================================================================ | |
fn foo(a Int, b Int) { (b,a) } | |
foo(3,4) println | |
(4, 3) | |
test output: | |
RESULT: | |
(4, 3) | |
<============================================================================ | |
>============================================================================ | |
fn foo(a Int, b Int) { (b,a) } | |
fn foo(a Obj, b Obj) { (a,b,b,a) } | |
foo(3,4) println | |
foo(5.,6.) println | |
foo(3,4) println | |
foo(5.,6.) println | |
(4, 3) | |
(5., 6., 6., 5.) | |
(4, 3) | |
(5., 6., 6., 5.) | |
test output: | |
RESULT: | |
(5., 6., 6., 5.) | |
<============================================================================ | |
>============================================================================ | |
fn foo(a Int, b Int) = (b,a) | |
foo(3,4) println | |
(4, 3) | |
test output: | |
RESULT: | |
(4, 3) | |
<============================================================================ | |
>============================================================================ | |
fn foo(a Int, b Int) = (b,a) | |
fn foo(a Obj, b Obj) = (a,b,b,a) | |
foo(3,4) println | |
foo(5.,6.) println | |
foo(3,4) println | |
foo(5.,6.) println | |
(4, 3) | |
(5., 6., 6., 5.) | |
(4, 3) | |
(5., 6., 6., 5.) | |
test output: | |
RESULT: | |
(5., 6., 6., 5.) | |
<============================================================================ | |
>============================================================================ | |
defClass(#Florg, [Scalar], {z:7}) println | |
Florg | |
test output: | |
RESULT: | |
Florg | |
<============================================================================ | |
>============================================================================ | |
defClass(#Florg, [Scalar], {z:7}); Florg new({x:2π, y:1}) println | |
Florg{x:6.283185307179586, y:1} | |
test output: | |
RESULT: | |
Florg{x: 6.283185307179586, y: 1} | |
<============================================================================ | |
>============================================================================ | |
defClass(#Florg, [Scalar], {z:7}); Florg{x:2π, y:1} println | |
Florg{x:6.283185307179586, y:1} | |
test output: | |
RESULT: | |
Florg{x: 6.283185307179586, y: 1} | |
<============================================================================ | |
>============================================================================ | |
defClass(#Florg, [Scalar], {z:7}); let f = Florg{x:2π, y:1}; [f, f.x, f.y, f.z] println | |
[Florg{x:6.283185307179586, y:1}, 6.283185307179586, 1, 7] | |
test output: | |
RESULT: | |
[Florg{x: 6.283185307179586, y: 1}, 6.283185307179586, 1, 7] | |
<============================================================================ | |
>============================================================================ | |
defClass(#Florg, [Scalar]) {z:7}; let f = Florg{x:2π, y:1}; [f, f.x, f.y, f.z] println | |
[Florg{x:6.283185307179586, y:1}, 6.283185307179586, 1, 7] | |
test output: | |
RESULT: | |
[Florg{x: 6.283185307179586, y: 1}, 6.283185307179586, 1, 7] | |
<============================================================================ | |
>============================================================================ | |
{a:1, b:2., c:[3,4]} println | |
{a:1, b:2., c:[3, 4]} | |
test output: | |
RESULT: | |
{a: 1, b: 2., c: [3, 4]} | |
<============================================================================ | |
>============================================================================ | |
defGeneric(#foo) println | |
GF(foo) | |
test output: | |
RESULT: | |
GF(foo) | |
<============================================================================ | |
>============================================================================ | |
-- example from 'A Monotonic Superclass Linearization for Dylan' by Barrett, et al. | |
defClass(#Boat, [Scalar], {}) | |
defClass(#DayBoat, [Boat], {}) | |
defClass(#WheelBoat, [Boat], {}) | |
defClass(#Engineless, [DayBoat], {}) | |
defClass(#SmallMultihull, [DayBoat], {}) | |
defClass(#PedalWheelBoat, [Engineless, WheelBoat], {}) | |
PedalWheelBoat allSuperclasses println | |
defClass(#SmallCatamaran, [SmallMultihull], {}) | |
defClass(#Pedalo, [PedalWheelBoat, SmallCatamaran], {}) | |
Pedalo allSuperclasses println | |
[PedalWheelBoat, Engineless, DayBoat, WheelBoat, Boat, Scalar, Obj] | |
[Pedalo, PedalWheelBoat, Engineless, SmallCatamaran, SmallMultihull, DayBoat, WheelBoat, Boat, Scalar, Obj] | |
test output: | |
RESULT: | |
[ Pedalo, | |
. PedalWheelBoat, | |
. Engineless, | |
. SmallCatamaran, | |
. SmallMultihull, | |
. DayBoat, | |
. WheelBoat, | |
. Boat, | |
. Scalar, | |
. Obj] | |
<============================================================================ | |
>============================================================================ | |
-- example from 'A Monotonic Superclass Linearization for Dylan' by Barrett, et al. | |
defClass(#Pane, [Scalar], {}) | |
defClass(#ScrollingMixin, [Scalar], {}) | |
defClass(#EditingMixin, [Scalar], {}) | |
defClass(#ScrollablePane, [Pane, ScrollingMixin], {}) | |
defClass(#EditablePane, [Pane, EditingMixin], {}) | |
defClass(#EditableScrollablePane, [ScrollablePane, EditablePane], {}) | |
EditableScrollablePane allSuperclasses println | |
[EditableScrollablePane, ScrollablePane, EditablePane, Pane, ScrollingMixin, EditingMixin, Scalar, Obj] | |
test output: | |
RESULT: | |
[ EditableScrollablePane, | |
. ScrollablePane, | |
. EditablePane, | |
. Pane, | |
. ScrollingMixin, | |
. EditingMixin, | |
. Scalar, | |
. Obj] | |
<============================================================================ | |
>============================================================================ | |
{a:1, b:2}.a println | |
1 | |
test output: | |
RESULT: | |
1 | |
<============================================================================ | |
>============================================================================ | |
{a:1, b:2}.b println | |
2 | |
test output: | |
RESULT: | |
2 | |
<============================================================================ | |
>============================================================================ | |
{a:1, b:2}.c println | |
nil | |
test output: | |
RESULT: | |
nil | |
<============================================================================ | |
>============================================================================ | |
var x = {a:1, b:2}; x.c = 9; x println | |
{a:1, b:2, c:9} | |
test output: | |
RESULT: | |
{a: 1, b: 2, c: 9} | |
<============================================================================ | |
>============================================================================ | |
let a = 5; a = 6; a println | |
error: 12 Name 'a' is immutable. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
var a = 5; a = 6; a println | |
6 | |
test output: | |
RESULT: | |
6 | |
<============================================================================ | |
>============================================================================ | |
let [a,b] = 5; a println | |
error: 1 Assignment pattern match failed. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
let (a,b) = 5; a println | |
error: 1 Assignment pattern match failed. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
var a = {x:1}; a.y = 2; a println | |
{x:1, y:2} | |
test output: | |
RESULT: | |
{x: 1, y: 2} | |
<============================================================================ | |
>============================================================================ | |
var (a,b) = ({x:1},{u:4}); (a.y,b.v) = (2,5); (b,a) println | |
({u:4, v:5}, {x:1, y:2}) | |
test output: | |
RESULT: | |
({u: 4, v: 5}, {x: 1, y: 2}) | |
<============================================================================ | |
>============================================================================ | |
var [a,b] = [{x:1},{u:4}]; [a.y,b.v] = [2,5]; [b,a] println | |
[{u:4, v:5}, {x:1, y:2}] | |
test output: | |
RESULT: | |
[{u: 4, v: 5}, {x: 1, y: 2}] | |
<============================================================================ | |
>============================================================================ | |
let a = {x:1, y:2}; a println; (a.x,a.y) = (a.y,a.x); a println; | |
{x:1, y:2} | |
{x:2, y:1} | |
test output: | |
RESULT: | |
{x: 2, y: 1} | |
<============================================================================ | |
>============================================================================ | |
let a = {x:1, y:2}; a println; [a.x,a.y] = [a.y,a.x]; a println; | |
{x:1, y:2} | |
{x:2, y:1} | |
test output: | |
RESULT: | |
{x: 2, y: 1} | |
<============================================================================ | |
>============================================================================ | |
Obj.z println | |
Obj.z = 123 -- you can add properties to classes. | |
Obj.z println | |
nil | |
123 | |
test output: | |
RESULT: | |
123 | |
<============================================================================ | |
>============================================================================ | |
Record{a:1, b:2} println | |
{a:1, b:2} | |
test output: | |
RESULT: | |
{a: 1, b: 2} | |
<============================================================================ | |
>============================================================================ | |
defClass(#Point, [Scalar], {x:0.,y:0.}); Point new {x:5,y:2.1} println | |
Point{x:5, y:2.1} | |
test output: | |
RESULT: | |
Point{x: 5, y: 2.1} | |
<============================================================================ | |
>============================================================================ | |
defClass(#Point, [Scalar], {x:0.,y:0.}); let p = Point {x:5,y:2.1}; p println | |
Point{x:5, y:2.1} | |
test output: | |
RESULT: | |
Point{x: 5, y: 2.1} | |
<============================================================================ | |
>============================================================================ | |
String{x:1} println | |
error: 1 class String cannot be instantiated via apply | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
Class{x:1} println | |
error: 1 class Class cannot be instantiated via apply | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
{a:1,b:2} addAll {b:3,c:4,x:1.,y:2.,z:3.,u:4.,v:5.,w:6.} | |
test output: | |
RESULT: | |
{a: 1, b: 3, c: 4, x: 1., y: 2., z: 3., u: 4., v: 5., w: 6.} | |
<============================================================================ | |
>============================================================================ | |
let r = {a:1,b:2} addAllIfAbsent {b:3,c:4,x:1.,y:2.,z:3.,u:4.,v:5.,w:6.} | |
(r.a,r.b,r.c,r.x,r.z,r.u,r.w) println | |
r println | |
(1, 2, 4, 1., 3., 4., 6.) | |
{a:1, b:2, c:4, x:1., y:2., z:3., u:4., v:5., w:6.} | |
test output: | |
RESULT: | |
{a: 1, b: 2, c: 4, x: 1., y: 2., z: 3., u: 4., v: 5., w: 6.} | |
<============================================================================ | |
>============================================================================ | |
let r = {a:1,b:2} addAllIfPresent {b:3,c:4,x:1.,y:2.,z:3.,u:4.,v:5.,w:6.} | |
r println | |
{a:1, b:3} | |
test output: | |
RESULT: | |
{a: 1, b: 3} | |
<============================================================================ | |
>============================================================================ | |
let r = {a:1,b:2,c:7,v:8,m:9,n:11,o:12} intersect {b:3,c:4,x:1.,y:2.,z:3.,u:4.,v:5.,w:6.} | |
r println | |
{b:2, c:7, v:8} | |
test output: | |
RESULT: | |
{b: 2, c: 7, v: 8} | |
<============================================================================ | |
>============================================================================ | |
{b:3,c:4,x:1.,y:2.,z:3.,u:4.,v:5.,w:6.} keys println | |
[b, c, x, y, z, u, v, w] | |
test output: | |
RESULT: | |
[b, c, x, y, z, u, v, w] | |
<============================================================================ | |
>============================================================================ | |
{b:3,c:4,x:1.,y:2.,z:3.,u:4.,v:5.,w:6.} values println | |
[3, 4, 1., 2., 3., 4., 5., 6.] | |
test output: | |
RESULT: | |
[3, 4, 1., 2., 3., 4., 5., 6.] | |
<============================================================================ | |
>============================================================================ | |
let a = "abc" asSymbol; [a, a class] | |
test output: | |
RESULT: | |
[abc, Symbol] | |
<============================================================================ | |
>============================================================================ | |
let r = {a:1,b:2,c:7,v:8,m:9,n:11,o:12} setDifference {b:3,c:4,x:1.,y:2.,z:3.,u:4.,v:5.,w:6.} | |
r println | |
{a:1, m:9, n:11, o:12} | |
test output: | |
RESULT: | |
{a: 1, m: 9, n: 11, o: 12} | |
<============================================================================ | |
>============================================================================ | |
{1, 2, 3, 4, 5, 3, 4, 2, 1, 3, 3, 3} println | |
{5, 4, 3, 2, 1} | |
test output: | |
RESULT: | |
{5, 4, 3, 2, 1} | |
<============================================================================ | |
>============================================================================ | |
{1, 2, 3, 4, 5, 3, 4, 2, 1, 3, 3, 3} addAll {7, 7, 9, 8, 9, 9, 8, 1, 3, 3, 5} println | |
{8, 2, 5, 7, 9, 1, 4, 3} | |
test output: | |
RESULT: | |
{8, 2, 5, 7, 9, 1, 4, 3} | |
<============================================================================ | |
>============================================================================ | |
{1, 2, 3, 4, 5} intersect {4, 5, 6} println | |
{5, 4} | |
test output: | |
RESULT: | |
{5, 4} | |
<============================================================================ | |
>============================================================================ | |
{1, 2, 3, 4, 5} setDifference {4, 5, 6} println | |
{3, 2, 1} | |
test output: | |
RESULT: | |
{3, 2, 1} | |
<============================================================================ | |
>============================================================================ | |
{2, 3, 4} isSubsetOf {1, 2, 3, 4, 5, 6} println | |
true | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
{2, 7, 4} isSubsetOf {1, 2, 3, 4, 5, 6} println | |
false | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
{a:1,c:3} isSubsetOf {a:7,b:8,c:9} println | |
true | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
{a:1,c:3,z:99} isSubsetOf {a:7,b:8,c:9} println | |
false | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
{a:1,b:2,c:3} isDisjoint {x:7,y:8,z:9} println | |
true | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
{a:1,b:2,c:3} isDisjoint {x:7,y:8,b:6,z:9} println | |
false | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
-- analog bubbles, pipeline syntax | |
.4 lfsaw * 2 + [8, 7.23] lfsaw * .25 + 9.667 |> exp2 sinosc * 4c |> combn(.2,0,4) play | |
ast: | |
[ astDo, | |
. [ astCall, | |
. . play, | |
. . [ astCall, | |
. . . combn, | |
. . . [ astCall, | |
. . . . *, | |
. . . . [ astCall, | |
. . . . . sinosc, | |
. . . . . [ astCall, | |
. . . . . . exp2, | |
. . . . . . [ astCall, | |
. . . . . . . +, | |
. . . . . . . [ astCall, | |
. . . . . . . . +, | |
. . . . . . . . [astCall, *, [astCall, lfsaw, 0.4], 2], | |
. . . . . . . . [astCall, *, [astCall, lfsaw, [astList, obj, 8, 7.23]], 0.25]], | |
. . . . . . . 9.667]]], | |
. . . . 0.04], | |
. . . 0.2, | |
. . . 0, | |
. . . 4]]] | |
chunk code ----- | |
0 codePushLiteral 0 0.4 | |
1 codePushGlobalVar 1 lfsaw | |
2 codeApply 1 | |
3 codePushSmallInt 2 | |
4 codePushGlobalVar 2 * | |
5 codeApply 2 | |
6 codePushSmallInt 8 | |
7 codePushLiteral 3 7.23 | |
8 codePushArray 32 | |
9 codePushGlobalVar 1 lfsaw | |
10 codeApply 1 | |
11 codePushLiteral 4 0.25 | |
12 codePushGlobalVar 2 * | |
13 codeApply 2 | |
14 codePushGlobalVar 5 + | |
15 codeApply 2 | |
16 codePushLiteral 6 9.667 | |
17 codePushGlobalVar 5 + | |
18 codeApply 2 | |
19 codePushGlobalVar 7 exp2 | |
20 codeApply 1 | |
21 codePushGlobalVar 8 sinosc | |
22 codeApply 1 | |
23 codePushLiteral 9 0.04 | |
24 codePushGlobalVar 2 * | |
25 codeApply 2 | |
26 codePushLiteral 10 0.2 | |
27 codePushSmallInt 0 | |
28 codePushSmallInt 4 | |
29 codePushGlobalVar 11 combn | |
30 codeApply 4 | |
31 codePushGlobalVar 12 play | |
32 codeApply 1 | |
33 codeReturn | |
test output: | |
RESULT: | |
nil | |
<============================================================================ | |
>============================================================================ | |
-- analog bubbles, algebraic syntax | |
play(combn(sinosc(exp2(lfsaw(.4) * 2 + lfsaw([8, 7.23]) * .25 + 9.667)) * 4c, .2, 0, 4)) | |
ast: | |
[ astDo, | |
. [ astCall, | |
. . play, | |
. . [ astCall, | |
. . . combn, | |
. . . [ astCall, | |
. . . . *, | |
. . . . [ astCall, | |
. . . . . sinosc, | |
. . . . . [ astCall, | |
. . . . . . exp2, | |
. . . . . . [ astCall, | |
. . . . . . . +, | |
. . . . . . . [ astCall, | |
. . . . . . . . +, | |
. . . . . . . . [astCall, *, [astCall, lfsaw, 0.4], 2], | |
. . . . . . . . [astCall, *, [astCall, lfsaw, [astList, obj, 8, 7.23]], 0.25]], | |
. . . . . . . 9.667]]], | |
. . . . 0.04], | |
. . . 0.2, | |
. . . 0, | |
. . . 4]]] | |
chunk code ----- | |
0 codePushLiteral 0 0.4 | |
1 codePushGlobalVar 1 lfsaw | |
2 codeApply 1 | |
3 codePushSmallInt 2 | |
4 codePushGlobalVar 2 * | |
5 codeApply 2 | |
6 codePushSmallInt 8 | |
7 codePushLiteral 3 7.23 | |
8 codePushArray 32 | |
9 codePushGlobalVar 1 lfsaw | |
10 codeApply 1 | |
11 codePushLiteral 4 0.25 | |
12 codePushGlobalVar 2 * | |
13 codeApply 2 | |
14 codePushGlobalVar 5 + | |
15 codeApply 2 | |
16 codePushLiteral 6 9.667 | |
17 codePushGlobalVar 5 + | |
18 codeApply 2 | |
19 codePushGlobalVar 7 exp2 | |
20 codeApply 1 | |
21 codePushGlobalVar 8 sinosc | |
22 codeApply 1 | |
23 codePushLiteral 9 0.04 | |
24 codePushGlobalVar 2 * | |
25 codeApply 2 | |
26 codePushLiteral 10 0.2 | |
27 codePushSmallInt 0 | |
28 codePushSmallInt 4 | |
29 codePushGlobalVar 11 combn | |
30 codeApply 4 | |
31 codePushGlobalVar 12 play | |
32 codeApply 1 | |
33 codeReturn | |
test output: | |
RESULT: | |
nil | |
<============================================================================ | |
>============================================================================ | |
-- analog bubbles, pipeline syntax, compressed out spaces | |
.4lfsaw*2+[8,7.23]lfsaw*.25+9.667|>exp2 sinosc*4c|>combn(.2,0,4)play | |
ast: | |
[ astDo, | |
. [ astCall, | |
. . play, | |
. . [ astCall, | |
. . . combn, | |
. . . [ astCall, | |
. . . . *, | |
. . . . [ astCall, | |
. . . . . sinosc, | |
. . . . . [ astCall, | |
. . . . . . exp2, | |
. . . . . . [ astCall, | |
. . . . . . . +, | |
. . . . . . . [ astCall, | |
. . . . . . . . +, | |
. . . . . . . . [astCall, *, [astCall, lfsaw, 0.4], 2], | |
. . . . . . . . [astCall, *, [astCall, lfsaw, [astList, obj, 8, 7.23]], 0.25]], | |
. . . . . . . 9.667]]], | |
. . . . 0.04], | |
. . . 0.2, | |
. . . 0, | |
. . . 4]]] | |
chunk code ----- | |
0 codePushLiteral 0 0.4 | |
1 codePushGlobalVar 1 lfsaw | |
2 codeApply 1 | |
3 codePushSmallInt 2 | |
4 codePushGlobalVar 2 * | |
5 codeApply 2 | |
6 codePushSmallInt 8 | |
7 codePushLiteral 3 7.23 | |
8 codePushArray 32 | |
9 codePushGlobalVar 1 lfsaw | |
10 codeApply 1 | |
11 codePushLiteral 4 0.25 | |
12 codePushGlobalVar 2 * | |
13 codeApply 2 | |
14 codePushGlobalVar 5 + | |
15 codeApply 2 | |
16 codePushLiteral 6 9.667 | |
17 codePushGlobalVar 5 + | |
18 codeApply 2 | |
19 codePushGlobalVar 7 exp2 | |
20 codeApply 1 | |
21 codePushGlobalVar 8 sinosc | |
22 codeApply 1 | |
23 codePushLiteral 9 0.04 | |
24 codePushGlobalVar 2 * | |
25 codeApply 2 | |
26 codePushLiteral 10 0.2 | |
27 codePushSmallInt 0 | |
28 codePushSmallInt 4 | |
29 codePushGlobalVar 11 combn | |
30 codeApply 4 | |
31 codePushGlobalVar 12 play | |
32 codeApply 1 | |
33 codeReturn | |
test output: | |
RESULT: | |
nil | |
<============================================================================ | |
>============================================================================ | |
-- analog bubbles, algebraic syntax, compressed out spaces | |
play(combn(sinosc(exp2(lfsaw(.4)*2+lfsaw([8,7.23])*.25+9.667))*4c,.2,0,4)) | |
ast: | |
[ astDo, | |
. [ astCall, | |
. . play, | |
. . [ astCall, | |
. . . combn, | |
. . . [ astCall, | |
. . . . *, | |
. . . . [ astCall, | |
. . . . . sinosc, | |
. . . . . [ astCall, | |
. . . . . . exp2, | |
. . . . . . [ astCall, | |
. . . . . . . +, | |
. . . . . . . [ astCall, | |
. . . . . . . . +, | |
. . . . . . . . [astCall, *, [astCall, lfsaw, 0.4], 2], | |
. . . . . . . . [astCall, *, [astCall, lfsaw, [astList, obj, 8, 7.23]], 0.25]], | |
. . . . . . . 9.667]]], | |
. . . . 0.04], | |
. . . 0.2, | |
. . . 0, | |
. . . 4]]] | |
chunk code ----- | |
0 codePushLiteral 0 0.4 | |
1 codePushGlobalVar 1 lfsaw | |
2 codeApply 1 | |
3 codePushSmallInt 2 | |
4 codePushGlobalVar 2 * | |
5 codeApply 2 | |
6 codePushSmallInt 8 | |
7 codePushLiteral 3 7.23 | |
8 codePushArray 32 | |
9 codePushGlobalVar 1 lfsaw | |
10 codeApply 1 | |
11 codePushLiteral 4 0.25 | |
12 codePushGlobalVar 2 * | |
13 codeApply 2 | |
14 codePushGlobalVar 5 + | |
15 codeApply 2 | |
16 codePushLiteral 6 9.667 | |
17 codePushGlobalVar 5 + | |
18 codeApply 2 | |
19 codePushGlobalVar 7 exp2 | |
20 codeApply 1 | |
21 codePushGlobalVar 8 sinosc | |
22 codeApply 1 | |
23 codePushLiteral 9 0.04 | |
24 codePushGlobalVar 2 * | |
25 codeApply 2 | |
26 codePushLiteral 10 0.2 | |
27 codePushSmallInt 0 | |
28 codePushSmallInt 4 | |
29 codePushGlobalVar 11 combn | |
30 codeApply 4 | |
31 codePushGlobalVar 12 play | |
32 codeApply 1 | |
33 codeReturn | |
test output: | |
RESULT: | |
nil | |
<============================================================================ | |
>============================================================================ | |
-- analog bubbles, algebraic syntax, compressed out spaces | |
defClass(#UGen, [Scalar], {}) | |
defMethod(+, [UGen,UGen], \a,b[UGen{name:"+",a:a,b:b}]) | |
defMethod(+, [UGen,Obj], \a,b[UGen{name:"+",a:a,b:b}]) | |
defMethod(+, [Obj,UGen], \a,b[UGen{name:"+",a:a,b:b}]) | |
defMethod(*, [UGen,UGen], \a,b[UGen{name:"*",a:a,b:b}]) | |
defMethod(*, [UGen,Obj], \a,b[UGen{name:"*",a:a,b:b}]) | |
defMethod(*, [Obj,UGen], \a,b[UGen{name:"*",a:a,b:b}]) | |
let play = \x[UGen{name:"play",in:x}] | |
let combn = \in,delay,maxDelay,decay[UGen{name:"combn",in:in,delay:delay,maxDelay:maxDelay,decay:decay}] | |
let sinosc = \freq[UGen{name:"sinosc",freq:freq}] | |
let lfsaw = \freq[UGen{name:"lfsaw",freq:freq}] | |
let exp2 = \x[UGen{name:"exp2",x:x}] | |
play(combn(sinosc(exp2(lfsaw(.4)*2+lfsaw([8,7.23])*.25+9.667))*4c,.2,0,4)) println | |
UGen{name:play, in:UGen{name:combn, in:UGen{name:*, a:UGen{name:sinosc, freq:UGen{name:exp2, x:UGen{name:+, a:UGen{name:+, a:UGen{name:*, a:UGen{name:lfsaw, freq:0.4}, b:2}, b:UGen{name:*, a:UGen{name:lfsaw, freq:[8, 7.23]}, b:0.25}}, b:9.667}}}, b:0.04}, delay:0.2, maxDelay:0, decay:4}} | |
test output: | |
RESULT: | |
UGen{ | |
. name: play, | |
. in: UGen{ | |
. . name: combn, | |
. . in: UGen{ | |
. . . name: *, | |
. . . a: UGen{ | |
. . . . name: sinosc, | |
. . . . freq: UGen{ | |
. . . . . name: exp2, | |
. . . . . x: UGen{ | |
. . . . . . name: +, | |
. . . . . . a: UGen{ | |
. . . . . . . name: +, | |
. . . . . . . a: UGen{name: *, a: UGen{name: lfsaw, freq: 0.4}, b: 2}, | |
. . . . . . . b: UGen{name: *, a: UGen{name: lfsaw, freq: [8, 7.23]}, b: 0.25}}, | |
. . . . . . b: 9.667}}}, | |
. . . b: 0.04}, | |
. . delay: 0.2, | |
. . maxDelay: 0, | |
. . decay: 4}} | |
<============================================================================ | |
>============================================================================ | |
-- analog bubbles, algebraic syntax, compressed out spaces | |
defClass(#UGen, [Scalar], {}) | |
fn + (a UGen, b UGen) {UGen{name:"+",a:a,b:b}} | |
fn + (a UGen, b Obj ) {UGen{name:"+",a:a,b:b}} | |
fn + (a Obj, b UGen) {UGen{name:"+",a:a,b:b}} | |
fn * (a UGen, b UGen) {UGen{name:"*",a:a,b:b}} | |
fn * (a UGen, b Obj ) {UGen{name:"*",a:a,b:b}} | |
fn * (a Obj, b UGen) {UGen{name:"*",a:a,b:b}} | |
let play = \x[UGen{name:"play",in:x}] | |
let combn = \in,delay,maxDelay,decay[UGen{name:"combn",in:in,delay:delay,maxDelay:maxDelay,decay:decay}] | |
let sinosc = \freq[UGen{name:"sinosc",freq:freq}] | |
let lfsaw = \freq[UGen{name:"lfsaw",freq:freq}] | |
let exp2 = \x[UGen{name:"exp2",x:x}] | |
play(combn(sinosc(exp2(lfsaw(.4)*2+lfsaw([8,7.23])*.25+9.667))*4c,.2,0,4)) println | |
UGen{name:play, in:UGen{name:combn, in:UGen{name:*, a:UGen{name:sinosc, freq:UGen{name:exp2, x:UGen{name:+, a:UGen{name:+, a:UGen{name:*, a:UGen{name:lfsaw, freq:0.4}, b:2}, b:UGen{name:*, a:UGen{name:lfsaw, freq:[8, 7.23]}, b:0.25}}, b:9.667}}}, b:0.04}, delay:0.2, maxDelay:0, decay:4}} | |
test output: | |
RESULT: | |
UGen{ | |
. name: play, | |
. in: UGen{ | |
. . name: combn, | |
. . in: UGen{ | |
. . . name: *, | |
. . . a: UGen{ | |
. . . . name: sinosc, | |
. . . . freq: UGen{ | |
. . . . . name: exp2, | |
. . . . . x: UGen{ | |
. . . . . . name: +, | |
. . . . . . a: UGen{ | |
. . . . . . . name: +, | |
. . . . . . . a: UGen{name: *, a: UGen{name: lfsaw, freq: 0.4}, b: 2}, | |
. . . . . . . b: UGen{name: *, a: UGen{name: lfsaw, freq: [8, 7.23]}, b: 0.25}}, | |
. . . . . . b: 9.667}}}, | |
. . . b: 0.04}, | |
. . delay: 0.2, | |
. . maxDelay: 0, | |
. . decay: 4}} | |
<============================================================================ | |
>============================================================================ | |
-- analog bubbles, algebraic syntax, compressed out spaces | |
defClass(#UGen, [Scalar], {}) | |
defMethod(+, [UGen,UGen], \a,b[UGen{name:"+",ins:[a,b]}]) | |
defMethod(+, [UGen,Obj], \a,b[UGen{name:"+",ins:[a,b]}]) | |
defMethod(+, [Obj,UGen], \a,b[UGen{name:"+",ins:[a,b]}]) | |
defMethod(*, [UGen,UGen], \a,b[UGen{name:"*",ins:[a,b]}]) | |
defMethod(*, [UGen,Obj], \a,b[UGen{name:"*",ins:[a,b]}]) | |
defMethod(*, [Obj,UGen], \a,b[UGen{name:"*",ins:[a,b]}]) | |
let play = \x[UGen{name:"play",ins:[x]}] | |
let combn = \in,delay,maxDelay,decay[UGen{name:"combn",ins:[in,delay,maxDelay,decay]}] | |
let sinosc = \freq[UGen{name:"sinosc",ins:[freq]}] | |
let lfsaw = \freq[UGen{name:"lfsaw",ins:[freq]}] | |
let exp2 = \x[UGen{name:"exp2",ins:[x]}] | |
play(combn(sinosc(exp2(lfsaw(.4)*2+lfsaw([8,7.23])*.25+9.667))*4c,.2,0,4)) println | |
UGen{name:play, ins:[UGen{name:combn, ins:[UGen{name:*, ins:[UGen{name:sinosc, ins:[UGen{name:exp2, ins:[UGen{name:+, ins:[UGen{name:+, ins:[UGen{name:*, ins:[UGen{name:lfsaw, ins:[0.4]}, 2]}, UGen{name:*, ins:[UGen{name:lfsaw, ins:[[8, 7.23]]}, 0.25]}]}, 9.667]}]}]}, 0.04]}, 0.2, 0, 4]}]} | |
test output: | |
RESULT: | |
UGen{ | |
. name: play, | |
. ins: [ | |
. . UGen{ | |
. . . name: combn, | |
. . . ins: [ | |
. . . . UGen{ | |
. . . . . name: *, | |
. . . . . ins: [ | |
. . . . . . UGen{ | |
. . . . . . . name: sinosc, | |
. . . . . . . ins: [ | |
. . . . . . . . UGen{ | |
. . . . . . . . . name: exp2, | |
. . . . . . . . . ins: [ | |
. . . . . . . . . . UGen{ | |
. . . . . . . . . . . name: +, | |
. . . . . . . . . . . ins: [ | |
. . . . . . . . . . . . UGen{ | |
. . . . . . . . . . . . . name: +, | |
. . . . . . . . . . . . . ins: [ | |
. . . . . . . . . . . . . . UGen{name: *, ins: [UGen{name: lfsaw, ins: [0.4]}, 2]}, | |
. . . . . . . . . . . . . . UGen{name: *, ins: [UGen{name: lfsaw, ins: [[8, 7.23]]}, 0.25]}]}, | |
. . . . . . . . . . . . 9.667]}]}]}, | |
. . . . . . 0.04]}, | |
. . . . 0.2, | |
. . . . 0, | |
. . . . 4]}]} | |
<============================================================================ | |
>============================================================================ | |
let a=123456;let b=[a,a,a,a,a];let c=[b,b,b,b];let d=[c,c,c]; d println | |
[[[123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456]], [[123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456]], [[123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456]]] | |
test output: | |
RESULT: | |
[ [ [123456, 123456, 123456, 123456, 123456], | |
. . [123456, 123456, 123456, 123456, 123456], | |
. . [123456, 123456, 123456, 123456, 123456], | |
. . [123456, 123456, 123456, 123456, 123456]], | |
. [ [123456, 123456, 123456, 123456, 123456], | |
. . [123456, 123456, 123456, 123456, 123456], | |
. . [123456, 123456, 123456, 123456, 123456], | |
. . [123456, 123456, 123456, 123456, 123456]], | |
. [ [123456, 123456, 123456, 123456, 123456], | |
. . [123456, 123456, 123456, 123456, 123456], | |
. . [123456, 123456, 123456, 123456, 123456], | |
. . [123456, 123456, 123456, 123456, 123456]]] | |
<============================================================================ | |
>============================================================================ | |
let a=123456;let b=[a,a,a,a,a];let c=[b,b,b,b];let d=[c,c,c];let e=[d,d]; e println | |
[[[[123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456]], [[123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456]], [[123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456]]], [[[123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456]], [[123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456]], [[123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456], [123456, 123456, 123456, 123456, 123456]]⋰] | |
test output: | |
RESULT: | |
[ [ [ [123456, 123456, 123456, 123456, 123456], | |
. . . [123456, 123456, 123456, 123456, 123456], | |
. . . [123456, 123456, 123456, 123456, 123456], | |
. . . [123456, 123456, 123456, 123456, 123456]], | |
. . [ [123456, 123456, 123456, 123456, 123456], | |
. . . [123456, 123456, 123456, 123456, 123456], | |
. . . [123456, 123456, 123456, 123456, 123456], | |
. . . [123456, 123456, 123456, 123456, 123456]], | |
. . [ [123456, 123456, 123456, 123456, 123456], | |
. . . [123456, 123456, 123456, 123456, 123456], | |
. . . [123456, 123456, 123456, 123456, 123456], | |
. . . [123456, 123456, 123456, 123456, 123456]]], | |
. [ [ [123456, 123456, 123456, 123456, 123456], | |
. . . [123456, 123456, 123456, 123456, 123456], | |
. . . [123456, 123456, 123456, 123456, 123456], | |
. . . [123456, 123456, 123456, 123456, 123456]], | |
. . [ [123456, 123456, 123456, 123456, 123456], | |
. . . [123456, 123456, 123456, 123456, 123456], | |
. . . [123456, 123456, 123456, 123456, 123456], | |
. . . [123456, 123456, 123456, 123456, 123456]], | |
. . [ [123456, 123456, 123456, 123456, 123456], | |
. . . [123456, 123456, 123456, 123456, 123456], | |
. . . [123456, 123456, 123456, 123456, 123456], | |
. . . [123456, 123456, 123456, 123456, 123456]]]] | |
<============================================================================ | |
>============================================================================ | |
let z=123456;let a=[z,z,z];let b=[a,a,a,a,a];let c=[b,b,b,b];let d=[c,c,c];let e=[d,d]; e println | |
[[[[[123456, 123456, 123456], [123456, 123456, 123456], [123456, 123456, 123456], [123456, 123456, 123456], [123456, 123456, 123456]], [[123456, 123456, 123456], [123456, 123456, 123456], [123456, 123456, 123456], [123456, 123456, 123456], [123456, 123456, 123456]], [[123456, 123456, 123456], [123456, 123456, 123456], [123456, 123456, 123456], [123456, 123456, 123456], [123456, 123456, 123456]], [[123456, 123456, 123456], [123456, 123456, 123456], [123456, 123456, 123456], [123456, 123456, 123456], [123456, 123456, 123456]]], [[[123456, 123456, 123456], [123456, 123456, 123456], [123456, 123456, 123456], [123456, 123456, 123456], [123456, 123456, 123456]], [[123456, 123456, 123456], [123456, 123456, 123456], [123456, 123456, 123456], [123456, 123456, 123456], [123456, 123456, 123456]], [[123456, 123456, 123456], [123456, 123456, 123456], [123456, 123456, 123456], [123456, 123456, 123456], [123456, 123456, 123456]], [[123456, 123456, 123456], [123456, 123456, 123456], [123456, 123456, 123456], [123456, 12345⋰] | |
test output: | |
RESULT: | |
[ [ [ [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]], | |
. . . [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]], | |
. . . [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]], | |
. . . [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]]], | |
. . [ [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]], | |
. . . [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]], | |
. . . [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]], | |
. . . [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]]], | |
. . [ [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]], | |
. . . [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]], | |
. . . [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]], | |
. . . [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]]]], | |
. [ [ [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]], | |
. . . [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]], | |
. . . [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]], | |
. . . [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]]], | |
. . [ [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]], | |
. . . [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]], | |
. . . [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]], | |
. . . [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]]], | |
. . [ [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]], | |
. . . [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]], | |
. . . [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]], | |
. . . [ [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456], | |
. . . . [123456, 123456, 123456]]]]] | |
<============================================================================ | |
>============================================================================ | |
let z=123456;let a=["abc",[z,z,z]];let b=["def",[a,a,a,a]];let c=["xyz",[b,b,b,b,b]];[c,c,c] println | |
[[xyz, [[def, [[abc, [123456, 123456, 123456]], [abc, [123456, 123456, 123456]], [abc, [123456, 123456, 123456]], [abc, [123456, 123456, 123456]]]], [def, [[abc, [123456, 123456, 123456]], [abc, [123456, 123456, 123456]], [abc, [123456, 123456, 123456]], [abc, [123456, 123456, 123456]]]], [def, [[abc, [123456, 123456, 123456]], [abc, [123456, 123456, 123456]], [abc, [123456, 123456, 123456]], [abc, [123456, 123456, 123456]]]], [def, [[abc, [123456, 123456, 123456]], [abc, [123456, 123456, 123456]], [abc, [123456, 123456, 123456]], [abc, [123456, 123456, 123456]]]], [def, [[abc, [123456, 123456, 123456]], [abc, [123456, 123456, 123456]], [abc, [123456, 123456, 123456]], [abc, [123456, 123456, 123456]]]]]], [xyz, [[def, [[abc, [123456, 123456, 123456]], [abc, [123456, 123456, 123456]], [abc, [123456, 123456, 123456]], [abc, [123456, 123456, 123456]]]], [def, [[abc, [123456, 123456, 123456]], [abc, [123456, 123456, 123456]], [abc, [123456, 123456, 123456]], [abc, [123456, 123456, 123456]]]], [def, [[abc, [1234⋰] | |
test output: | |
RESULT: | |
[ [ xyz, | |
. . [ [ def, | |
. . . . [ [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]]]], | |
. . . [ def, | |
. . . . [ [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]]]], | |
. . . [ def, | |
. . . . [ [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]]]], | |
. . . [ def, | |
. . . . [ [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]]]], | |
. . . [ def, | |
. . . . [ [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]]]]]], | |
. [ xyz, | |
. . [ [ def, | |
. . . . [ [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]]]], | |
. . . [ def, | |
. . . . [ [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]]]], | |
. . . [ def, | |
. . . . [ [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]]]], | |
. . . [ def, | |
. . . . [ [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]]]], | |
. . . [ def, | |
. . . . [ [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]]]]]], | |
. [ xyz, | |
. . [ [ def, | |
. . . . [ [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]]]], | |
. . . [ def, | |
. . . . [ [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]]]], | |
. . . [ def, | |
. . . . [ [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]]]], | |
. . . [ def, | |
. . . . [ [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]]]], | |
. . . [ def, | |
. . . . [ [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]], | |
. . . . . [abc, [123456, 123456, 123456]]]]]]] | |
<============================================================================ | |
>============================================================================ | |
let z=123456;let a=["abcdefghij",[z,z,z]];let b=["defghijklmnopq",[a,a,a,a]];let c=["uvwxyz",[b,b,b,b,b]];[c,c,c] println | |
[[uvwxyz, [[defghijklmnopq, [[abcdefghij, [123456, 123456, 123456]], [abcdefghij, [123456, 123456, 123456]], [abcdefghij, [123456, 123456, 123456]], [abcdefghij, [123456, 123456, 123456]]]], [defghijklmnopq, [[abcdefghij, [123456, 123456, 123456]], [abcdefghij, [123456, 123456, 123456]], [abcdefghij, [123456, 123456, 123456]], [abcdefghij, [123456, 123456, 123456]]]], [defghijklmnopq, [[abcdefghij, [123456, 123456, 123456]], [abcdefghij, [123456, 123456, 123456]], [abcdefghij, [123456, 123456, 123456]], [abcdefghij, [123456, 123456, 123456]]]], [defghijklmnopq, [[abcdefghij, [123456, 123456, 123456]], [abcdefghij, [123456, 123456, 123456]], [abcdefghij, [123456, 123456, 123456]], [abcdefghij, [123456, 123456, 123456]]]], [defghijklmnopq, [[abcdefghij, [123456, 123456, 123456]], [abcdefghij, [123456, 123456, 123456]], [abcdefghij, [123456, 123456, 123456]], [abcdefghij, [123456, 123456, 123456]]]]]], [uvwxyz, [[defghijklmnopq, [[abcdefghij, [123456, 123456, 123456]], [abcdefghij, [123456, 123456, 123456]], [⋰] | |
test output: | |
RESULT: | |
[ [ uvwxyz, | |
. . [ [ defghijklmnopq, | |
. . . . [ [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]]]], | |
. . . [ defghijklmnopq, | |
. . . . [ [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]]]], | |
. . . [ defghijklmnopq, | |
. . . . [ [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]]]], | |
. . . [ defghijklmnopq, | |
. . . . [ [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]]]], | |
. . . [ defghijklmnopq, | |
. . . . [ [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]]]]]], | |
. [ uvwxyz, | |
. . [ [ defghijklmnopq, | |
. . . . [ [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]]]], | |
. . . [ defghijklmnopq, | |
. . . . [ [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]]]], | |
. . . [ defghijklmnopq, | |
. . . . [ [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]]]], | |
. . . [ defghijklmnopq, | |
. . . . [ [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]]]], | |
. . . [ defghijklmnopq, | |
. . . . [ [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]]]]]], | |
. [ uvwxyz, | |
. . [ [ defghijklmnopq, | |
. . . . [ [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]]]], | |
. . . [ defghijklmnopq, | |
. . . . [ [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]]]], | |
. . . [ defghijklmnopq, | |
. . . . [ [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]]]], | |
. . . [ defghijklmnopq, | |
. . . . [ [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]]]], | |
. . . [ defghijklmnopq, | |
. . . . [ [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]], | |
. . . . . [abcdefghij, [123456, 123456, 123456]]]]]]] | |
<============================================================================ | |
>============================================================================ | |
let z=123456;let y=9;let x=678;let a=["abc",[z,y,x]];let b=["def",[a,x,a,a,a]];let c=["xyz",[b,a,b,y,b,b]];[c,z,c,b,a,c] println | |
[[xyz, [[def, [[abc, [123456, 9, 678]], 678, [abc, [123456, 9, 678]], [abc, [123456, 9, 678]], [abc, [123456, 9, 678]]]], [abc, [123456, 9, 678]], [def, [[abc, [123456, 9, 678]], 678, [abc, [123456, 9, 678]], [abc, [123456, 9, 678]], [abc, [123456, 9, 678]]]], 9, [def, [[abc, [123456, 9, 678]], 678, [abc, [123456, 9, 678]], [abc, [123456, 9, 678]], [abc, [123456, 9, 678]]]], [def, [[abc, [123456, 9, 678]], 678, [abc, [123456, 9, 678]], [abc, [123456, 9, 678]], [abc, [123456, 9, 678]]]]]], 123456, [xyz, [[def, [[abc, [123456, 9, 678]], 678, [abc, [123456, 9, 678]], [abc, [123456, 9, 678]], [abc, [123456, 9, 678]]]], [abc, [123456, 9, 678]], [def, [[abc, [123456, 9, 678]], 678, [abc, [123456, 9, 678]], [abc, [123456, 9, 678]], [abc, [123456, 9, 678]]]], 9, [def, [[abc, [123456, 9, 678]], 678, [abc, [123456, 9, 678]], [abc, [123456, 9, 678]], [abc, [123456, 9, 678]]]], [def, [[abc, [123456, 9, 678]], 678, [abc, [123456, 9, 678]], [abc, [123456, 9, 678]], [abc, [123456, 9, 678]]]]]], [def, [[abc, [123456, 9, 67⋰] | |
test output: | |
RESULT: | |
[ [ xyz, | |
. . [ [ def, | |
. . . . [ [abc, [123456, 9, 678]], | |
. . . . . 678, | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]]]], | |
. . . [abc, [123456, 9, 678]], | |
. . . [ def, | |
. . . . [ [abc, [123456, 9, 678]], | |
. . . . . 678, | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]]]], | |
. . . 9, | |
. . . [ def, | |
. . . . [ [abc, [123456, 9, 678]], | |
. . . . . 678, | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]]]], | |
. . . [ def, | |
. . . . [ [abc, [123456, 9, 678]], | |
. . . . . 678, | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]]]]]], | |
. 123456, | |
. [ xyz, | |
. . [ [ def, | |
. . . . [ [abc, [123456, 9, 678]], | |
. . . . . 678, | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]]]], | |
. . . [abc, [123456, 9, 678]], | |
. . . [ def, | |
. . . . [ [abc, [123456, 9, 678]], | |
. . . . . 678, | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]]]], | |
. . . 9, | |
. . . [ def, | |
. . . . [ [abc, [123456, 9, 678]], | |
. . . . . 678, | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]]]], | |
. . . [ def, | |
. . . . [ [abc, [123456, 9, 678]], | |
. . . . . 678, | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]]]]]], | |
. [ def, | |
. . [ [abc, [123456, 9, 678]], | |
. . . 678, | |
. . . [abc, [123456, 9, 678]], | |
. . . [abc, [123456, 9, 678]], | |
. . . [abc, [123456, 9, 678]]]], | |
. [abc, [123456, 9, 678]], | |
. [ xyz, | |
. . [ [ def, | |
. . . . [ [abc, [123456, 9, 678]], | |
. . . . . 678, | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]]]], | |
. . . [abc, [123456, 9, 678]], | |
. . . [ def, | |
. . . . [ [abc, [123456, 9, 678]], | |
. . . . . 678, | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]]]], | |
. . . 9, | |
. . . [ def, | |
. . . . [ [abc, [123456, 9, 678]], | |
. . . . . 678, | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]]]], | |
. . . [ def, | |
. . . . [ [abc, [123456, 9, 678]], | |
. . . . . 678, | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]], | |
. . . . . [abc, [123456, 9, 678]]]]]]] | |
<============================================================================ | |
>============================================================================ | |
let a={a:1,b:2,c:3};let b={d:a,e:a,f:a};let c={x:b,y:a,z:b};let d={u:c,v:b,w:a}; (d,d) println | |
({u:{x:{d:{a:1, b:2, c:3}, e:{a:1, b:2, c:3}, f:{a:1, b:2, c:3}}, y:{a:1, b:2, c:3}, z:{d:{a:1, b:2, c:3}, e:{a:1, b:2, c:3}, f:{a:1, b:2, c:3}}}, v:{d:{a:1, b:2, c:3}, e:{a:1, b:2, c:3}, f:{a:1, b:2, c:3}}, w:{a:1, b:2, c:3}}, {u:{x:{d:{a:1, b:2, c:3}, e:{a:1, b:2, c:3}, f:{a:1, b:2, c:3}}, y:{a:1, b:2, c:3}, z:{d:{a:1, b:2, c:3}, e:{a:1, b:2, c:3}, f:{a:1, b:2, c:3}}}, v:{d:{a:1, b:2, c:3}, e:{a:1, b:2, c:3}, f:{a:1, b:2, c:3}}, w:{a:1, b:2, c:3}}) | |
test output: | |
RESULT: | |
( { u: { x: {d: {a: 1, b: 2, c: 3}, e: {a: 1, b: 2, c: 3}, f: {a: 1, b: 2, c: 3}}, | |
. . . y: {a: 1, b: 2, c: 3}, | |
. . . z: {d: {a: 1, b: 2, c: 3}, e: {a: 1, b: 2, c: 3}, f: {a: 1, b: 2, c: 3}}}, | |
. . v: {d: {a: 1, b: 2, c: 3}, e: {a: 1, b: 2, c: 3}, f: {a: 1, b: 2, c: 3}}, | |
. . w: {a: 1, b: 2, c: 3}}, | |
. { u: { x: {d: {a: 1, b: 2, c: 3}, e: {a: 1, b: 2, c: 3}, f: {a: 1, b: 2, c: 3}}, | |
. . . y: {a: 1, b: 2, c: 3}, | |
. . . z: {d: {a: 1, b: 2, c: 3}, e: {a: 1, b: 2, c: 3}, f: {a: 1, b: 2, c: 3}}}, | |
. . v: {d: {a: 1, b: 2, c: 3}, e: {a: 1, b: 2, c: 3}, f: {a: 1, b: 2, c: 3}}, | |
. . w: {a: 1, b: 2, c: 3}}) | |
<============================================================================ | |
>============================================================================ | |
defClass(#Cuvwxyz,[Scalar],{});let p=Cuvwxyz;let a=p{a:1,b:2,c:3};let b=p{d:a,e:a,f:a};let c=p{x:b,y:a,z:b};let d=p{u:c,v:b,w:a}; (d,d) println | |
(Cuvwxyz{u:Cuvwxyz{x:Cuvwxyz{d:Cuvwxyz{a:1, b:2, c:3}, e:Cuvwxyz{a:1, b:2, c:3}, f:Cuvwxyz{a:1, b:2, c:3}}, y:Cuvwxyz{a:1, b:2, c:3}, z:Cuvwxyz{d:Cuvwxyz{a:1, b:2, c:3}, e:Cuvwxyz{a:1, b:2, c:3}, f:Cuvwxyz{a:1, b:2, c:3}}}, v:Cuvwxyz{d:Cuvwxyz{a:1, b:2, c:3}, e:Cuvwxyz{a:1, b:2, c:3}, f:Cuvwxyz{a:1, b:2, c:3}}, w:Cuvwxyz{a:1, b:2, c:3}}, Cuvwxyz{u:Cuvwxyz{x:Cuvwxyz{d:Cuvwxyz{a:1, b:2, c:3}, e:Cuvwxyz{a:1, b:2, c:3}, f:Cuvwxyz{a:1, b:2, c:3}}, y:Cuvwxyz{a:1, b:2, c:3}, z:Cuvwxyz{d:Cuvwxyz{a:1, b:2, c:3}, e:Cuvwxyz{a:1, b:2, c:3}, f:Cuvwxyz{a:1, b:2, c:3}}}, v:Cuvwxyz{d:Cuvwxyz{a:1, b:2, c:3}, e:Cuvwxyz{a:1, b:2, c:3}, f:Cuvwxyz{a:1, b:2, c:3}}, w:Cuvwxyz{a:1, b:2, c:3}}) | |
test output: | |
RESULT: | |
( Cuvwxyz{ | |
. . u: Cuvwxyz{ | |
. . . x: Cuvwxyz{ | |
. . . . d: Cuvwxyz{a: 1, b: 2, c: 3}, | |
. . . . e: Cuvwxyz{a: 1, b: 2, c: 3}, | |
. . . . f: Cuvwxyz{a: 1, b: 2, c: 3}}, | |
. . . y: Cuvwxyz{a: 1, b: 2, c: 3}, | |
. . . z: Cuvwxyz{ | |
. . . . d: Cuvwxyz{a: 1, b: 2, c: 3}, | |
. . . . e: Cuvwxyz{a: 1, b: 2, c: 3}, | |
. . . . f: Cuvwxyz{a: 1, b: 2, c: 3}}}, | |
. . v: Cuvwxyz{ | |
. . . d: Cuvwxyz{a: 1, b: 2, c: 3}, | |
. . . e: Cuvwxyz{a: 1, b: 2, c: 3}, | |
. . . f: Cuvwxyz{a: 1, b: 2, c: 3}}, | |
. . w: Cuvwxyz{a: 1, b: 2, c: 3}}, | |
. Cuvwxyz{ | |
. . u: Cuvwxyz{ | |
. . . x: Cuvwxyz{ | |
. . . . d: Cuvwxyz{a: 1, b: 2, c: 3}, | |
. . . . e: Cuvwxyz{a: 1, b: 2, c: 3}, | |
. . . . f: Cuvwxyz{a: 1, b: 2, c: 3}}, | |
. . . y: Cuvwxyz{a: 1, b: 2, c: 3}, | |
. . . z: Cuvwxyz{ | |
. . . . d: Cuvwxyz{a: 1, b: 2, c: 3}, | |
. . . . e: Cuvwxyz{a: 1, b: 2, c: 3}, | |
. . . . f: Cuvwxyz{a: 1, b: 2, c: 3}}}, | |
. . v: Cuvwxyz{ | |
. . . d: Cuvwxyz{a: 1, b: 2, c: 3}, | |
. . . e: Cuvwxyz{a: 1, b: 2, c: 3}, | |
. . . f: Cuvwxyz{a: 1, b: 2, c: 3}}, | |
. . w: Cuvwxyz{a: 1, b: 2, c: 3}}) | |
<============================================================================ | |
>============================================================================ | |
let a={a:1,abc:2,abcdef:3};let b={uvwxyz:a,wxyz:(a,a),xy:[a,[a,[a,a],a],a]};let c={mnopq:b,opq:a,p:a}; [c] println | |
[{mnopq:{uvwxyz:{a:1, abc:2, abcdef:3}, wxyz:({a:1, abc:2, abcdef:3}, {a:1, abc:2, abcdef:3}), xy:[{a:1, abc:2, abcdef:3}, [{a:1, abc:2, abcdef:3}, [{a:1, abc:2, abcdef:3}, {a:1, abc:2, abcdef:3}], {a:1, abc:2, abcdef:3}], {a:1, abc:2, abcdef:3}]}, opq:{a:1, abc:2, abcdef:3}, p:{a:1, abc:2, abcdef:3}}] | |
test output: | |
RESULT: | |
[ { mnopq: { | |
. . . uvwxyz: {a: 1, abc: 2, abcdef: 3}, | |
. . . wxyz: ({a: 1, abc: 2, abcdef: 3}, {a: 1, abc: 2, abcdef: 3}), | |
. . . xy: [ | |
. . . . {a: 1, abc: 2, abcdef: 3}, | |
. . . . [ {a: 1, abc: 2, abcdef: 3}, | |
. . . . . [{a: 1, abc: 2, abcdef: 3}, {a: 1, abc: 2, abcdef: 3}], | |
. . . . . {a: 1, abc: 2, abcdef: 3}], | |
. . . . {a: 1, abc: 2, abcdef: 3}]}, | |
. . opq: {a: 1, abc: 2, abcdef: 3}, | |
. . p: {a: 1, abc: 2, abcdef: 3}}] | |
<============================================================================ | |
>============================================================================ | |
var x={a:1,b:2,c:3};x.c = x; x | |
test output: | |
RESULT: | |
{a: 1, b: 2, c: { ⟘^1 }} | |
<============================================================================ | |
>============================================================================ | |
var x={a:1,b:2};var y={c:x,d:x};var z={e:y,f:y};x.a = z; z.f = z;y.d=z; z | |
test output: | |
RESULT: | |
{e: {c: {a: { ⟘^3 }, b: 2}, d: { ⟘^2 }}, f: { ⟘^1 }} | |
<============================================================================ | |
>============================================================================ | |
defClass(#Cuvwxyz,[Scalar],{});let p=Cuvwxyz;let a=p{a:1,b:2,c:3};let b=p{d:a,e:a,f:a};let c=p{x:b,y:a,z:b};let d=p{u:c,v:b,w:a};a.b=a; [d,d] prettyPrint | |
[ Cuvwxyz{ | |
. . u: Cuvwxyz{ | |
. . . x: Cuvwxyz{ | |
. . . . d: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . . e: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . . f: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}}, | |
. . . y: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . z: Cuvwxyz{ | |
. . . . d: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . . e: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . . f: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}}}, | |
. . v: Cuvwxyz{ | |
. . . d: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . e: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . f: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}}, | |
. . w: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}}, | |
. Cuvwxyz{ | |
. . u: Cuvwxyz{ | |
. . . x: Cuvwxyz{ | |
. . . . d: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . . e: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . . f: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}}, | |
. . . y: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . z: Cuvwxyz{ | |
. . . . d: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . . e: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . . f: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}}}, | |
. . v: Cuvwxyz{ | |
. . . d: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . e: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . f: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}}, | |
. . w: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}}] | |
test output: | |
RESULT: | |
[ Cuvwxyz{ | |
. . u: Cuvwxyz{ | |
. . . x: Cuvwxyz{ | |
. . . . d: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . . e: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . . f: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}}, | |
. . . y: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . z: Cuvwxyz{ | |
. . . . d: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . . e: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . . f: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}}}, | |
. . v: Cuvwxyz{ | |
. . . d: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . e: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . f: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}}, | |
. . w: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}}, | |
. Cuvwxyz{ | |
. . u: Cuvwxyz{ | |
. . . x: Cuvwxyz{ | |
. . . . d: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . . e: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . . f: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}}, | |
. . . y: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . z: Cuvwxyz{ | |
. . . . d: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . . e: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . . f: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}}}, | |
. . v: Cuvwxyz{ | |
. . . d: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . e: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}, | |
. . . f: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}}, | |
. . w: Cuvwxyz{a: 1, b: Cuvwxyz{ ⟘^1 }, c: 3}}] | |
<============================================================================ | |
>============================================================================ | |
\a,b[(a,b)](5,6) println | |
(5, 6) | |
test output: | |
RESULT: | |
(5, 6) | |
<============================================================================ | |
>============================================================================ | |
\a,b(1)[(a,b)](5) println | |
(5, 1) | |
test output: | |
RESULT: | |
(5, 1) | |
<============================================================================ | |
>============================================================================ | |
\a,b(2),c(a+b)[(a,b,c)](5) println | |
(5, 2, 7) | |
test output: | |
RESULT: | |
(5, 2, 7) | |
<============================================================================ | |
>============================================================================ | |
\a,b(2),c(a+b),d(4+c)[(a,b,c,d)](5) println | |
(5, 2, 7, 11) | |
test output: | |
RESULT: | |
(5, 2, 7, 11) | |
<============================================================================ | |
>============================================================================ | |
\a,b(2),c(a+b),d(4+c)[(a,b,c,d)](5,4) println | |
(5, 4, 9, 13) | |
test output: | |
RESULT: | |
(5, 4, 9, 13) | |
<============================================================================ | |
>============================================================================ | |
\a,b(2),c(a+b),d(4+c)[(a,b,c,d)](5,4,3) println | |
(5, 4, 3, 7) | |
test output: | |
RESULT: | |
(5, 4, 3, 7) | |
<============================================================================ | |
>============================================================================ | |
\a,b(2),c(a+b),d(4+c)[(a,b,c,d)](5,4,3,2) println | |
(5, 4, 3, 2) | |
test output: | |
RESULT: | |
(5, 4, 3, 2) | |
<============================================================================ | |
>============================================================================ | |
\a,b(2),c(a+b),d(4+c)[(a,b,c,d)]() println | |
error: 7 too few arguments. 1 arguments are required. 0 were passed. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
\a,b(2),c,d[(a,b,c,d)](4) println | |
(4, 2, nil, nil) | |
test output: | |
RESULT: | |
(4, 2, nil, nil) | |
<============================================================================ | |
>============================================================================ | |
\a,b(2),c,d(5)[(a,b,c,d)](4) println | |
(4, 2, nil, 5) | |
test output: | |
RESULT: | |
(4, 2, nil, 5) | |
<============================================================================ | |
>============================================================================ | |
let z = 7; let f = \a,b(2),c(a+z),d(c+5)[(a,b,c,d)]; f(4) println | |
(4, 2, 11, 16) | |
test output: | |
RESULT: | |
(4, 2, 11, 16) | |
<============================================================================ | |
>============================================================================ | |
defGeneric(#foo) | |
defMethod(foo, [Int], \a,b[[b,a]]) | |
defMethod(foo, [Float], \a,b[[a,b,b,a]]) | |
foo(3,#x) println | |
foo(5.,#y) println | |
[x, 3] | |
[5., y, y, 5.] | |
test output: | |
RESULT: | |
[5., y, y, 5.] | |
<============================================================================ | |
>============================================================================ | |
defGeneric(#foo) | |
defMethod(foo, [Int], \a,b[[b,a]]) | |
defMethod(foo, [Float], \a,b[[a,b,b,a]]) | |
foo(3,#x) println | |
foo(5.,#y) println | |
[x, 3] | |
[5., y, y, 5.] | |
test output: | |
RESULT: | |
[5., y, y, 5.] | |
<============================================================================ | |
>============================================================================ | |
defGeneric(#foo) | |
defMethod(foo, [Int], \a,b[[b,a]]) | |
test output: | |
RESULT: | |
<Method> | |
<============================================================================ | |
>============================================================================ | |
defGeneric(#foo) | |
defMethod(foo, [Int, Int], \a,b[[b,a]]) | |
foo(5,6) println | |
[6, 5] | |
test output: | |
RESULT: | |
[6, 5] | |
<============================================================================ | |
>============================================================================ | |
defGeneric(#foo) | |
defMethod(foo, [Int, Int, Int], \a,b[[b,a]]) | |
foo(5,6) println | |
error: 6 The number of argument types is more than the max arguments to the function. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
defGeneric(#foo) | |
defMethod(foo, [Int, Int, Int], \a,b,c[[c,b,a]]) | |
foo(5,6,7,8) println | |
CALL FRAMES SIZE 1 BASE 1 | |
0 ? lm 0x0 pc 0x0 sb 0 ssz 0 istry 0 ksz XXX | |
-> ? lm 0x128664820 pc 0x12961208c sb 0 ssz 4 ksz 6 | |
num args: 4 | |
0 I64 | |
1 I64 | |
2 I64 | |
3 I64 | |
error: 3 No applicable method found for function 'foo'. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
defGeneric(#foo) | |
defMethod(foo, [Int, Int, Int], \a,b,c[[c,b,a]]) | |
foo(5,6) println | |
CALL FRAMES SIZE 1 BASE 1 | |
0 ? lm 0x0 pc 0x0 sb 0 ssz 0 istry 0 ksz XXX | |
-> ? lm 0x128663ca0 pc 0x129614604 sb 0 ssz 2 ksz 6 | |
num args: 2 | |
0 I64 | |
1 I64 | |
error: 3 No applicable method found for function 'foo'. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
defGeneric(#foo) | |
defMethod(foo, [Int, Int], \a,b,c(9)[[c,b,a]]) | |
foo(5,6) println | |
[9, 6, 5] | |
test output: | |
RESULT: | |
[9, 6, 5] | |
<============================================================================ | |
>============================================================================ | |
defGeneric(#foo) | |
defMethod(foo, [Int, Int], \a,b,c(9)[[c,b,a]]) | |
foo(5,6,7) println | |
[7, 6, 5] | |
test output: | |
RESULT: | |
[7, 6, 5] | |
<============================================================================ | |
>============================================================================ | |
defGeneric(#foo) | |
defMethod(foo, [Int, Int], \a,b,c(9)[[c,b,a]]) | |
foo(5,6,7,8) println | |
CALL FRAMES SIZE 1 BASE 1 | |
0 ? lm 0x0 pc 0x0 sb 0 ssz 0 istry 0 ksz XXX | |
-> ? lm 0x128665520 pc 0x129620f08 sb 0 ssz 4 ksz 6 | |
num args: 4 | |
0 I64 | |
1 I64 | |
2 I64 | |
3 I64 | |
error: 3 No applicable method found for function 'foo'. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
defGeneric(#foo) | |
defMethod(foo, [Int, Int], \a,b,c(9)[[c,b,a]]) | |
foo(5) println | |
CALL FRAMES SIZE 1 BASE 1 | |
0 ? lm 0x0 pc 0x0 sb 0 ssz 0 istry 0 ksz XXX | |
-> ? lm 0x1286687a0 pc 0x12962353c sb 0 ssz 1 ksz 6 | |
num args: 1 | |
0 I64 | |
error: 3 No applicable method found for function 'foo'. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
defGeneric(#foo) | |
defMethod(foo, [Int, Int], \a,b,c(9)[[c,b,a]]) | |
foo() println | |
CALL FRAMES SIZE 1 BASE 1 | |
0 ? lm 0x0 pc 0x0 sb 0 ssz 0 istry 0 ksz XXX | |
-> ? lm 0x128667ca0 pc 0x12962b938 sb 0 ssz 0 ksz 6 | |
num args: 0 | |
error: 3 No applicable method found for function 'foo'. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
let x = #+; [x, x typeName] println | |
[+, Symbol] | |
test output: | |
RESULT: | |
[+, Symbol] | |
<============================================================================ | |
>============================================================================ | |
let x = true; \x[ x ? 3 : 4 ] (x) println | |
3 | |
test output: | |
RESULT: | |
3 | |
<============================================================================ | |
>============================================================================ | |
let x = false; \x[ x ? 3 : 4 ] (x) println | |
4 | |
test output: | |
RESULT: | |
4 | |
<============================================================================ | |
>============================================================================ | |
var i = 0; while (i < 4) { i println; i = i + 1 }; #done println | |
0 | |
1 | |
2 | |
3 | |
done | |
test output: | |
RESULT: | |
done | |
<============================================================================ | |
>============================================================================ | |
var i = 0; while (i < 40) { i print; i = i + 1 }; #done println | |
0123456789101112131415161718192021222324252627282930313233343536373839done | |
test output: | |
RESULT: | |
done | |
<============================================================================ | |
>============================================================================ | |
var i = 0; while (i < 4) { let z = i+i; z println; i = i + 1 }; z println | |
0 | |
2 | |
4 | |
6 | |
error: 3 Undefined global variable 'z' | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
var i = 0; let z = 7; while (i < 4) { let z = i+i; z println; i = i + 1 }; z println | |
0 | |
2 | |
4 | |
6 | |
7 | |
test output: | |
RESULT: | |
7 | |
<============================================================================ | |
>============================================================================ | |
var f = nil; var i = 0; let z = 7; while (i < 20) { let z = i+i; f =\[[i,z]]; i = i + 1 }; [z, f()] println; | |
[7, [20, 38]] | |
test output: | |
RESULT: | |
[7, [20, 38]] | |
<============================================================================ | |
>============================================================================ | |
var f = nil; let z = 7; do { var z = 3; f = \[z]; z } println; [z, f()] println; | |
3 | |
[7, 3] | |
test output: | |
RESULT: | |
[7, 3] | |
<============================================================================ | |
>============================================================================ | |
var f = nil; let z = 7; do { var z = 3; f = \[z]; z = 4; z = z + 1 } println; [z, f()] println; | |
5 | |
[7, 5] | |
test output: | |
RESULT: | |
[7, 5] | |
<============================================================================ | |
>============================================================================ | |
var f = nil; let z = 7; do { var z = 3; let x = z; f = \[[x,z]]; z = 4; z = z + 1 } println; [z, f()] println; | |
5 | |
[7, [3, 5]] | |
test output: | |
RESULT: | |
[7, [3, 5]] | |
<============================================================================ | |
>============================================================================ | |
var f = nil; let z = 7; do { var z = 3; do { let x = z+z; f = \[[x,z]]; z = 4; }; z = z + 1 } println; [z, f()] println; | |
5 | |
[7, [6, 5]] | |
test output: | |
RESULT: | |
[7, [6, 5]] | |
<============================================================================ | |
>============================================================================ | |
true && do { #didit println; true } | |
didit | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
true && do { #didit println; false } | |
didit | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
false && do { #didit println; true } | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
false && do { #didit println; false } | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
true || do { #didit println; true } | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
true || do { #didit println; false } | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
false || do { #didit println; true } | |
didit | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
false || do { #didit println; false } | |
didit | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
let tri = \n[ n < 2 ? 1 : n + tri(n-1) ]; tri(4) println | |
10 | |
test output: | |
RESULT: | |
10 | |
<============================================================================ | |
>============================================================================ | |
tri(4) println | |
error: 3 Undefined global variable 'tri' | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
let tri = \n[ n < 2 ? 1 : n + tri(n-1) ]; tri(0) println | |
1 | |
test output: | |
RESULT: | |
1 | |
<============================================================================ | |
>============================================================================ | |
let tri = \n[ n < 2 ? 1 : n + tri(n-1) ]; tri(4) println | |
10 | |
test output: | |
RESULT: | |
10 | |
<============================================================================ | |
>============================================================================ | |
let tri = \n[ n < 2 ? 1 : n + tri(n-1) ]; tri(19) println | |
190 | |
test output: | |
RESULT: | |
190 | |
<============================================================================ | |
>============================================================================ | |
let tri = \n[ n < 2 ? 1 : n + tri(n-1) ]; tri(20) println | |
210 | |
test output: | |
RESULT: | |
210 | |
<============================================================================ | |
>============================================================================ | |
1 === 1 | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
1 === 2 | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
#hat === #hat | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
#hat === #pig | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
[1] === [1] | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
1 !== 1 | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
1 !== 2 | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
#hat !== #hat | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
#hat !== #pig | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
[1] !== [1] | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
1 == 1 | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
1 == 2 | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
#hat == #hat | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
#hat == #pig | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
[1,2,3] == [1,2,3] | |
test output: | |
RESULT: | |
[true, true, true] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3] == [1,2.,3] | |
test output: | |
RESULT: | |
[true, true, true] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3] == [1,2.1,3] | |
test output: | |
RESULT: | |
[true, false, true] | |
<============================================================================ | |
>============================================================================ | |
complex(2,3) == complex(2,3) | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
rational(2,3) == rational(2,3) | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
1 != 1 | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
1 != 2 | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
#hat != #hat | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
#hat != #pig | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
[1,2,3] != [1,2,3] | |
test output: | |
RESULT: | |
[false, false, false] | |
<============================================================================ | |
>============================================================================ | |
complex(2,3) != complex(2,3) | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
rational(2,3) != rational(2,3) | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
[1, #hat, [2, 3]] == [1, #hat, [2, 3]] | |
test output: | |
RESULT: | |
[true, true, [true, true]] | |
<============================================================================ | |
>============================================================================ | |
[1, #hat, [2, 3]] == [1, #pig, [5, 3]] | |
test output: | |
RESULT: | |
[true, false, [false, true]] | |
<============================================================================ | |
>============================================================================ | |
[1, #hat, [2, 3]] == [1, #pig, 7] | |
test output: | |
RESULT: | |
[true, false, [false, false]] | |
<============================================================================ | |
>============================================================================ | |
[1, #pig, 3] == [1, #hat, [2, 3]] | |
test output: | |
RESULT: | |
[true, false, [false, true]] | |
<============================================================================ | |
>============================================================================ | |
[1, #pig, [3]] == [1, #hat, [2, 3]] | |
test output: | |
RESULT: | |
[true, false, [false]] | |
<============================================================================ | |
>============================================================================ | |
#i32[1, 2, 3] == #i32[1, 2, 3] | |
test output: | |
RESULT: | |
#i32[1, 1, 1] | |
<============================================================================ | |
>============================================================================ | |
[1, 2, 3] == #i32[1, 2, 3] | |
test output: | |
RESULT: | |
[#i32[1, 0, 0], #i32[0, 1, 0], #i32[0, 0, 1]] | |
<============================================================================ | |
>============================================================================ | |
[[1, 2, 3]] == [#i32[1, 2, 3]] | |
test output: | |
RESULT: | |
[[#i32[1, 0, 0], #i32[0, 1, 0], #i32[0, 0, 1]]] | |
<============================================================================ | |
>============================================================================ | |
[1, #hat, [2, 3]] ==` [1, #hat, [2, 3]] | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
[1, #hat, [2, 3]] ==` [1, #pig, [5, 3]] | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
[1, 2, 3] ==` #i32[1, 2, 3] | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
[[1, 2, 3]] ==` [#i32[1, 2, 3]] | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
{a:1,b:2} == {a:1,b:2} | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
let x = {a:1,b:2}; x.a = x; x == {a:x,b:2} | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
let x = {a:1,b:2}; x.a = x; x == {a:x,b:3} | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
let x = {a:1,b:2}; x.a = x; let y = {a:{a:x,b:2},b:2}; [x,y] println; x == y | |
[{a:{ ⟘^1 }, b:2}, {a:{a:{a:{ ⟘^1 }, b:2}, b:2}, b:2}] | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
let x = {a:1,b:2}; x.a = x; let y = {a:1,b:2}; let z = {a:{a:y,b:2},b:2}; y.a = z; [x,z] println; x == z | |
[{a:{ ⟘^1 }, b:2}, {a:{a:{a:{ ⟘^3 }, b:2}, b:2}, b:2}] | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
2 == 2. | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
let x = [1]; [x pointer hexstr, x idhash hexstr] println | |
[0x12ee42aa0, 0x6cf1df6c8e5a8a95] | |
test output: | |
RESULT: | |
[0x12ee42aa0, 0x6cf1df6c8e5a8a95] | |
<============================================================================ | |
>============================================================================ | |
let x = [2]; [x pointer hexstr, x idhash hexstr] println | |
[0x12ee6b360, 0xe27d7c42b1ba65ba] | |
test output: | |
RESULT: | |
[0x12ee6b360, 0xe27d7c42b1ba65ba] | |
<============================================================================ | |
>============================================================================ | |
let x = {a:1,b:2,c:5}; [x pointer hexstr, x idhash hexstr] println | |
[0x12869ba20, 0xf84dfd357d467e1c] | |
test output: | |
RESULT: | |
[0x12869ba20, 0xf84dfd357d467e1c] | |
<============================================================================ | |
>============================================================================ | |
let x = {a:1,b:2,c:4}; [x pointer hexstr, x idhash hexstr] println | |
[0x12869eba0, 0xf739791594b117f8] | |
test output: | |
RESULT: | |
[0x12869eba0, 0xf739791594b117f8] | |
<============================================================================ | |
>============================================================================ | |
let x = {a:1,b:2,c:3}; [x pointer hexstr, x idhash hexstr] println | |
[0x12869df20, 0xcd8125cb1566cd5d] | |
test output: | |
RESULT: | |
[0x12869df20, 0xcd8125cb1566cd5d] | |
<============================================================================ | |
>============================================================================ | |
36028797018963970 == 36028797018963970.0 | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
36028797018963971 == 36028797018963970.0 | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
let x = {a:1,b:2}; x.a = x | |
let y = {a:1,b:2} | |
let z = {a:{a:y,b:2},b:2}; y.a = z | |
[x,z] println | |
[x eqhash hexstr, z eqhash hexstr] println | |
x == z |> println | |
[{a:{ ⟘^1 }, b:2}, {a:{a:{a:{ ⟘^3 }, b:2}, b:2}, b:2}] | |
[0xbd084c11476482cf, 0xbd084c11476482cf] | |
true | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
let x = {a:1,b:2}; x.a = x | |
let y = {a:1,b:2}; y.a = y | |
[x eqhash hexstr, y eqhash hexstr] println | |
x == y |> println; x println; y println | |
[0xbd084c11476482cf, 0xbd084c11476482cf] | |
true | |
{a:{ ⟘^1 }, b:2} | |
{a:{ ⟘^1 }, b:2} | |
test output: | |
RESULT: | |
{a: { ⟘^1 }, b: 2} | |
<============================================================================ | |
>============================================================================ | |
let a = {3,5,2,3,5,1,2,1,4,3} | |
let b = {1,2,3,4,5} | |
[a, b, a eqhash hexstr, b eqhash hexstr, a == b] println | |
[{1, 2, 5, 4, 3}, {5, 4, 3, 2, 1}, 0xb3c1421ec649747e, 0xb3c1421ec649747e, true] | |
test output: | |
RESULT: | |
[ {1, 2, 5, 4, 3}, | |
. {5, 4, 3, 2, 1}, | |
. 0xb3c1421ec649747e, | |
. 0xb3c1421ec649747e, | |
. true] | |
<============================================================================ | |
>============================================================================ | |
let a = {a:1, b:2, c:3, d:4} | |
let b = {d:4, b:2, a:1, c:3} | |
[a, b, a eqhash hexstr, b eqhash hexstr, a == b] println | |
[{a:1, b:2, c:3, d:4}, {d:4, b:2, a:1, c:3}, 0x910dc51cf187f0e8, 0x910dc51cf187f0e8, true] | |
test output: | |
RESULT: | |
[ {a: 1, b: 2, c: 3, d: 4}, | |
. {d: 4, b: 2, a: 1, c: 3}, | |
. 0x910dc51cf187f0e8, | |
. 0x910dc51cf187f0e8, | |
. true] | |
<============================================================================ | |
>============================================================================ | |
complex(1.,2.) * complex(3.,4.) println | |
x64(3., 4.) | |
test output: | |
RESULT: | |
x64(-5., 10.) | |
<============================================================================ | |
>============================================================================ | |
[3 min 7, 3 max 7, 3. min 7, 3. max 7, 3 min 7., 3 max 7., 3. min 7., 3. max 7.] println | |
[3, 7, 3., 7., 3., 7., 3., 7.] | |
test output: | |
RESULT: | |
[3, 7, 3., 7., 3., 7., 3., 7.] | |
<============================================================================ | |
>============================================================================ | |
[3 < 7, 3 > 7, 3. < 7, 3. > 7, 3 < 7., 3 > 7., 3. < 7., 3. > 7.] println | |
[true, false, true, false, true, false, true, false] | |
test output: | |
RESULT: | |
[true, false, true, false, true, false, true, false] | |
<============================================================================ | |
>============================================================================ | |
[1 << 8, 65535 >> 3, -1 >> 43 |> hexstr, -1 >>> 43 |> hexstr] println | |
[256, 8191, 0xffffffffffffffff, 0x1fffff] | |
test output: | |
RESULT: | |
[256, 8191, 0xffffffffffffffff, 0x1fffff] | |
<============================================================================ | |
>============================================================================ | |
((1 << 8) | (1 << 3)) println | |
264 | |
test output: | |
RESULT: | |
264 | |
<============================================================================ | |
>============================================================================ | |
[28683 hexstr, 987834 hexstr, (28683 & 987834) hexstr] println | |
[0x700b, 0xf12ba, 0x100a] | |
test output: | |
RESULT: | |
[0x700b, 0xf12ba, 0x100a] | |
<============================================================================ | |
>============================================================================ | |
[28683 hexstr, 987834 hexstr, (28683 ~ 987834) hexstr] println | |
[0x700b, 0xf12ba, 0xf62b1] | |
test output: | |
RESULT: | |
[0x700b, 0xf12ba, 0xf62b1] | |
<============================================================================ | |
>============================================================================ | |
hypot(3.,4.) println | |
5. | |
test output: | |
RESULT: | |
5. | |
<============================================================================ | |
>============================================================================ | |
2/3 + 1/4 |> println | |
11/12 | |
test output: | |
RESULT: | |
11/12 | |
<============================================================================ | |
>============================================================================ | |
(3/16) << 3 |> println | |
3/2 | |
test output: | |
RESULT: | |
3/2 | |
<============================================================================ | |
>============================================================================ | |
(3/16) << 4 |> println | |
3 | |
test output: | |
RESULT: | |
3 | |
<============================================================================ | |
>============================================================================ | |
(3/16) >> 1 |> println | |
1/16 | |
test output: | |
RESULT: | |
1/16 | |
<============================================================================ | |
>============================================================================ | |
5 / 4 << 3 |> println | |
10 | |
test output: | |
RESULT: | |
10 | |
<============================================================================ | |
>============================================================================ | |
(3. / 4. * 2.) println | |
1.5 | |
test output: | |
RESULT: | |
1.5 | |
<============================================================================ | |
>============================================================================ | |
(2 ^ 3 ^ 2) println | |
512 | |
test output: | |
RESULT: | |
512 | |
<============================================================================ | |
>============================================================================ | |
(1 - 2 + 3) println | |
2 | |
test output: | |
RESULT: | |
2 | |
<============================================================================ | |
>============================================================================ | |
let x = true; \x[ let a = 3; let b = 4; x ? a : b ] (x) println | |
3 | |
test output: | |
RESULT: | |
3 | |
<============================================================================ | |
>============================================================================ | |
let x = false; \x[ let a = 3; let b = 4; x ? a : b ] (x) println | |
4 | |
test output: | |
RESULT: | |
4 | |
<============================================================================ | |
>============================================================================ | |
(2/3) ^ 3 |> println | |
8/27 | |
test output: | |
RESULT: | |
8/27 | |
<============================================================================ | |
>============================================================================ | |
(2/3) ^ -2 |> println | |
9/4 | |
test output: | |
RESULT: | |
9/4 | |
<============================================================================ | |
>============================================================================ | |
[-3.5 trunc, -7/2 |> trunc, 3.5 trunc, 7/2 |> trunc] println | |
[-3., -3, 3., 3] | |
test output: | |
RESULT: | |
[-3., -3, 3., 3] | |
<============================================================================ | |
>============================================================================ | |
[-4.5 trunc, -9/2 |> trunc, 4.5 trunc, 9/2 |> trunc] println | |
[-4., -4, 4., 4] | |
test output: | |
RESULT: | |
[-4., -4, 4., 4] | |
<============================================================================ | |
>============================================================================ | |
[-3.5 round, -7/2 |> round, 3.5 round, 7/2 |> round] println | |
[-4., -4, 4., 4] | |
test output: | |
RESULT: | |
[-4., -4, 4., 4] | |
<============================================================================ | |
>============================================================================ | |
[-4.5 round, -9/2 |> round, 4.5 round, 9/2 |> round] println | |
[-5., -5, 5., 5] | |
test output: | |
RESULT: | |
[-5., -5, 5., 5] | |
<============================================================================ | |
>============================================================================ | |
[-3.5 floor, -7/2 |> floor, 3.5 floor, 7/2 |> floor] println | |
[-4., -4, 3., 3] | |
test output: | |
RESULT: | |
[-4., -4, 3., 3] | |
<============================================================================ | |
>============================================================================ | |
[-4.5 floor, -9/2 |> floor, 4.5 floor, 9/2 |> floor] println | |
[-5., -5, 4., 4] | |
test output: | |
RESULT: | |
[-5., -5, 4., 4] | |
<============================================================================ | |
>============================================================================ | |
[-3.5 ceil, -7/2 |> ceil, 3.5 ceil, 7/2 |> ceil] println | |
[-3., -3, 4., 4] | |
test output: | |
RESULT: | |
[-3., -3, 4., 4] | |
<============================================================================ | |
>============================================================================ | |
[-4.5 ceil, -9/2 |> ceil, 4.5 ceil, 9/2 |> ceil] println | |
[-4., -4, 5., 5] | |
test output: | |
RESULT: | |
[-4., -4, 5., 5] | |
<============================================================================ | |
>============================================================================ | |
5 * cos(asin(3./5.)) | |
test output: | |
RESULT: | |
4. | |
<============================================================================ | |
>============================================================================ | |
5 * cos(asin(3/5)) | |
test output: | |
RESULT: | |
4. | |
<============================================================================ | |
>============================================================================ | |
(81/64) / (5/4) | |
test output: | |
RESULT: | |
81/80 | |
<============================================================================ | |
>============================================================================ | |
-3^2 -- math precedence. exponentiation before unary minus. | |
test output: | |
RESULT: | |
-9 | |
<============================================================================ | |
>============================================================================ | |
-3 abs -- unary minus before trailing function application. | |
test output: | |
RESULT: | |
3 | |
<============================================================================ | |
>============================================================================ | |
-3 abs^2 -- math precedence. ??. | |
test output: | |
RESULT: | |
9 | |
<============================================================================ | |
>============================================================================ | |
-2 sin^3 -- math precedence. ??. | |
test output: | |
RESULT: | |
-0.7518269446689928 | |
<============================================================================ | |
>============================================================================ | |
let p = {x:3,y:4}; -p.x -- dot slot selection before unary minus. | |
test output: | |
RESULT: | |
-3 | |
<============================================================================ | |
>============================================================================ | |
let f = \x[x*x]; [f(3), -f(3)] println -- function argument application before unary minus | |
[9, -9] | |
test output: | |
RESULT: | |
[9, -9] | |
<============================================================================ | |
>============================================================================ | |
(3/4) * (4/9) | |
test output: | |
RESULT: | |
1/3 | |
<============================================================================ | |
>============================================================================ | |
11/7 |> asFloat println; let π = 1π; π/2 |> println; 1e40 println | |
1.5714285714285714 | |
1.5707963267948966 | |
1e+40 | |
test output: | |
RESULT: | |
1e+40 | |
<============================================================================ | |
>============================================================================ | |
[(7 // 2), (-7 // 2)] println -- truncating integer division. | |
[3, -3] | |
test output: | |
RESULT: | |
[3, -3] | |
<============================================================================ | |
>============================================================================ | |
let inv = \x[1/x] | |
[11/7 |> inv, .4 inv] println | |
[7/11, 2.5] | |
test output: | |
RESULT: | |
[7/11, 2.5] | |
<============================================================================ | |
>============================================================================ | |
[gcd(0,0), gcd(0,1), gcd(1,0), gcd(1,1), gcd(-1,1), gcd(1,-1), gcd(-1,-1), gcd(-1,0), gcd(0,-1)] println | |
[1, 1, 1, 1, 1, 1, 1, 1, 1] | |
test output: | |
RESULT: | |
[1, 1, 1, 1, 1, 1, 1, 1, 1] | |
<============================================================================ | |
>============================================================================ | |
[lcm(0,0), lcm(0,1), lcm(1,0), lcm(1,1), lcm(-1,1), lcm(1,-1), lcm(-1,-1), lcm(-1,0), lcm(0,-1)] println | |
[0, 0, 0, 1, -1, -1, 1, 0, 0] | |
test output: | |
RESULT: | |
[0, 0, 0, 1, -1, -1, 1, 0, 0] | |
<============================================================================ | |
>============================================================================ | |
-9/8 * 7/6 * 4/5 | |
test output: | |
RESULT: | |
-21/20 | |
<============================================================================ | |
>============================================================================ | |
let [a,b,c] = [#i32[2, 3, 4, 5], #x32[complex(2, 3), complex(4, 5)], #r64[2/7, 3/7, 4/7, 5/7, 6/7]] | |
[a,b,c] println | |
[a len, b len, c len] println; [a,b,c] | |
[#i32[2, 3, 4, 5], #x32[x32(2.f, 3.f), x32(4.f, 5.f)], #r64[2/7, 3/7, 4/7, 5/7, 6/7]] | |
[4, 2, 5] | |
test output: | |
RESULT: | |
[ #i32[2, 3, 4, 5], | |
. #x32[x32(2.f, 3.f), x32(4.f, 5.f)], | |
. #r64[2/7, 3/7, 4/7, 5/7, 6/7]] | |
<============================================================================ | |
>============================================================================ | |
#r64[1,2/3,4] println class | |
#r64[1/1, 2/3, 4/1] | |
test output: | |
RESULT: | |
List_r64 | |
<============================================================================ | |
>============================================================================ | |
let inv = \x[1/x] | |
#i64[8,9,10,11,12] inv println class | |
#r64[1/8, 1/9, 1/10, 1/11, 1/12] | |
test output: | |
RESULT: | |
List_r64 | |
<============================================================================ | |
>============================================================================ | |
1 + [[1,2,3.1,4.3] / [7,8/3,9,10.2,11], #f64[1,2,3,4] / #f64[7,8,9,10,11], #i64[1,2,3,4] / #i64[7,8,9,10,11], #x64[1,2,3,4] / #x64[7,8,9,10,11]] * 3 | |
test output: | |
RESULT: | |
[ [10/7, 13/4, 2.033333333333333, 2.264705882352941], | |
. #f64[1.4285714285714286, 1.75, 2., 2.2], | |
. #r64[10/7, 7/4, 2/1, 11/5], | |
. #x64[x64(1.4285714285714286, 0.), x64(1.75, 0.), x64(2., 0.), x64(2.2, 0.)]] | |
<============================================================================ | |
>============================================================================ | |
-[1,2.,3/4,complex(5.,6/7),#f64[8,9.]] sin | |
test output: | |
RESULT: | |
[ -0.8414709848078965, | |
. -0.9092974268256817, | |
. -0.6816387600233341, | |
. x64(1.3332841344465478, -0.27402413818821425), | |
. #f64[-0.9893582466233818, -0.4121184852417566]] | |
<============================================================================ | |
>============================================================================ | |
[0,1,2,3,4,5,6,7,8,9,10,11,12,13]/4 |> floor | |
test output: | |
RESULT: | |
[0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3] | |
<============================================================================ | |
>============================================================================ | |
fn frac(x) = x - x floor; [0,1,2,3,4,5,6,7,8,9,10,11,12,13]/4 |> frac | |
test output: | |
RESULT: | |
[0, 1/4, 1/2, 3/4, 0, 1/4, 1/2, 3/4, 0, 1/4, 1/2, 3/4, 0, 1/4] | |
<============================================================================ | |
>============================================================================ | |
[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24] * .1 %% (1/3) | |
test output: | |
RESULT: | |
[ 0., | |
. 0.1, | |
. 0.2, | |
. 0.30000000000000004, | |
. 0.2666666666666666, | |
. 0.16666666666666666, | |
. 0.06666666666666657, | |
. 0.033333333333333506, | |
. 0.13333333333333344, | |
. 0.2333333333333334, | |
. 0.3333333333333333, | |
. 0.23333333333333323, | |
. 0.13333333333333314, | |
. 0.033333333333333215, | |
. 0.06666666666666701, | |
. 0.16666666666666666, | |
. 0.2666666666666669, | |
. 0.2999999999999998, | |
. 0.19999999999999987, | |
. 0.09999999999999964, | |
. ...] | |
<============================================================================ | |
>============================================================================ | |
[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]/10 %% (1/3) | |
test output: | |
RESULT: | |
[ 0, | |
. 1/10, | |
. 1/5, | |
. 3/10, | |
. 4/15, | |
. 1/6, | |
. 1/15, | |
. 1/30, | |
. 2/15, | |
. 7/30, | |
. 1/3, | |
. 7/30, | |
. 2/15, | |
. 1/30, | |
. 1/15, | |
. 1/6, | |
. 4/15, | |
. 3/10, | |
. 1/5, | |
. 1/10, | |
. ...] | |
<============================================================================ | |
>============================================================================ | |
[2.*(3/5), 2*(3/5), complex(2,0)*(3/5), complex(2,0)*(3./5), (3/5)*2., (3/5)*complex(2,0)] | |
test output: | |
RESULT: | |
[1.2, 6/5, 1.2, 1.2, 1.2, 1.2] | |
<============================================================================ | |
>============================================================================ | |
let absdif = \a,b[abs(a-b)] | |
[absdif(4/3, 5/7), absdif(5/7, 4/3)] | |
test output: | |
RESULT: | |
[13/21, 13/21] | |
<============================================================================ | |
>============================================================================ | |
[2, 3, 4, 5] class println | |
List_obj | |
test output: | |
RESULT: | |
List_obj | |
<============================================================================ | |
>============================================================================ | |
#i32[2, 3, 4, 5] class println | |
List_i32 | |
test output: | |
RESULT: | |
List_i32 | |
<============================================================================ | |
>============================================================================ | |
#i32[[2, 3], [4, 5]] class println | |
error: 6 Object of class List_obj cannot be converted to integer. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
[[2, 3] @, [4, 5] @] println | |
[[2, 4], [3, 5]] | |
test output: | |
RESULT: | |
[[2, 4], [3, 5]] | |
<============================================================================ | |
>============================================================================ | |
#i32[[2, 3] @, [4, 5] @] @ class println | |
[List_i32, List_i32] | |
test output: | |
RESULT: | |
[List_i32, List_i32] | |
<============================================================================ | |
>============================================================================ | |
#i64[2, 3, 4, 5] println | |
#i32[2, 3, 4, 5] println | |
[2, 3, 4, 5] println | |
#i64[2, 3, 4, 5] | |
#i32[2, 3, 4, 5] | |
[2, 3, 4, 5] | |
test output: | |
RESULT: | |
[2, 3, 4, 5] | |
<============================================================================ | |
>============================================================================ | |
#i64[[2, 3], [4, 5]] println | |
#i32[[2, 3], [4, 5]] println | |
[[2, 3], [4, 5]] println | |
error: 6 Object of class List_obj cannot be converted to integer. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
2 + 3j |> println | |
x64(2., 3.) | |
test output: | |
RESULT: | |
x64(2., 3.) | |
<============================================================================ | |
>============================================================================ | |
[1M, 1k, 1h, 1c, 1m, 1u, 1j, 1kj] println | |
[1e+06, 1000., 100., 0.01, 0.001, 1e-06, x64(0., 1.), x64(0., 1000.)] | |
test output: | |
RESULT: | |
[1e+06, 1000., 100., 0.01, 0.001, 1e-06, x64(0., 1.), x64(0., 1000.)] | |
<============================================================================ | |
>============================================================================ | |
[1.M, 1.k, 1234., 1.h, 1.c, 1.m, 1.u, 1.j, 1.kj] println | |
[1e+06, 1000., 1234., 100., 0.01, 0.001, 1e-06, x64(0., 1.), x64(0., 1000.)] | |
test output: | |
RESULT: | |
[ 1e+06, | |
. 1000., | |
. 1234., | |
. 100., | |
. 0.01, | |
. 0.001, | |
. 1e-06, | |
. x64(0., 1.), | |
. x64(0., 1000.)] | |
<============================================================================ | |
>============================================================================ | |
let a = {x:1, y:2}; a.x println | |
1 | |
test output: | |
RESULT: | |
1 | |
<============================================================================ | |
>============================================================================ | |
let a = {x:1, y:2}; let x = \a[a.x]; a x println | |
1 | |
test output: | |
RESULT: | |
1 | |
<============================================================================ | |
>============================================================================ | |
[1, 2, 3] + [10, 20, 30] |> println | |
[11, 22, 33] | |
test output: | |
RESULT: | |
[11, 22, 33] | |
<============================================================================ | |
>============================================================================ | |
fn foo(n Int) { n println; n <= 0 ? 0 : n-1 |> foo } | |
foo(5) | |
5 | |
4 | |
3 | |
2 | |
1 | |
0 | |
test output: | |
RESULT: | |
0 | |
<============================================================================ | |
>============================================================================ | |
fn foo(n Int) { n println; n <= 0 ? 0 : n-1 |> foo } | |
foo([3,4,5]) | |
test output: | |
3 | |
2 | |
1 | |
0 | |
4 | |
3 | |
2 | |
1 | |
0 | |
5 | |
4 | |
3 | |
2 | |
1 | |
0 | |
RESULT: | |
[0, 0, 0] | |
<============================================================================ | |
>============================================================================ | |
fn foo(n Int) { | |
n <= 0 ? 0 : do { n println; n-1 |> foo } | |
} | |
foo(5) | |
5 | |
4 | |
3 | |
2 | |
1 | |
test output: | |
RESULT: | |
0 | |
<============================================================================ | |
>============================================================================ | |
-- newlines everywhere | |
fn foo ( | |
n Int | |
) | |
{ | |
n <= | |
0 ? | |
0 : | |
do | |
{ | |
n println | |
n - | |
1 |> | |
foo | |
} | |
} | |
foo(5) | |
5 | |
4 | |
3 | |
2 | |
1 | |
test output: | |
RESULT: | |
0 | |
<============================================================================ | |
>============================================================================ | |
-- mutually recursive functions | |
fn bar -- 'forward declaration'. actually this defines a generic function with no methods. | |
fn foo(n Int) { | |
n println | |
n <= 0 ? 0 : n-1 |> bar | |
} | |
fn bar(n Int) { #bar println; n foo } -- define a method of generic function 'bar'. | |
foo(5) | |
5 | |
bar | |
4 | |
bar | |
3 | |
bar | |
2 | |
bar | |
1 | |
bar | |
0 | |
test output: | |
RESULT: | |
0 | |
<============================================================================ | |
>============================================================================ | |
-- mutually recursive functions w/o forward declaration | |
fn foo(n Int) { | |
n println | |
n <= 0 ? 0 : n-1 |> bar | |
} | |
fn bar(n Int) { #bar println; n foo } | |
foo(5) | |
5 | |
bar | |
4 | |
bar | |
3 | |
bar | |
2 | |
bar | |
1 | |
bar | |
0 | |
test output: | |
RESULT: | |
0 | |
<============================================================================ | |
>============================================================================ | |
-- generic function with no methods | |
fn foo | |
foo(5) | |
CALL FRAMES SIZE 1 BASE 1 | |
0 ? lm 0x0 pc 0x0 sb 0 ssz 0 istry 0 ksz XXX | |
-> ? lm 0x1286dd2a0 pc 0x13452b164 sb 0 ssz 1 ksz 1 | |
num args: 1 | |
0 I64 | |
error: 3 No applicable method found for function 'foo'. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
fn fox(a Int, b = 7) = [b, a] | |
fn fox(a Float, b = 8.1) = [b, a, "x"] | |
1 fox println; 2.1 fox println; 3 fox(321) println | |
[7, 1] | |
[8.1, 2.1, x] | |
[321, 3] | |
test output: | |
RESULT: | |
[321, 3] | |
<============================================================================ | |
>============================================================================ | |
fn fox(a Int, b Int = 7) { ["A", a, b] } | |
fn fox(a Int, b Float) { ["B", a, b] } | |
fn fox(a Float, b Int) { ["C", a, b] } | |
fn fox(a Float = 0., b Float = 0.) { ["D", a, b] } | |
[fox(1), fox(1, 2), fox(1, 2.), fox(1., 2), fox(1., 2.), fox()] println | |
[[A, 1, 7], [A, 1, 2], [B, 1, 2.], [C, 1., 2], [D, 1., 2.], [D, 0., 0.]] | |
test output: | |
RESULT: | |
[[A, 1, 7], [A, 1, 2], [B, 1, 2.], [C, 1., 2], [D, 1., 2.], [D, 0., 0.]] | |
<============================================================================ | |
>============================================================================ | |
fn fox(a Int, b Int = 7) { ["A", a, b] } | |
fn fox(a Int, b Float) { ["B", a, b] } | |
fn fox(a Float, b Int) { ["C", a, b] } | |
fn fox(a Float = 0., b Float) { ["D", a, b] } | |
[fox(1), fox(1, 2), fox(1, 2.), fox(1., 2), fox(1., 2.), fox()] println | |
[[A, 1, 7], [A, 1, 2], [B, 1, 2.], [C, 1., 2], [D, 1., 2.], [D, 0., nil]] | |
test output: | |
RESULT: | |
[ [A, 1, 7], | |
. [A, 1, 2], | |
. [B, 1, 2.], | |
. [C, 1., 2], | |
. [D, 1., 2.], | |
. [D, 0., nil]] | |
<============================================================================ | |
>============================================================================ | |
fn fox(a Int, b Int = 7) { ["A", a, b] } | |
fn fox(a Int, b Float) { ["B", a, b] } | |
fn fox(a Float, b Int) { ["C", a, b] } | |
fn fox(a Float = 0., b Float) { ["D", a, b] } | |
fn fox() { ["E"] } | |
[fox(1), fox(1, 2), fox(1, 2.), fox(1., 2), fox(1., 2.), fox()] println | |
[[A, 1, 7], [A, 1, 2], [B, 1, 2.], [C, 1., 2], [D, 1., 2.], [D, 0., nil]] | |
test output: | |
RESULT: | |
[ [A, 1, 7], | |
. [A, 1, 2], | |
. [B, 1, 2.], | |
. [C, 1., 2], | |
. [D, 1., 2.], | |
. [D, 0., nil]] | |
<============================================================================ | |
>============================================================================ | |
fn fox(a = 1, b Int) { ["A", a, b] } | |
fn fox(a, b Float) { ["B", a, b] } | |
[fox(1), fox(1, 2), fox(1, 2.), fox(1., 2), fox(1., 2.), fox()] println | |
[[A, 1, nil], [A, 1, 2], [B, 1, 2.], [A, 1., 2], [B, 1., 2.], [A, 1, nil]] | |
test output: | |
RESULT: | |
[ [A, 1, nil], | |
. [A, 1, 2], | |
. [B, 1, 2.], | |
. [A, 1., 2], | |
. [B, 1., 2.], | |
. [A, 1, nil]] | |
<============================================================================ | |
>============================================================================ | |
fn fox(a = 1, b Int) { ["A", a, b] } | |
fn fox(a, b Float) { ["B", a, b] } | |
[fox(1), fox(1, 2), fox(1, 2.), fox(1., 2), fox(1., 2.), fox(), fox(1,nil)] println | |
CALL FRAMES SIZE 1 BASE 1 | |
0 ? lm 0x0 pc 0x0 sb 0 ssz 0 istry 0 ksz XXX | |
-> ? lm 0x105122ba0 pc 0x11dbca63c sb 0 ssz 8 ksz 6 | |
num args: 2 | |
0 I64 | |
1 Nil | |
error: 3 No applicable method found for function 'fox'. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
fn fox(a Int, b Int = 7) { ["A", a, b] } | |
fn fox(a Int, b Float) { ["B", a, b] } | |
fn fox(a Float, b Int) { ["C", a, b] } | |
fn fox(a Float = 0., b Float) { ["D", a, b] } | |
fn fox() { ["E"] } | |
[fox(1), fox(1, 2), fox(1, 2.), fox(1., 2), fox(1., 2.), fox()] println | |
[fox(1), fox(1, 2), fox(1, 2.), fox(1., 2), fox(1., 2.), fox()] println | |
[[A, 1, 7], [A, 1, 2], [B, 1, 2.], [C, 1., 2], [D, 1., 2.], [D, 0., nil]] | |
[[A, 1, 7], [A, 1, 2], [B, 1, 2.], [C, 1., 2], [D, 1., 2.], [D, 0., nil]] | |
test output: | |
RESULT: | |
[ [A, 1, 7], | |
. [A, 1, 2], | |
. [B, 1, 2.], | |
. [C, 1., 2], | |
. [D, 1., 2.], | |
. [D, 0., nil]] | |
<============================================================================ | |
>============================================================================ | |
Float allSuperclasses println | |
[Float, Real, Complex, Number, Scalar, Obj] | |
test output: | |
RESULT: | |
[Float, Real, Complex, Number, Scalar, Obj] | |
<============================================================================ | |
>============================================================================ | |
List allSuperclasses println | |
[List, Seq, Obj] | |
test output: | |
RESULT: | |
[List, Seq, Obj] | |
<============================================================================ | |
>============================================================================ | |
List_i32 allSuperclasses println | |
[List_i32, List_int, List, Seq, ConcreteNumeric, Obj] | |
test output: | |
RESULT: | |
[List_i32, List_int, List, Seq, ConcreteNumeric, Obj] | |
<============================================================================ | |
>============================================================================ | |
defClass(#A, [Scalar], {a:1}, {b:2}); | |
defClass(#B, [A], {c:3}, {d:4}); | |
let a = A{e:5} | |
let b = B{f:6} | |
A println | |
B println | |
a println | |
b println | |
a.e println | |
b.f println | |
a.a println | |
b.a println | |
b.c println | |
A.b println | |
B.b println -- nil | |
B.d println | |
(a class).b println | |
(b class).b println -- nil | |
(b class).d println | |
a.b println | |
b.b println -- nil | |
b.d println | |
A | |
B | |
A{e:5} | |
B{f:6} | |
5 | |
6 | |
1 | |
1 | |
3 | |
2 | |
nil | |
4 | |
2 | |
nil | |
4 | |
2 | |
2 | |
4 | |
test output: | |
RESULT: | |
4 | |
<============================================================================ | |
>============================================================================ | |
EqMap new println | |
EqMap | |
test output: | |
RESULT: | |
EqMap{} | |
<============================================================================ | |
>============================================================================ | |
let m = EqMap new put(1,#a) put(2,#b) | |
[m get(1), m get(2), m get(3), m] println | |
[a, b, nil, EqMap{2:b, 1:a}] | |
test output: | |
RESULT: | |
[a, b, nil, EqMap{2: b, 1: a}] | |
<============================================================================ | |
>============================================================================ | |
{} class println | |
Record | |
test output: | |
RESULT: | |
Record | |
<============================================================================ | |
>============================================================================ | |
{1, 2, 2, 1, 3, 1} println | |
{3, 2, 1} | |
test output: | |
RESULT: | |
{3, 2, 1} | |
<============================================================================ | |
>============================================================================ | |
{1, 2, 2, 1, 3, 1} class println | |
EqSet | |
test output: | |
RESULT: | |
EqSet | |
<============================================================================ | |
>============================================================================ | |
[1, 2, 2, 1, 3, 1] idset println | |
{≡ 3, 2, 1} | |
test output: | |
RESULT: | |
{3, 2, 1} | |
<============================================================================ | |
>============================================================================ | |
[1, 2, 2, 1, 3, 1] idset class println | |
IdSet | |
test output: | |
RESULT: | |
IdSet | |
<============================================================================ | |
>============================================================================ | |
1/2 |> class println | |
R64 | |
test output: | |
RESULT: | |
R64 | |
<============================================================================ | |
>============================================================================ | |
{1/2, 1/2, 2/3} println | |
{2/3, 1/2} | |
test output: | |
RESULT: | |
{2/3, 1/2} | |
<============================================================================ | |
>============================================================================ | |
{1/2, 1/2, 2/3} class println | |
EqSet | |
test output: | |
RESULT: | |
EqSet | |
<============================================================================ | |
>============================================================================ | |
{{ | |
syntax error, line 1: expected set or record fields after '{'. | |
this line: | |
{{ | |
next token: [2] 1 tokEOF | |
syntax error, line 1: expected statements | |
this line: | |
{{ | |
next token: [2] 1 tokEOF | |
PARSE FAILED | |
============================================================================= | |
unknown error | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
1 %^ 2; 8 println | |
syntax error, line 1: unrecognized operator | |
this line: | |
1 %^ 2; 8 println | |
next token: [1] 35 tokOperator '%^' | |
syntax error, line 1: errors occurred while parsing. | |
this line: | |
1 %^ 2; 8 println | |
next token: [6] 1 tokEOF | |
PARSE FAILED | |
============================================================================= | |
unknown error | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
-- this is a comment | |
-- this is another comment | |
1 %^ 2 -- oops | |
8 println | |
-- all done here | |
syntax error, line 3: unrecognized operator | |
this line: | |
1 %^ 2 -- oops | |
next token: [3] 35 tokOperator '%^' | |
syntax error, line 5: errors occurred while parsing. | |
next token: [10] 1 tokEOF | |
PARSE FAILED | |
============================================================================= | |
unknown error | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
let a = {3,5,2,3,5,1,2,1,4,3} | |
let b = {1,2,3,4,5 #@$ | |
[a, b, a eqhash hexstr, b eqhash hexstr, a == b] println | |
syntax error, line 2: expected set or record fields after '{'. | |
this line: | |
let b = {1,2,3,4,5 #@$ | |
next token: [39] 36 tokEach | |
syntax error, line 3: errors occurred while parsing. | |
this line: | |
[a, b, a eqhash hexstr, b eqhash hexstr, a == b] println | |
next token: [60] 1 tokEOF | |
PARSE FAILED | |
============================================================================= | |
unknown error | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
let a = {3,5,2,3,5,1,2,1,4,3} | |
let b = {1,2,3,4,5 | |
[a, b, a eqhash hexstr, b eqhash hexstr, a == b] println | |
syntax error, line 3: expected set or record fields after '{'. | |
this line: | |
[a, b, a eqhash hexstr, b eqhash hexstr, a == b] println | |
next token: [40] 19 tokName 'a' | |
syntax error, line 3: errors occurred while parsing. | |
this line: | |
[a, b, a eqhash hexstr, b eqhash hexstr, a == b] println | |
next token: [57] 1 tokEOF | |
PARSE FAILED | |
============================================================================= | |
unknown error | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
let a = {3,5,2,3,5,1,2,1,4,3} | |
let b = {1,2,3,4,5, | |
[a, b, a eqhash hexstr, b eqhash hexstr, a == b]}; b println | |
error: 3 Undefined global variable 'b' | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
import stuff | |
stuff.funA() | |
stuff.funB() | |
(stuff.funA typeName, stuff.funA pointer hexstr) println | |
(stuff.funB typeName, stuff.funB pointer hexstr) println | |
stuff println | |
A | |
B | |
(GF, 0x10b257680) | |
(Lambda, 0x105111420) | |
{__moduleName:stuff, funA:GF(funA), funB:<Lambda>} | |
test output: | |
RESULT: | |
{__moduleName: stuff, funA: GF(funA), funB: <Lambda>} | |
<============================================================================ | |
>============================================================================ | |
import stuff : * | |
funA() | |
funB() | |
(funA typeName, funA pointer hexstr) println | |
(funB typeName, funB pointer hexstr) println | |
A | |
B | |
(GF, 0x10b248f80) | |
(Lambda, 0x1051082a0) | |
test output: | |
RESULT: | |
(Lambda, 0x1051082a0) | |
<============================================================================ | |
>============================================================================ | |
import stuff as X | |
X.funA() | |
X.funB() | |
(X.funA typeName, X.funA pointer hexstr) println | |
(X.funB typeName, X.funB pointer hexstr) println | |
A | |
B | |
(GF, 0x10b23a880) | |
(Lambda, 0x1051098a0) | |
test output: | |
RESULT: | |
(Lambda, 0x1051098a0) | |
<============================================================================ | |
>============================================================================ | |
funB() | |
(funB typeName, funB pointer hexstr) println | |
funA() | |
(funA typeName, funA pointer hexstr) println | |
error: 3 Undefined global variable 'funB' | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
import stuff : funB | |
funB() | |
(funB typeName, funB pointer hexstr) println | |
funA() | |
(funA typeName, funA pointer hexstr) println | |
codeImportNames | |
B | |
(Lambda, 0x1286e2aa0) | |
error: 3 Undefined global variable 'funA' | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
import stuff : funB | |
funB() | |
(funB typeName, funB pointer hexstr) println | |
codeImportNames | |
B | |
(Lambda, 0x1286e18a0) | |
test output: | |
RESULT: | |
(Lambda, 0x1286e18a0) | |
<============================================================================ | |
>============================================================================ | |
import stuff : funA | |
funA() | |
funB() | |
codeImportNames | |
A | |
error: 3 Undefined global variable 'funB' | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
import stuff | |
import stuff : funA | |
funA() | |
stuff.funA() | |
stuff.funB() | |
(funA typeName, funA pointer hexstr) println | |
(stuff.funA typeName, stuff.funA pointer hexstr) println | |
(stuff.funB typeName, stuff.funB pointer hexstr) println | |
codeImportNames | |
A | |
A | |
B | |
(GF, 0x133ca68a0) | |
(GF, 0x133ca68a0) | |
(Lambda, 0x1286e35a0) | |
test output: | |
RESULT: | |
(Lambda, 0x1286e35a0) | |
<============================================================================ | |
>============================================================================ | |
import stuff : funA as xA, funB as xB | |
xA() | |
xB() | |
(xA typeName, xA pointer hexstr) println | |
(xB typeName, xB pointer hexstr) println | |
codeImportNames | |
A | |
B | |
(GF, 0x133cb4fa0) | |
(Lambda, 0x1286e62a0) | |
test output: | |
RESULT: | |
(Lambda, 0x1286e62a0) | |
<============================================================================ | |
>============================================================================ | |
addAll println | |
GF(addAll) | |
test output: | |
RESULT: | |
GF(addAll) | |
<============================================================================ | |
>============================================================================ | |
(-) println | |
GF(-) | |
test output: | |
RESULT: | |
GF(-) | |
<============================================================================ | |
>============================================================================ | |
(*)(3, 5) println | |
15 | |
test output: | |
RESULT: | |
15 | |
<============================================================================ | |
>============================================================================ | |
3 (*) 5 println | |
ast: | |
[astDo, [astCall, println, [astCall, *, 3, 5]]] | |
chunk code ----- | |
0 codePushSmallInt 3 | |
1 codePushSmallInt 5 | |
2 codePushGlobalVar 0 * | |
3 codeApply 2 | |
4 codePushGlobalVar 1 println | |
5 codeApply 1 | |
6 codeReturn | |
test output: | |
RESULT: | |
nil | |
<============================================================================ | |
>============================================================================ | |
3 (*) 5 println | |
15 | |
test output: | |
RESULT: | |
15 | |
<============================================================================ | |
>============================================================================ | |
let x = (*); 3 x(5) println | |
15 | |
test output: | |
RESULT: | |
15 | |
<============================================================================ | |
>============================================================================ | |
let x = *; 3 x(5) println | |
15 | |
test output: | |
RESULT: | |
15 | |
<============================================================================ | |
>============================================================================ | |
5(1,-2,3/5) | |
syntax error, line 1: expected a parenthesized operator name after value and '('. | |
this line: | |
5(1,-2,3/5) | |
next token: [3] 8 tokComma ',' | |
syntax error, line 1: expected statements | |
this line: | |
5(1,-2,3/5) | |
next token: [11] 1 tokEOF | |
PARSE FAILED | |
============================================================================= | |
unknown error | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
defClass(#A, Scalar, {x:1}, {y:2}) | |
let a = A{z:3} | |
("a", a, a.x, a.y, a.z, "A", A, A.x, A.y, A.z) println | |
(a.x, a.y, a.z) = (10, 20, 30) | |
(A.x, A.y, A.z) = (40, 50, 60) | |
("a", a, a.x, a.y, a.z, "A", A, A.x, A.y, A.z) println | |
((a class).x, (a class).y, (a class).z) = (70, 80, 90) | |
("a", a, a.x, a.y, a.z, "A", A, A.x, A.y, A.z) println | |
a setContents {x:11, y:22, z:33} | |
A setContents {x:44, y:55, z:66} | |
("a", a, a.x, a.y, a.z, "A", A, A.x, A.y, A.z) println | |
(a, A{z:3}, 1, 2, 3, A, A, nil, 2, nil) | |
(a, A{z:30, x:10, y:20}, 10, 20, 30, A, A, 40, 50, 60) | |
(a, A{z:30, x:10, y:20}, 10, 20, 30, A, A, 70, 80, 90) | |
(a, A{x:11, y:22, z:33}, 11, 22, 33, A, A, 44, 55, 66) | |
test output: | |
RESULT: | |
(a, A{x: 11, y: 22, z: 33}, 11, 22, 33, A, A, 44, 55, 66) | |
<============================================================================ | |
>============================================================================ | |
1 < 2 |> println | |
1 > 2 |> println | |
if (true) { "a" } else { "b" } println | |
if (false) { "a" } else { "b" } println | |
if (true) { "a" } else if (true) { "b" } else { "c" } println | |
if (false) { "a" } else if (true) { "b" } else { "c" } println | |
if (false) { "a" } else if (false) { "b" } else { "c" } println | |
if (false) { "a" } else if (true ) { "b" } else if (true) { "c" } else { "d" } println | |
if (false) { "a" } else if (false) { "b" } else if (true) { "c" } else { "d" } println | |
if (false) { "a" } else if (false) { "b" } else if (false) { "c" } else { "d" } println | |
true | |
false | |
a | |
b | |
a | |
b | |
c | |
b | |
c | |
d | |
test output: | |
RESULT: | |
d | |
<============================================================================ | |
>============================================================================ | |
#f32[1,2,3,4,5,6] isTensor | |
test output: | |
RESULT: | |
([6], f32) | |
<============================================================================ | |
>============================================================================ | |
[#f32[1],#f32[3]] isTensor | |
test output: | |
RESULT: | |
([2, 1], f32) | |
<============================================================================ | |
>============================================================================ | |
[[#f32[1,2,3],#f32[3,4,5]]] isTensor | |
test output: | |
RESULT: | |
([1, 2, 3], f32) | |
<============================================================================ | |
>============================================================================ | |
[[#i32[1, 2],#i32[3, 4]]] isTensor | |
test output: | |
RESULT: | |
([1, 2, 2], i32) | |
<============================================================================ | |
>============================================================================ | |
[[#r32[1/7, 2/7],#r32[3/7, 4/7]]] isTensor | |
test output: | |
RESULT: | |
([1, 2, 2], r32) | |
<============================================================================ | |
>============================================================================ | |
[[#r64[1/7, 2/7],#r64[3/7, 4/7]]] isTensor | |
test output: | |
RESULT: | |
([1, 2, 2], r64) | |
<============================================================================ | |
>============================================================================ | |
[[#r64[1/7, 2/7],#r32[3/7, 4/7]]] isTensor | |
test output: | |
RESULT: | |
([1, 2, 2], r64) | |
<============================================================================ | |
>============================================================================ | |
[#f32[1], #i32[3]] isTensor | |
test output: | |
RESULT: | |
([2, 1], f32) | |
<============================================================================ | |
>============================================================================ | |
[[1, 2], [3, 4]] isTensor | |
test output: | |
RESULT: | |
([2, 2], i64) | |
<============================================================================ | |
>============================================================================ | |
[[[[1.1, 2.1, 3.1],[3.1, 4.1, 5.1]]]] isTensor | |
test output: | |
RESULT: | |
([1, 1, 2, 3], f64) | |
<============================================================================ | |
>============================================================================ | |
[[[[1.1, 2/1, 3], [3, 4, 5]]]] isTensor | |
test output: | |
RESULT: | |
([1, 1, 2, 3], f64) | |
<============================================================================ | |
>============================================================================ | |
[[1, 2], [3, 4, 5]] isTensor | |
test output: | |
RESULT: | |
nil | |
<============================================================================ | |
>============================================================================ | |
[[1/1, 2/2], [3/3, 4/4]] isTensor | |
test output: | |
RESULT: | |
([2, 2], r64) | |
<============================================================================ | |
>============================================================================ | |
#i32[2/3, 3/2, 17/5] | |
test output: | |
RESULT: | |
#i32[0, 1, 3] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] take([0,1,2,3,4,5,6]) | |
test output: | |
RESULT: | |
[ [], | |
. [1], | |
. [1, 2], | |
. [1, 2, 3], | |
. [1, 2, 3, 4], | |
. [1, 2, 3, 4, 5], | |
. [1, 2, 3, 4, 5]] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] take(3) | |
test output: | |
RESULT: | |
[1, 2, 3] | |
<============================================================================ | |
>============================================================================ | |
#f32[1,2,3,4,5] take(3) | |
test output: | |
RESULT: | |
#f32[1.f, 2.f, 3.f] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] take(-3) | |
test output: | |
RESULT: | |
[3, 4, 5] | |
<============================================================================ | |
>============================================================================ | |
#f32[1,2,3,4,5] take(-3) | |
test output: | |
RESULT: | |
#f32[3.f, 4.f, 5.f] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] drop(3) | |
test output: | |
RESULT: | |
[4, 5] | |
<============================================================================ | |
>============================================================================ | |
#f32[1,2,3,4,5] drop(3) | |
test output: | |
RESULT: | |
#f32[4.f, 5.f] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] drop(-3) | |
test output: | |
RESULT: | |
[1, 2] | |
<============================================================================ | |
>============================================================================ | |
#f32[1,2,3,4,5] drop(-3) | |
test output: | |
RESULT: | |
#f32[1.f, 2.f] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7] stride(1) | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5, 6, 7] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7] stride(2) | |
test output: | |
RESULT: | |
[1, 3, 5, 7] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7] stride(3) | |
test output: | |
RESULT: | |
[1, 4, 7] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7] stride(-1) | |
test output: | |
RESULT: | |
[7, 6, 5, 4, 3, 2, 1] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7] stride(-2) | |
test output: | |
RESULT: | |
[7, 5, 3, 1] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7] stride(-3) | |
test output: | |
RESULT: | |
[7, 4, 1] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] stutter(2) | |
test output: | |
RESULT: | |
[1, 1, 2, 2, 3, 3, 4, 4, 5, 5] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] stutter(3) | |
test output: | |
RESULT: | |
[1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] rotate(1) | |
test output: | |
RESULT: | |
[5, 1, 2, 3, 4] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] rotate(2) | |
test output: | |
RESULT: | |
[4, 5, 1, 2, 3] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] rotate([-1,0,1,2,3]) | |
test output: | |
RESULT: | |
[ [2, 3, 4, 5, 1], | |
. [1, 2, 3, 4, 5], | |
. [5, 1, 2, 3, 4], | |
. [4, 5, 1, 2, 3], | |
. [3, 4, 5, 1, 2]] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] rotate(-1) | |
test output: | |
RESULT: | |
[2, 3, 4, 5, 1] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] rotate(-2) | |
test output: | |
RESULT: | |
[3, 4, 5, 1, 2] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7] clump(2) | |
test output: | |
RESULT: | |
[[1, 2], [3, 4], [5, 6]] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7] clump(3) | |
test output: | |
RESULT: | |
[[1, 2, 3], [4, 5, 6]] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7] clump([1,2] @) | |
test output: | |
RESULT: | |
[[[1], [2], [3], [4], [5], [6], [7]], [[1, 2], [3, 4], [5, 6]]] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] reverse | |
test output: | |
RESULT: | |
[5, 4, 3, 2, 1] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] evenMirror | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5, 5, 4, 3, 2, 1] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] oddMirror | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5, 4, 3, 2, 1] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] cycMirror | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5, 4, 3, 2] | |
<============================================================================ | |
>============================================================================ | |
[1] oddMirror | |
test output: | |
RESULT: | |
[1] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] muss -- shuffle to a random order | |
test output: | |
RESULT: | |
[1, 4, 3, 2, 5] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] muss -- shuffle to a random order | |
test output: | |
RESULT: | |
[1, 3, 2, 4, 5] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4] pick(16) -- pick values at random | |
test output: | |
RESULT: | |
[3, 2, 3, 4, 1, 1, 1, 4, 1, 3, 4, 3, 3, 1, 4, 1] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4] xpick(16) -- pick values at random, excluding previous. | |
test output: | |
RESULT: | |
[3, 2, 1, 2, 1, 2, 4, 2, 4, 2, 3, 4, 1, 3, 1, 2] | |
<============================================================================ | |
>============================================================================ | |
[1,2] pick(16) -- pick values at random | |
test output: | |
RESULT: | |
[1, 2, 2, 1, 1, 1, 2, 2, 1, 1, 2, 2, 1, 2, 2, 2] | |
<============================================================================ | |
>============================================================================ | |
[1,2] xpick(16) -- pick values at random, excluding previous. | |
test output: | |
RESULT: | |
[1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4] ncyc(0) | |
test output: | |
RESULT: | |
[] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4] ncyc(1) | |
test output: | |
RESULT: | |
[1, 2, 3, 4] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4] ncyc(2) | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 1, 2, 3, 4] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4] ncyc(3) | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4] | |
<============================================================================ | |
>============================================================================ | |
[[1,2],[3,4,5]] join | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5] | |
<============================================================================ | |
>============================================================================ | |
[#f32[1,2],#f32[3,4,5]] join | |
test output: | |
RESULT: | |
#f32[1.f, 2.f, 3.f, 4.f, 5.f] | |
<============================================================================ | |
>============================================================================ | |
[#i32[1,2],#i32[3,4,5]] join | |
test output: | |
RESULT: | |
#i32[1, 2, 3, 4, 5] | |
<============================================================================ | |
>============================================================================ | |
[[1],[2],[3,4,5]] join | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5] | |
<============================================================================ | |
>============================================================================ | |
[#f32[1,2],[3,4,5]] join | |
test output: | |
error: 6 join: lists must have the same element types. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
[#f32[1,2],#i32[3,4,5]] join | |
test output: | |
error: 6 join: lists must have the same element types. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
[[1],2,[3,4,5]] join | |
test output: | |
error: 6 join: lists must have the same element types. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
[1,2,3,10,30,50] reduce(+,1000) | |
test output: | |
RESULT: | |
1096 | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,10,30,50] scan(+,1000) | |
test output: | |
RESULT: | |
[1001, 1003, 1006, 1016, 1046, 1096] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6] scan(+,1000) | |
test output: | |
RESULT: | |
[1001, 1003, 1006, 1010, 1015, 1021] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,10,30,50] reduce1(+) | |
test output: | |
RESULT: | |
97 | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,10,30,50] scan1(+) | |
test output: | |
RESULT: | |
[1, 3, 6, 16, 46, 96] | |
<============================================================================ | |
>============================================================================ | |
fn isOdd(x Int) { (x&1)==1 }; [1,2,3,4,5,6,7] filter(isOdd) | |
test output: | |
RESULT: | |
[1, 3, 5, 7] | |
<============================================================================ | |
>============================================================================ | |
fn sq(x) {x*x}; [1,2,3,4,5,6,7] map(sq) | |
test output: | |
RESULT: | |
[1, 4, 9, 16, 25, 36, 49] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7] map(\x[x*x]) | |
test output: | |
RESULT: | |
[1, 4, 9, 16, 25, 36, 49] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7] map \x[x*x] | |
test output: | |
RESULT: | |
[1, 4, 9, 16, 25, 36, 49] | |
<============================================================================ | |
>============================================================================ | |
fn sum(x) = x reduce(+,0); [1,2,3,4,5,6,7] sum | |
test output: | |
RESULT: | |
28 | |
<============================================================================ | |
>============================================================================ | |
fn prod(x) = x reduce(*,1); [1,2,3,4,5,6,7] prod | |
test output: | |
RESULT: | |
5040 | |
<============================================================================ | |
>============================================================================ | |
fn +/(x) = x reduce(+,0); [1,2,3,4,5,6,7] +/ | |
test output: | |
RESULT: | |
28 | |
<============================================================================ | |
>============================================================================ | |
fn */(x) = x reduce(*,1); [1,2,3,4,5,6,7] */ | |
test output: | |
RESULT: | |
5040 | |
<============================================================================ | |
>============================================================================ | |
fn ∑(x) = x reduce(+,0); ∑ [1,2,3,4,5,6,7] | |
test output: | |
RESULT: | |
28 | |
<============================================================================ | |
>============================================================================ | |
fn ∏(x) = x reduce(*,1); ∏ [1,2,3,4,5,6,7] | |
test output: | |
RESULT: | |
5040 | |
<============================================================================ | |
>============================================================================ | |
fn maximum(x) = x reduce1(max); [4,6,2,7,1,5,3] maximum | |
test output: | |
RESULT: | |
7 | |
<============================================================================ | |
>============================================================================ | |
fn minimum(x) = x reduce1(min); [4,6,2,7,1,5,3] minimum | |
test output: | |
RESULT: | |
1 | |
<============================================================================ | |
>============================================================================ | |
fn isOdd(x Int) { (x&1)==1 }; [1,3,5,7] all(isOdd) | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
fn isOdd(x Int) { (x&1)==1 }; [1,3,4,7] all(isOdd) | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
fn isOdd(x Int) { (x&1)==1 }; [1,3,5,8] all(isOdd) | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
fn isOdd(x Int) { (x&1)==1 }; [2,4,6,8] any(isOdd) | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
fn isOdd(x Int) { (x&1)==1 }; [2,4,5,8] any(isOdd) | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
fn isOdd(x Int) { (x&1)==1 }; [2,4,6,9] any(isOdd) | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
fn isOdd(x Int) { (x&1)==1 }; [2,4,6,9,10,12,13] isOdd | |
test output: | |
RESULT: | |
[false, false, false, true, false, false, true] | |
<============================================================================ | |
>============================================================================ | |
\x[(x&1)==1]([2,4,6,9,10,12,13]) | |
test output: | |
RESULT: | |
[false, false, false, true, false, false, true] | |
<============================================================================ | |
>============================================================================ | |
[0,1] pick(16) clump(2) | |
test output: | |
RESULT: | |
[[0, 1], [1, 1], [0, 1], [0, 0], [0, 1], [1, 1], [1, 1], [0, 1]] | |
<============================================================================ | |
>============================================================================ | |
fn sumIsOdd(a Int, b Int) { ((a+b)&1)==1 }; any([2,4,6,9], 2, sumIsOdd) | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
fn sumIsOdd(a Int, b Int) { ((a+b)&1)==1 }; any([2,4,6,8], 2, sumIsOdd) | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
fn sumIsOdd(a Int, b Int) { ((a+b)&1)==1 }; any([2,4,6,8], 1, sumIsOdd) | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
fn sumIsOdd(a Int, b Int) { ((a+b)&1)==1 }; any([2,4,6,8], [8,6,2,0], sumIsOdd) | |
test output: | |
RESULT: | |
false | |
<============================================================================ | |
>============================================================================ | |
fn sumIsOdd(a Int, b Int) { ((a+b)&1)==1 }; any([2,4,6,8], [8,6,3,0], sumIsOdd) | |
test output: | |
RESULT: | |
true | |
<============================================================================ | |
>============================================================================ | |
[{a:1,b:2},{a:3,b:4},{a:5,b:6},{a:7,b:8}].a -- field selection maps over arrays | |
test output: | |
RESULT: | |
[1, 3, 5, 7] | |
<============================================================================ | |
>============================================================================ | |
[{a:1,b:2},{a:3,b:4},{a:5,b:6},{a:7,b:8}].b | |
test output: | |
RESULT: | |
[2, 4, 6, 8] | |
<============================================================================ | |
>============================================================================ | |
[{a:1,b:2},{a:3,b:4},{x:5,b:6},{x:7,y:8}].a | |
test output: | |
RESULT: | |
[1, 3, nil, nil] | |
<============================================================================ | |
>============================================================================ | |
[{a:1,b:2},{a:3,b:4},{x:5,b:6},{x:7,y:8}] cyc .a | |
test output: | |
RESULT: | |
[1, 3, nil, nil, 1, 3, nil, nil, ...] | |
<============================================================================ | |
>============================================================================ | |
[{a:1,b:2},{a:3,b:4},{x:5,b:6},{x:7,y:8}] stutter(2) .a | |
test output: | |
RESULT: | |
[1, 1, 3, 3, nil, nil, nil, nil] | |
<============================================================================ | |
>============================================================================ | |
[{a:1,b:2},{a:3,b:4},{x:5,b:6},{x:7,y:8}] stutter(2) cyc .b | |
test output: | |
RESULT: | |
[2, 2, 4, 4, 6, 6, nil, nil, ...] | |
<============================================================================ | |
>============================================================================ | |
#f32[1,2,3,4,5] take(3) | |
test output: | |
RESULT: | |
#f32[1.f, 2.f, 3.f] | |
<============================================================================ | |
>============================================================================ | |
#i32[1,2,3,4,5] take(-3) | |
test output: | |
RESULT: | |
#i32[3, 4, 5] | |
<============================================================================ | |
>============================================================================ | |
#i32[1,2,3,4,5] drop(3) | |
test output: | |
RESULT: | |
#i32[4, 5] | |
<============================================================================ | |
>============================================================================ | |
#f32[1,2,3,4,5] drop(-3) | |
test output: | |
RESULT: | |
#f32[1.f, 2.f] | |
<============================================================================ | |
>============================================================================ | |
#f32[1,2,3,4,5,6,7] stride(1) | |
test output: | |
RESULT: | |
#f32[1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f] | |
<============================================================================ | |
>============================================================================ | |
#f32[1,2,3,4,5,6,7] stride(2) | |
test output: | |
RESULT: | |
#f32[1.f, 3.f, 5.f, 7.f] | |
<============================================================================ | |
>============================================================================ | |
#f32[1,2,3,4,5,6,7] stride(3) | |
test output: | |
RESULT: | |
#f32[1.f, 4.f, 7.f] | |
<============================================================================ | |
>============================================================================ | |
#f32[1,2,3,4,5,6,7] stride(-1) | |
test output: | |
RESULT: | |
#f32[7.f, 6.f, 5.f, 4.f, 3.f, 2.f, 1.f] | |
<============================================================================ | |
>============================================================================ | |
#f32[1,2,3,4,5,6,7] stride(-2) | |
test output: | |
RESULT: | |
#f32[7.f, 5.f, 3.f, 1.f] | |
<============================================================================ | |
>============================================================================ | |
#f32[1,2,3,4,5,6,7] stride(-3) | |
test output: | |
RESULT: | |
#f32[7.f, 4.f, 1.f] | |
<============================================================================ | |
>============================================================================ | |
#i32[1,2,3,4,5] stutter(2) | |
test output: | |
RESULT: | |
#i32[1, 1, 2, 2, 3, 3, 4, 4, 5, 5] | |
<============================================================================ | |
>============================================================================ | |
#i32[1,2,3,4,5] stutter(3) | |
test output: | |
RESULT: | |
#i32[1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5] | |
<============================================================================ | |
>============================================================================ | |
#i32[1,2,3,4,5] rotate(1) | |
test output: | |
RESULT: | |
#i32[5, 1, 2, 3, 4] | |
<============================================================================ | |
>============================================================================ | |
#i32[1,2,3,4,5] rotate(2) | |
test output: | |
RESULT: | |
#i32[4, 5, 1, 2, 3] | |
<============================================================================ | |
>============================================================================ | |
#i32[1,2,3,4,5] rotate(-1) | |
test output: | |
RESULT: | |
#i32[2, 3, 4, 5, 1] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5]/3 |> rotate(-2) | |
test output: | |
RESULT: | |
[1, 4/3, 5/3, 1/3, 2/3] | |
<============================================================================ | |
>============================================================================ | |
#r32[1,2,3,4,5,6,7] clump(1) | |
test output: | |
RESULT: | |
[ #r32[1/1], | |
. #r32[2/1], | |
. #r32[3/1], | |
. #r32[4/1], | |
. #r32[5/1], | |
. #r32[6/1], | |
. #r32[7/1]] | |
<============================================================================ | |
>============================================================================ | |
#i32[1,2,3,4,5,6,7] clump(2) | |
test output: | |
RESULT: | |
[#i32[1, 2], #i32[3, 4], #i32[5, 6]] | |
<============================================================================ | |
>============================================================================ | |
#i32[1,2,3,4,5,6,7] clump(3) | |
test output: | |
RESULT: | |
[#i32[1, 2, 3], #i32[4, 5, 6]] | |
<============================================================================ | |
>============================================================================ | |
#i32[1,2,3,4,5] reverse | |
test output: | |
RESULT: | |
#i32[5, 4, 3, 2, 1] | |
<============================================================================ | |
>============================================================================ | |
#i32[1,2,3,4,5] evenMirror | |
test output: | |
RESULT: | |
#i32[1, 2, 3, 4, 5, 5, 4, 3, 2, 1] | |
<============================================================================ | |
>============================================================================ | |
#i32[1,2,3,4,5] oddMirror | |
test output: | |
RESULT: | |
#i32[1, 2, 3, 4, 5, 4, 3, 2, 1] | |
<============================================================================ | |
>============================================================================ | |
#i32[1,2,3,4] ncyc(0) | |
test output: | |
RESULT: | |
#i32[] | |
<============================================================================ | |
>============================================================================ | |
#i32[1,2,3,4] ncyc(1) | |
test output: | |
RESULT: | |
#i32[1, 2, 3, 4] | |
<============================================================================ | |
>============================================================================ | |
#i32[1,2,3,4] ncyc(2) | |
test output: | |
RESULT: | |
#i32[1, 2, 3, 4, 1, 2, 3, 4] | |
<============================================================================ | |
>============================================================================ | |
#i32[1,2,3,4] ncyc(3) | |
test output: | |
RESULT: | |
#i32[1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] remove(1) | |
test output: | |
RESULT: | |
[2, 3, 4, 5] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] remove(3) | |
test output: | |
RESULT: | |
[1, 2, 4, 5] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] remove(5) | |
test output: | |
RESULT: | |
[1, 2, 3, 4] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] remove(7) | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5] | |
<============================================================================ | |
>============================================================================ | |
[1] remove(1) | |
test output: | |
RESULT: | |
[] | |
<============================================================================ | |
>============================================================================ | |
[] remove(1) | |
test output: | |
RESULT: | |
[] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] replace(1, 9) | |
test output: | |
RESULT: | |
[9, 2, 3, 4, 5] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] replace(3, 9) | |
test output: | |
RESULT: | |
[1, 2, 9, 4, 5] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] replace(5, 9) | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 9] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] replace(7, 9) | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5] | |
<============================================================================ | |
>============================================================================ | |
[1] replace(1, 9) | |
test output: | |
RESULT: | |
[9] | |
<============================================================================ | |
>============================================================================ | |
[] replace(1, 9) | |
test output: | |
RESULT: | |
[] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] remove(1, true, false) -- identity, unordered | |
test output: | |
RESULT: | |
[5, 2, 3, 4] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] remove(3, false, false) -- identity, unordered | |
test output: | |
RESULT: | |
[1, 2, 5, 4] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] remove(5, false, false) -- identity, unordered | |
test output: | |
RESULT: | |
[1, 2, 3, 4] | |
<============================================================================ | |
>============================================================================ | |
["a","b","c"] remove("a") | |
test output: | |
RESULT: | |
[b, c] | |
<============================================================================ | |
>============================================================================ | |
["a","b","c"] remove("b") | |
test output: | |
RESULT: | |
[a, c] | |
<============================================================================ | |
>============================================================================ | |
["a","b","c"] remove("c") | |
test output: | |
RESULT: | |
[a, b] | |
<============================================================================ | |
>============================================================================ | |
["a","b","c"] replace("a", "z") | |
test output: | |
RESULT: | |
[z, b, c] | |
<============================================================================ | |
>============================================================================ | |
["a","b","c"] replace("b", "z") | |
test output: | |
RESULT: | |
[a, z, c] | |
<============================================================================ | |
>============================================================================ | |
["a","b","c"] replace("c", "z") | |
test output: | |
RESULT: | |
[a, b, z] | |
<============================================================================ | |
>============================================================================ | |
["a","b","c"] remove("b", false) -- identity instead of equality | |
test output: | |
RESULT: | |
[a, b, c] | |
<============================================================================ | |
>============================================================================ | |
["a","b","c"] remove("a", true, false) -- unordered | |
test output: | |
RESULT: | |
[c, b] | |
<============================================================================ | |
>============================================================================ | |
(+)(5, 3) println | |
8 | |
test output: | |
RESULT: | |
8 | |
<============================================================================ | |
>============================================================================ | |
+(5, 3) println | |
CALL FRAMES SIZE 1 BASE 1 | |
0 ? lm 0x0 pc 0x0 sb 0 ssz 0 istry 0 ksz XXX | |
-> ? lm 0x12866ee20 pc 0x12a7d9a64 sb 0 ssz 1 ksz 2 | |
num args: 1 | |
0 Tuple | |
error: 3 No applicable method found for function '+'. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
(+)(5, 3)^2 println | |
64 | |
test output: | |
RESULT: | |
64 | |
<============================================================================ | |
>============================================================================ | |
(*)(5, 3) println | |
15 | |
test output: | |
RESULT: | |
15 | |
<============================================================================ | |
>============================================================================ | |
(min)(5, 3) println | |
3 | |
test output: | |
RESULT: | |
3 | |
<============================================================================ | |
>============================================================================ | |
(max)(5, 3) println | |
5 | |
test output: | |
RESULT: | |
5 | |
<============================================================================ | |
>============================================================================ | |
5 (max)(3) println | |
ast: | |
[astDo, [astCall, println, [astCall, max, 5, 3]]] | |
chunk code ----- | |
0 codePushSmallInt 5 | |
1 codePushSmallInt 3 | |
2 codePushGlobalVar 0 max | |
3 codeApply 2 | |
4 codePushGlobalVar 1 println | |
5 codeApply 1 | |
6 codeReturn | |
test output: | |
RESULT: | |
nil | |
<============================================================================ | |
>============================================================================ | |
5 (max)(3) println | |
5 | |
test output: | |
RESULT: | |
5 | |
<============================================================================ | |
>============================================================================ | |
let x = 5; x (max)(3) println | |
CALL FRAMES SIZE 1 BASE 1 | |
0 ? lm 0x0 pc 0x0 sb 0 ssz 0 istry 0 ksz XXX | |
-> ? lm 0x12866c2a0 pc 0x129b77cdc sb 0 ssz 3 ksz 4 | |
num args: 2 | |
0 I64 | |
1 GF | |
error: 3 No applicable method found for function 'call'. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
let x = 5; x (max)(3) println | |
ast: | |
[ astDo, | |
. [astLet, [astVarPattern, x], 5], | |
. [astCall, println, [astCall, [astCall, x, max], 3]]] | |
chunk code ----- | |
0 codePushSmallInt 5 | |
1 codeAssign 0 <GlobalVarPattern> | |
2 codeDrop | |
3 codePushSmallInt 3 | |
4 codePushGlobalVar 1 max | |
5 codePushGlobalVar 2 x | |
6 codeApply 1 | |
7 codeApply 1 | |
8 codePushGlobalVar 3 println | |
9 codeApply 1 | |
10 codeReturn | |
test output: | |
RESULT: | |
nil | |
<============================================================================ | |
>============================================================================ | |
["a", "bc", "cde"] getsym println | |
[a, bc, cde] | |
test output: | |
RESULT: | |
[a, bc, cde] | |
<============================================================================ | |
>============================================================================ | |
["a", "bc", "cde"] + "z" |> println | |
[az, bcz, cdez] | |
test output: | |
RESULT: | |
[az, bcz, cdez] | |
<============================================================================ | |
>============================================================================ | |
["a", "bc", "cde"] * 3 |> println | |
[aaa, bcbcbc, cdecdecde] | |
test output: | |
RESULT: | |
[aaa, bcbcbc, cdecdecde] | |
<============================================================================ | |
>============================================================================ | |
[123, 456, 789] hexstr println | |
[0x7b, 0x1c8, 0x315] | |
test output: | |
RESULT: | |
[0x7b, 0x1c8, 0x315] | |
<============================================================================ | |
>============================================================================ | |
[{a:1}, {b:2}, {c:3}] addAll({y:8, z:9}) println | |
[{a:1, y:8, z:9}, {b:2, y:8, z:9}, {c:3, y:8, z:9}] | |
test output: | |
RESULT: | |
[{a: 1, y: 8, z: 9}, {b: 2, y: 8, z: 9}, {c: 3, y: 8, z: 9}] | |
<============================================================================ | |
>============================================================================ | |
{y:8, z:9} addAll([{a:1}, {b:2}, {c:3}]) println | |
{y:8, z:9, a:1, b:2, c:3} | |
test output: | |
RESULT: | |
{y: 8, z: 9, a: 1, b: 2, c: 3} | |
<============================================================================ | |
>============================================================================ | |
[{u:6, v:7}, {y:8, z:9}] addAll([{a:1}, {b:2}, {c:3}]) println | |
[{u:6, v:7, a:1, b:2, c:3}, {y:8, z:9, a:1, b:2, c:3}] | |
test output: | |
RESULT: | |
[{u: 6, v: 7, a: 1, b: 2, c: 3}, {y: 8, z: 9, a: 1, b: 2, c: 3}] | |
<============================================================================ | |
>============================================================================ | |
[{a:1}, {b:2}, {c:3}] addAll([{u:6, v:7}, {y:8, z:9}]) println | |
[{a:1, u:6, v:7, y:8, z:9}, {b:2, u:6, v:7, y:8, z:9}, {c:3, u:6, v:7, y:8, z:9}] | |
test output: | |
RESULT: | |
[ {a: 1, u: 6, v: 7, y: 8, z: 9}, | |
. {b: 2, u: 6, v: 7, y: 8, z: 9}, | |
. {c: 3, u: 6, v: 7, y: 8, z: 9}] | |
<============================================================================ | |
>============================================================================ | |
[{a:1}, {b:2}, {c:3}] addAll([{s:4, t:5}, {u:6, v:7}, {y:8, z:9}]) println | |
[{a:1, s:4, t:5, u:6, v:7, y:8, z:9}, {b:2, s:4, t:5, u:6, v:7, y:8, z:9}, {c:3, s:4, t:5, u:6, v:7, y:8, z:9}] | |
test output: | |
RESULT: | |
[ {a: 1, s: 4, t: 5, u: 6, v: 7, y: 8, z: 9}, | |
. {b: 2, s: 4, t: 5, u: 6, v: 7, y: 8, z: 9}, | |
. {c: 3, s: 4, t: 5, u: 6, v: 7, y: 8, z: 9}] | |
<============================================================================ | |
>============================================================================ | |
[{a:1}, [{b:2}, {c:3}]] addAll([[{s:4, t:5}, {u:6, v:7}], {y:8, z:9}]) println | |
[{a:1, s:4, t:5, u:6, v:7, y:8, z:9}, [{b:2, s:4, t:5, u:6, v:7, y:8, z:9}, {c:3, s:4, t:5, u:6, v:7, y:8, z:9}]] | |
test output: | |
RESULT: | |
[ {a: 1, s: 4, t: 5, u: 6, v: 7, y: 8, z: 9}, | |
. [ {b: 2, s: 4, t: 5, u: 6, v: 7, y: 8, z: 9}, | |
. . {c: 3, s: 4, t: 5, u: 6, v: 7, y: 8, z: 9}]] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3] cyc take(16) | |
test output: | |
RESULT: | |
[1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3] ncyc(3) take(16) | |
test output: | |
RESULT: | |
[1, 2, 3, 1, 2, 3, 1, 2, 3] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3] ncyc(1) take(16) | |
test output: | |
RESULT: | |
[1, 2, 3] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3] ncyc(0) take(16) | |
test output: | |
RESULT: | |
[] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7,8,9] take(0) | |
test output: | |
RESULT: | |
[] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7,8,9] take(5) | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7,8,9] drop(0) take(16) | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5, 6, 7, 8, 9] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7,8,9] drop(5) take(16) | |
test output: | |
RESULT: | |
[6, 7, 8, 9] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7,8,9] stride(-1) take(16) | |
test output: | |
RESULT: | |
[9, 8, 7, 6, 5, 4, 3, 2, 1] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7,8,9] stride(0) take(16) | |
test output: | |
RESULT: | |
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7,8,9] stride(2) take(16) | |
test output: | |
RESULT: | |
[1, 3, 5, 7, 9] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7,8,9] stride(5) take(16) | |
test output: | |
RESULT: | |
[1, 6] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7,8,9] stride(8) take(16) | |
test output: | |
RESULT: | |
[1, 9] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7,8,9] stride(200) take(16) | |
test output: | |
RESULT: | |
[1] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7,8,9] stutter(3) take(16) | |
test output: | |
RESULT: | |
[1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7,8,9] stutter(2) take(16) | |
test output: | |
RESULT: | |
[1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7,8,9] stutter(1) take(16) | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5, 6, 7, 8, 9] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7,8,9] stutter(0) take(16) -- stutter is clamped below at 1 | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5, 6, 7, 8, 9] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5,6,7,8,9] stutter(-1) take(16) -- stutter is clamped below at 1 | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5, 6, 7, 8, 9] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) take(0) take(16) | |
test output: | |
RESULT: | |
[] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) take(5) take(16) | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) drop(0) take(16) | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) drop(5) take(16) | |
test output: | |
RESULT: | |
[6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) stride(-1) take(16) | |
error: 16 stride: stride cannot be negative on indefinite length list. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
by(1,1) take(16) stride(-1) | |
test output: | |
RESULT: | |
[16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) stride(0) take(16) | |
test output: | |
RESULT: | |
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) stride(2) take(16) | |
test output: | |
RESULT: | |
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) stride(5) take(16) | |
test output: | |
RESULT: | |
[1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56, 61, 66, 71, 76] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) stride(8) take(16) | |
test output: | |
RESULT: | |
[1, 9, 17, 25, 33, 41, 49, 57, 65, 73, 81, 89, 97, 105, 113, 121] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) stride(200) take(16) | |
test output: | |
RESULT: | |
[ 1, | |
. 201, | |
. 401, | |
. 601, | |
. 801, | |
. 1001, | |
. 1201, | |
. 1401, | |
. 1601, | |
. 1801, | |
. 2001, | |
. 2201, | |
. 2401, | |
. 2601, | |
. 2801, | |
. 3001] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) stutter(3) take(16) | |
test output: | |
RESULT: | |
[1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) stutter(2) take(16) | |
test output: | |
RESULT: | |
[1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) stutter(1) take(16) | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) stutter(0) take(16) | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) stutter(-1) take(16) | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4] picks take(16) | |
test output: | |
RESULT: | |
[2, 1, 4, 4, 4, 4, 1, 3, 1, 1, 4, 1, 4, 4, 1, 2] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4] xpicks take(16) | |
test output: | |
RESULT: | |
[3, 4, 2, 3, 2, 4, 3, 1, 2, 4, 1, 3, 4, 2, 1, 2] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) map(sqrt) take(16) | |
test output: | |
RESULT: | |
[ 1., | |
. 1.4142135623730951, | |
. 1.7320508075688772, | |
. 2., | |
. 2.23606797749979, | |
. 2.449489742783178, | |
. 2.6457513110645907, | |
. 2.8284271247461903, | |
. 3., | |
. 3.1622776601683795, | |
. 3.3166247903554, | |
. 3.4641016151377544, | |
. 3.605551275463989, | |
. 3.7416573867739413, | |
. 3.872983346207417, | |
. 4.] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) map \x[x*x] take(16) | |
test output: | |
RESULT: | |
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256] | |
<============================================================================ | |
>============================================================================ | |
fn isOdd(x Int) = (x&1)==1; by(1,1) filter(isOdd) take(16) | |
test output: | |
RESULT: | |
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31] | |
<============================================================================ | |
>============================================================================ | |
fn isTri(x Int) = (x%3)==0; by(1,1) filter(isTri) take(16) | |
test output: | |
RESULT: | |
[3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) scan(+,0) take(16) | |
test output: | |
RESULT: | |
[1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) scan1(+) take(16) | |
test output: | |
RESULT: | |
[1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136] | |
<============================================================================ | |
>============================================================================ | |
by(0,5) take(16) | |
test output: | |
RESULT: | |
[0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75] | |
<============================================================================ | |
>============================================================================ | |
by(7,4) take(16) | |
test output: | |
RESULT: | |
[7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, 67] | |
<============================================================================ | |
>============================================================================ | |
by([10, 20], 3) take(16) | |
test output: | |
RESULT: | |
[ [10, 20], | |
. [13, 23], | |
. [16, 26], | |
. [19, 29], | |
. [22, 32], | |
. [25, 35], | |
. [28, 38], | |
. [31, 41], | |
. [34, 44], | |
. [37, 47], | |
. [40, 50], | |
. [43, 53], | |
. [46, 56], | |
. [49, 59], | |
. [52, 62], | |
. [55, 65]] | |
<============================================================================ | |
>============================================================================ | |
by(3, [10, 20]) take(16) | |
test output: | |
RESULT: | |
[ 3, | |
. [13, 23], | |
. [23, 43], | |
. [33, 63], | |
. [43, 83], | |
. [53, 103], | |
. [63, 123], | |
. [73, 143], | |
. [83, 163], | |
. [93, 183], | |
. [103, 203], | |
. [113, 223], | |
. [123, 243], | |
. [133, 263], | |
. [143, 283], | |
. [153, 303]] | |
<============================================================================ | |
>============================================================================ | |
geo(1,2) take(16) | |
test output: | |
RESULT: | |
#i64[ | |
. 1, | |
. 2, | |
. 4, | |
. 8, | |
. 16, | |
. 32, | |
. 64, | |
. 128, | |
. 256, | |
. 512, | |
. 1024, | |
. 2048, | |
. 4096, | |
. 8192, | |
. 16384, | |
. 32768] | |
<============================================================================ | |
>============================================================================ | |
geo(2,3) take(16) | |
test output: | |
RESULT: | |
#i64[ | |
. 2, | |
. 6, | |
. 18, | |
. 54, | |
. 162, | |
. 486, | |
. 1458, | |
. 4374, | |
. 13122, | |
. 39366, | |
. 118098, | |
. 354294, | |
. 1062882, | |
. 3188646, | |
. 9565938, | |
. 28697814] | |
<============================================================================ | |
>============================================================================ | |
geo(2,[5,3]) take(16) | |
test output: | |
RESULT: | |
[ 2, | |
. [10, 6], | |
. [50, 18], | |
. [250, 54], | |
. [1250, 162], | |
. [6250, 486], | |
. [31250, 1458], | |
. [156250, 4374], | |
. [781250, 13122], | |
. [3906250, 39366], | |
. [19531250, 118098], | |
. [97656250, 354294], | |
. [488281250, 1062882], | |
. [2441406250, 3188646], | |
. [12207031250, 9565938], | |
. [61035156250, 28697814]] | |
<============================================================================ | |
>============================================================================ | |
by(1,2) | |
test output: | |
RESULT: | |
[1, 3, 5, 7, 9, 11, 13, 15, ...] | |
<============================================================================ | |
>============================================================================ | |
by(1,2) class println | |
List_obj | |
test output: | |
RESULT: | |
List_obj | |
<============================================================================ | |
>============================================================================ | |
by(1,1) take(7) | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5, 6, 7] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) take(8) | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5, 6, 7, 8] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) take(9) | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5, 6, 7, 8, 9] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) take(9) take(1k) | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5, 6, 7, 8, 9] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) take(1h) | |
test output: | |
RESULT: | |
[ 1, | |
. 2, | |
. 3, | |
. 4, | |
. 5, | |
. 6, | |
. 7, | |
. 8, | |
. 9, | |
. 10, | |
. 11, | |
. 12, | |
. 13, | |
. 14, | |
. 15, | |
. 16, | |
. 17, | |
. 18, | |
. 19, | |
. 20, | |
. ...] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5, 6, 7, 8, ...] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) take(3) | |
test output: | |
RESULT: | |
[1, 2, 3] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) take(3) cyc | |
test output: | |
RESULT: | |
[1, 2, 3, 1, 2, 3, 1, 2, ...] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) take(3) ncyc(-1) | |
test output: | |
RESULT: | |
[] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) take(3) ncyc(0) | |
test output: | |
RESULT: | |
[] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) take(3) ncyc(1) | |
test output: | |
RESULT: | |
[1, 2, 3] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) take(3) ncyc(2) | |
test output: | |
RESULT: | |
[1, 2, 3, 1, 2, 3] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) take(3) ncyc(3) | |
test output: | |
RESULT: | |
[1, 2, 3, 1, 2, 3, 1, 2, 3] | |
<============================================================================ | |
>============================================================================ | |
fn MyPlus(a Number, b Number) = a+b; MyPlus([1,2,3,4], [10,20,30,40]) | |
test output: | |
RESULT: | |
[11, 22, 33, 44] | |
<============================================================================ | |
>============================================================================ | |
fn MyPlus(a Number, b Number) = a+b; MyPlus([1,2,3,4] asList, [10,20,30,40]) take(16) | |
test output: | |
RESULT: | |
[11, 22, 33, 44] | |
<============================================================================ | |
>============================================================================ | |
fn MyPlus(a Number, b Number) = a+b; MyPlus([1,2,3,4], [10,20,30,40] asList) take(16) | |
test output: | |
RESULT: | |
[11, 22, 33, 44] | |
<============================================================================ | |
>============================================================================ | |
fn MyPlus(a Number, b Number) = a+b; MyPlus([1,2,3,4] asList, [10,20,30,40] asList) take(16) | |
test output: | |
RESULT: | |
[11, 22, 33, 44] | |
<============================================================================ | |
>============================================================================ | |
fn MyPlus(a, b) = a+b; MyPlus([1,2,3,4], [10,20,30,40]) | |
test output: | |
RESULT: | |
[11, 22, 33, 44] | |
<============================================================================ | |
>============================================================================ | |
fn MyPlus(a, b) = a+b; MyPlus([1,2,3,4] asList, [10,20,30,40]) take(16) | |
test output: | |
RESULT: | |
[11, 22, 33, 44] | |
<============================================================================ | |
>============================================================================ | |
fn MyPlus(a, b) = a+b; MyPlus([1,2,3,4], [10,20,30,40] asList) take(16) | |
test output: | |
RESULT: | |
[11, 22, 33, 44] | |
<============================================================================ | |
>============================================================================ | |
fn MyPlus(a, b) = a+b; MyPlus([1,2,3,4] asList, [10,20,30,40] asList) take(16) | |
test output: | |
RESULT: | |
[11, 22, 33, 44] | |
<============================================================================ | |
>============================================================================ | |
let x = [1,2,3,4]; (x head, x tail, x tail tail, 9 cons(x)) println | |
(1, [2, 3, 4], [3, 4], [9, 1, 2, 3, 4]) | |
test output: | |
RESULT: | |
(1, [2, 3, 4], [3, 4], [9, 1, 2, 3, 4]) | |
<============================================================================ | |
>============================================================================ | |
1 cons(3) println | |
[1, 3] | |
test output: | |
RESULT: | |
[1, 3] | |
<============================================================================ | |
>============================================================================ | |
1 cons(3 once) println | |
[1, 3] | |
test output: | |
RESULT: | |
[1, 3] | |
<============================================================================ | |
>============================================================================ | |
by(by(1,1),by(1,1)) | |
test output: | |
RESULT: | |
[ [1, 2, 3, 4, 5, 6, 7, 8, ...], | |
. [2, 4, 6, 8, 10, 12, 14, 16, ...], | |
. [3, 6, 9, 12, 15, 18, 21, 24, ...], | |
. [4, 8, 12, 16, 20, 24, 28, 32, ...], | |
. [5, 10, 15, 20, 25, 30, 35, 40, ...], | |
. [6, 12, 18, 24, 30, 36, 42, 48, ...], | |
. [7, 14, 21, 28, 35, 42, 49, 56, ...], | |
. [8, 16, 24, 32, 40, 48, 56, 64, ...], | |
. ...] | |
<============================================================================ | |
>============================================================================ | |
by(by(1,1) @1,by(1,1) @2) | |
test output: | |
RESULT: | |
[ [ [1, 2, 3, 4, 5, 6, 7, 8, ...], | |
. . [1, 3, 5, 7, 9, 11, 13, 15, ...], | |
. . [1, 4, 7, 10, 13, 16, 19, 22, ...], | |
. . [1, 5, 9, 13, 17, 21, 25, 29, ...], | |
. . [1, 6, 11, 16, 21, 26, 31, 36, ...], | |
. . [1, 7, 13, 19, 25, 31, 37, 43, ...], | |
. . [1, 8, 15, 22, 29, 36, 43, 50, ...], | |
. . [1, 9, 17, 25, 33, 41, 49, 57, ...], | |
. . ...], | |
. [ [2, 3, 4, 5, 6, 7, 8, 9, ...], | |
. . [2, 4, 6, 8, 10, 12, 14, 16, ...], | |
. . [2, 5, 8, 11, 14, 17, 20, 23, ...], | |
. . [2, 6, 10, 14, 18, 22, 26, 30, ...], | |
. . [2, 7, 12, 17, 22, 27, 32, 37, ...], | |
. . [2, 8, 14, 20, 26, 32, 38, 44, ...], | |
. . [2, 9, 16, 23, 30, 37, 44, 51, ...], | |
. . [2, 10, 18, 26, 34, 42, 50, 58, ...], | |
. . ...], | |
. [ [3, 4, 5, 6, 7, 8, 9, 10, ...], | |
. . [3, 5, 7, 9, 11, 13, 15, 17, ...], | |
. . [3, 6, 9, 12, 15, 18, 21, 24, ...], | |
. . [3, 7, 11, 15, 19, 23, 27, 31, ...], | |
. . [3, 8, 13, 18, 23, 28, 33, 38, ...], | |
. . [3, 9, 15, 21, 27, 33, 39, 45, ...], | |
. . [3, 10, 17, 24, 31, 38, 45, 52, ...], | |
. . [3, 11, 19, 27, 35, 43, 51, 59, ...], | |
. . ...], | |
. [ [4, 5, 6, 7, 8, 9, 10, 11, ...], | |
. . [4, 6, 8, 10, 12, 14, 16, 18, ...], | |
. . [4, 7, 10, 13, 16, 19, 22, 25, ...], | |
. . [4, 8, 12, 16, 20, 24, 28, 32, ...], | |
. . [4, 9, 14, 19, 24, 29, 34, 39, ...], | |
. . [4, 10, 16, 22, 28, 34, 40, 46, ...], | |
. . [4, 11, 18, 25, 32, 39, 46, 53, ...], | |
. . [4, 12, 20, 28, 36, 44, 52, 60, ...], | |
. . ...], | |
. [ [5, 6, 7, 8, 9, 10, 11, 12, ...], | |
. . [5, 7, 9, 11, 13, 15, 17, 19, ...], | |
. . [5, 8, 11, 14, 17, 20, 23, 26, ...], | |
. . [5, 9, 13, 17, 21, 25, 29, 33, ...], | |
. . [5, 10, 15, 20, 25, 30, 35, 40, ...], | |
. . [5, 11, 17, 23, 29, 35, 41, 47, ...], | |
. . [5, 12, 19, 26, 33, 40, 47, 54, ...], | |
. . [5, 13, 21, 29, 37, 45, 53, 61, ...], | |
. . ...], | |
. [ [6, 7, 8, 9, 10, 11, 12, 13, ...], | |
. . [6, 8, 10, 12, 14, 16, 18, 20, ...], | |
. . [6, 9, 12, 15, 18, 21, 24, 27, ...], | |
. . [6, 10, 14, 18, 22, 26, 30, 34, ...], | |
. . [6, 11, 16, 21, 26, 31, 36, 41, ...], | |
. . [6, 12, 18, 24, 30, 36, 42, 48, ...], | |
. . [6, 13, 20, 27, 34, 41, 48, 55, ...], | |
. . [6, 14, 22, 30, 38, 46, 54, 62, ...], | |
. . ...], | |
. [ [7, 8, 9, 10, 11, 12, 13, 14, ...], | |
. . [7, 9, 11, 13, 15, 17, 19, 21, ...], | |
. . [7, 10, 13, 16, 19, 22, 25, 28, ...], | |
. . [7, 11, 15, 19, 23, 27, 31, 35, ...], | |
. . [7, 12, 17, 22, 27, 32, 37, 42, ...], | |
. . [7, 13, 19, 25, 31, 37, 43, 49, ...], | |
. . [7, 14, 21, 28, 35, 42, 49, 56, ...], | |
. . [7, 15, 23, 31, 39, 47, 55, 63, ...], | |
. . ...], | |
. [ [8, 9, 10, 11, 12, 13, 14, 15, ...], | |
. . [8, 10, 12, 14, 16, 18, 20, 22, ...], | |
. . [8, 11, 14, 17, 20, 23, 26, 29, ...], | |
. . [8, 12, 16, 20, 24, 28, 32, 36, ...], | |
. . [8, 13, 18, 23, 28, 33, 38, 43, ...], | |
. . [8, 14, 20, 26, 32, 38, 44, 50, ...], | |
. . [8, 15, 22, 29, 36, 43, 50, 57, ...], | |
. . [8, 16, 24, 32, 40, 48, 56, 64, ...], | |
. . ...], | |
. ...] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) + by(100,100) |> take(16) println | |
[101, 202, 303, 404, 505, 606, 707, 808, 909, 1010, 1111, 1212, 1313, 1414, 1515, 1616] | |
test output: | |
RESULT: | |
[ 101, | |
. 202, | |
. 303, | |
. 404, | |
. 505, | |
. 606, | |
. 707, | |
. 808, | |
. 909, | |
. 1010, | |
. 1111, | |
. 1212, | |
. 1313, | |
. 1414, | |
. 1515, | |
. 1616] | |
<============================================================================ | |
>============================================================================ | |
let a = 0 inlet | |
let b = 0 inlet | |
let c = a - b | |
a set(2) | |
c get println | |
b set(3) | |
c get println | |
a set(10) | |
c get println | |
2 | |
-1 | |
7 | |
test output: | |
RESULT: | |
7 | |
<============================================================================ | |
>============================================================================ | |
let a = 0 inlet | |
let b = 0 inlet | |
let c = 1 inlet | |
let d = (a - b) / c | |
a set(2) | |
d get println | |
b set(5) | |
d get println | |
a set(10) | |
d get println | |
c set(3) | |
d get println | |
b set(3) | |
d get println | |
2 | |
-3 | |
5 | |
5/3 | |
7/3 | |
test output: | |
RESULT: | |
7/3 | |
<============================================================================ | |
>============================================================================ | |
let a = 0 inlet | |
let b = 0 inlet | |
let c = a - b |> action \x["The result is %1 !" fmt(x) println] | |
a set(2); react() | |
b set(3); react() | |
a set(10); react() | |
a set(17); react() | |
b set(8); react() | |
a set(by(10,10)); react() | |
The result is 2 ! | |
The result is -1 ! | |
The result is 7 ! | |
The result is 14 ! | |
The result is 9 ! | |
The result is [2, 12, 22, 32, 42, 52, 62, 72, 82...] ! | |
test output: | |
RESULT: | |
nil | |
<============================================================================ | |
>============================================================================ | |
let a = 0 inlet | |
let b = 0 inlet | |
let c = a - b |> action \x["The result is %1 !" fmt(x) println] | |
a set(2); | |
b set(3); | |
a set(10); react() | |
a set(17); | |
b set(8); react() | |
a set(by(10,10)); react() | |
The result is 7 ! | |
The result is 9 ! | |
The result is [2, 12, 22, 32, 42, 52, 62, 72, 82...] ! | |
test output: | |
RESULT: | |
nil | |
<============================================================================ | |
>============================================================================ | |
let a = true inlet | |
let b = true inlet | |
let c = r_and(a,b) action \x["The result is %1 !" fmt(x) println] | |
"a set(true )" println; a set(true ); react() | |
"a set(true )" println; b set(true ); react() | |
"b set(false)" println; b set(false); react() | |
"a set(false)" println; a set(false); react() | |
"b set(true )" println; b set(true ); react() | |
"a set(true )" println; a set(true ); react() | |
"a set(false)" println; a set(false); react() | |
"b set(false)" println; b set(false); react() | |
a set(true ) | |
a set(true ) | |
b set(false) | |
The result is false ! | |
a set(false) | |
b set(true ) | |
a set(true ) | |
The result is true ! | |
a set(false) | |
The result is false ! | |
b set(false) | |
test output: | |
RESULT: | |
nil | |
<============================================================================ | |
>============================================================================ | |
let a = false inlet | |
let b = false inlet | |
let c = r_or(a,b) action \x["The result is %1 !" fmt(x) println] | |
"a set(false)" println; a set(false); react() | |
"a set(false)" println; b set(false); react() | |
"b set(true )" println; b set(true ); react() | |
"a set(true )" println; a set(true ); react() | |
"b set(false)" println; b set(false); react() | |
"a set(false)" println; a set(false); react() | |
"a set(true )" println; a set(true ); react() | |
"b set(true )" println; b set(true ); react() | |
a set(false) | |
a set(false) | |
b set(true ) | |
The result is true ! | |
a set(true ) | |
b set(false) | |
a set(false) | |
The result is false ! | |
a set(true ) | |
The result is true ! | |
b set(true ) | |
test output: | |
RESULT: | |
nil | |
<============================================================================ | |
>============================================================================ | |
let a = false inlet | |
let b = 1 inlet | |
let c = r_gate(a,b) action \x["The result is %1 !" fmt(x) println] | |
"a set(false)" println; a set(false); react() | |
"b set(2)" println; b set(2); react() | |
"a set(true )" println; a set(true ); react() | |
"b set(3)" println; b set(3); react() | |
"b set(4)" println; b set(4); react() | |
"a set(false)" println; a set(false); react() | |
"b set(5)" println; b set(5); react() | |
"b set(6)" println; b set(6); react() | |
"a set(true )" println; a set(true ); react() | |
"a set(true )" println; a set(true ); react() | |
"a set(false)" println; a set(false); react() | |
"a set(true )" println; a set(true ); react() | |
"b set(7)" println; b set(7); react() | |
a set(false) | |
b set(2) | |
a set(true ) | |
The result is 2 ! | |
b set(3) | |
The result is 3 ! | |
b set(4) | |
The result is 4 ! | |
a set(false) | |
b set(5) | |
b set(6) | |
a set(true ) | |
The result is 6 ! | |
a set(true ) | |
a set(false) | |
a set(true ) | |
b set(7) | |
The result is 7 ! | |
test output: | |
RESULT: | |
nil | |
<============================================================================ | |
>============================================================================ | |
let a = false inlet | |
let b = 1 inlet | |
let c = r_latch(a,b) action \x["The result is %1 !" fmt(x) println] | |
"a set(false)" println; a set(false); react() | |
"b set(2)" println; b set(2); react() | |
"a set(true )" println; a set(true ); react() | |
"b set(3)" println; b set(3); react() | |
"b set(4)" println; b set(4); react() | |
"a set(false)" println; a set(false); react() | |
"b set(5)" println; b set(5); react() | |
"b set(6)" println; b set(6); react() | |
"a set(true )" println; a set(true ); react() | |
"a set(true )" println; a set(true ); react() | |
"a set(false)" println; a set(false); react() | |
"a set(true )" println; a set(true ); react() | |
"b set(7)" println; b set(7); react() | |
a set(false) | |
b set(2) | |
a set(true ) | |
The result is 2 ! | |
b set(3) | |
b set(4) | |
a set(false) | |
The result is 4 ! | |
b set(5) | |
b set(6) | |
a set(true ) | |
The result is 6 ! | |
a set(true ) | |
a set(false) | |
a set(true ) | |
b set(7) | |
test output: | |
RESULT: | |
nil | |
<============================================================================ | |
>============================================================================ | |
-- field selection on a reactive stream | |
let r = nil inlet | |
let y = r .a action \x["A: %1" fmt(x) println] | |
let z = r .b action \x["B: %1" fmt(x) println] | |
"r set({a:1,b:2})" println; r set({a:1,b:2}); react() | |
"r set({a:3,b:2})" println; r set({a:3,b:2}); react() | |
"r set({a:3,b:4})" println; r set({a:3,b:4}); react() | |
"r set({a:5,b:4})" println; r set({a:5,b:4}); react() | |
"r set({a:5,b:6})" println; r set({a:5,b:6}); react() | |
"r set({a:7,b:8})" println; r set({a:7,b:8}); react() | |
"r set({x:5,y:6})" println; r set({x:5,y:6}); react() | |
"r set({x:5,b:9})" println; r set({x:5,b:9}); react() | |
"r set({a:10,y:9})" println; r set({a:10,y:9}); react() | |
r set({a:1,b:2}) | |
B: 2 | |
A: 1 | |
r set({a:3,b:2}) | |
A: 3 | |
r set({a:3,b:4}) | |
B: 4 | |
r set({a:5,b:4}) | |
A: 5 | |
r set({a:5,b:6}) | |
B: 6 | |
r set({a:7,b:8}) | |
B: 8 | |
A: 7 | |
r set({x:5,y:6}) | |
B: nil | |
A: nil | |
r set({x:5,b:9}) | |
B: 9 | |
r set({a:10,y:9}) | |
B: nil | |
A: 10 | |
test output: | |
RESULT: | |
nil | |
<============================================================================ | |
>============================================================================ | |
-- field selection on a reactive stream | |
let f = \x[x !== nil] | |
let r = nil inlet | |
let y = r .a filter(f) action \x["A: %1" fmt(x) println] | |
let z = r .b filter(f) action \x["B: %1" fmt(x) println] | |
"r set({a:1,b:2})" println; r set({a:1,b:2}); react() | |
"r set({a:3,b:2})" println; r set({a:3,b:2}); react() | |
"r set({a:3,b:4})" println; r set({a:3,b:4}); react() | |
"r set({a:5,b:4})" println; r set({a:5,b:4}); react() | |
"r set({a:5,b:6})" println; r set({a:5,b:6}); react() | |
"r set({a:7,b:8})" println; r set({a:7,b:8}); react() | |
"r set({x:5,y:6})" println; r set({x:5,y:6}); react() | |
"r set({x:5,b:9})" println; r set({x:5,b:9}); react() | |
"r set({a:10,y:9})" println; r set({a:10,y:9}); react() | |
r set({a:1,b:2}) | |
B: 2 | |
A: 1 | |
r set({a:3,b:2}) | |
A: 3 | |
r set({a:3,b:4}) | |
B: 4 | |
r set({a:5,b:4}) | |
A: 5 | |
r set({a:5,b:6}) | |
B: 6 | |
r set({a:7,b:8}) | |
B: 8 | |
A: 7 | |
r set({x:5,y:6}) | |
r set({x:5,b:9}) | |
B: 9 | |
r set({a:10,y:9}) | |
A: 10 | |
test output: | |
RESULT: | |
nil | |
<============================================================================ | |
>============================================================================ | |
-- field selection on a reactive stream | |
let f = \x[r_gate(scalarNotIdentical(x,nil), x)] | |
(nil !== nil) println | |
(1 !== nil) println | |
let r = nil inlet | |
let y = r .a f action \x["A: %1" fmt(x) println] | |
let z = r .b f action \x["B: %1" fmt(x) println] | |
"r set({a:1,b:2})" println; r set({a:1,b:2}); react() | |
"r set({a:3,b:2})" println; r set({a:3,b:2}); react() | |
"r set({a:3,b:4})" println; r set({a:3,b:4}); react() | |
"r set({a:5,b:4})" println; r set({a:5,b:4}); react() | |
"r set({a:5,b:6})" println; r set({a:5,b:6}); react() | |
"r set({a:7,b:8})" println; r set({a:7,b:8}); react() | |
"r set({x:5,y:6})" println; r set({x:5,y:6}); react() | |
"r set({x:5,b:9})" println; r set({x:5,b:9}); react() | |
"r set({a:10,y:9})" println; r set({a:10,y:9}); react() | |
false | |
true | |
r set({a:1,b:2}) | |
B: 2 | |
A: 1 | |
r set({a:3,b:2}) | |
A: 3 | |
r set({a:3,b:4}) | |
B: 4 | |
r set({a:5,b:4}) | |
A: 5 | |
r set({a:5,b:6}) | |
B: 6 | |
r set({a:7,b:8}) | |
B: 8 | |
A: 7 | |
r set({x:5,y:6}) | |
r set({x:5,b:9}) | |
B: 9 | |
r set({a:10,y:9}) | |
A: 10 | |
test output: | |
RESULT: | |
nil | |
<============================================================================ | |
>============================================================================ | |
-- field selection on a reactive stream | |
let r = nil inlet | |
let y = r .a action \x["A: %1" fmt(x) println] | |
let z = r .b action \x["B: %1" fmt(x) println] | |
"r set({a:1,b:2})" println; r set({a:1,b:2}); react() | |
"r set({a:3,b:2})" println; r set({a:3,b:2}); | |
"r set({a:3,b:4})" println; r set({a:3,b:4}); react() | |
"r set({a:5,b:4})" println; r set({a:5,b:4}); | |
"r set({a:5,b:6})" println; r set({a:5,b:6}); react() | |
"r set({a:7,b:8})" println; r set({a:7,b:8}); | |
"r set({x:5,y:6})" println; r set({x:5,y:6}); react() | |
"r set({x:5,b:9})" println; r set({x:5,b:9}); react() | |
"r set({a:10,y:9})" println; r set({a:10,y:9}); react() | |
r set({a:1,b:2}) | |
B: 2 | |
A: 1 | |
r set({a:3,b:2}) | |
r set({a:3,b:4}) | |
B: 4 | |
A: 3 | |
r set({a:5,b:4}) | |
r set({a:5,b:6}) | |
B: 6 | |
A: 5 | |
r set({a:7,b:8}) | |
r set({x:5,y:6}) | |
B: nil | |
A: nil | |
r set({x:5,b:9}) | |
B: 9 | |
r set({a:10,y:9}) | |
B: nil | |
A: 10 | |
test output: | |
RESULT: | |
nil | |
<============================================================================ | |
>============================================================================ | |
fn pair(a Scalar, b Scalar) = (a, b) | |
pair([1,2,3,4], by(10,10)) println | |
[(1, 10), (2, 20), (3, 30), (4, 40)] | |
test output: | |
RESULT: | |
[(1, 10), (2, 20), (3, 30), (4, 40)] | |
<============================================================================ | |
>============================================================================ | |
fn pair(a Scalar, b Scalar) = (a, b) | |
let x = 0 inlet | |
let y = pair([0,1,2,3,4], x) | |
-- y typeName println | |
x set(10); y get println | |
x set(20); y get println | |
x set(30); y get println | |
x set(40); y get println | |
[(0, 10), (1, 10), (2, 10), (3, 10), (4, 10)] | |
[(0, 20), (1, 20), (2, 20), (3, 20), (4, 20)] | |
[(0, 30), (1, 30), (2, 30), (3, 30), (4, 30)] | |
[(0, 40), (1, 40), (2, 40), (3, 40), (4, 40)] | |
test output: | |
RESULT: | |
[(0, 40), (1, 40), (2, 40), (3, 40), (4, 40)] | |
<============================================================================ | |
>============================================================================ | |
fn pair(a Scalar, b Scalar) = (a, b) | |
let x = 0 inlet | |
let y = pair([0,1,2,3,4] asList, x) | |
-- y typeName println | |
x set(10); y get println | |
x set(20); y get println | |
x set(30); y get println | |
x set(40); y get println | |
[(0, 10), (1, 10), (2, 10), (3, 10), (4, 10)] | |
[(0, 20), (1, 20), (2, 20), (3, 20), (4, 20)] | |
[(0, 30), (1, 30), (2, 30), (3, 30), (4, 30)] | |
[(0, 40), (1, 40), (2, 40), (3, 40), (4, 40)] | |
test output: | |
RESULT: | |
[(0, 40), (1, 40), (2, 40), (3, 40), (4, 40)] | |
<============================================================================ | |
>============================================================================ | |
fn pair(a Scalar, b Scalar) = (a, b) | |
let x = 0 inlet | |
let y = pair(by(1,1), x) | |
-- y typeName println | |
x set(10); y get println | |
x set(20); y get println | |
x set(30); y get println | |
x set(40); x set(50); y get println | |
[(1, 10), (2, 10), (3, 10), (4, 10), (5, 10), (6, 10), (7, 10), (8, 10), (9, 10)...] | |
[(1, 20), (2, 20), (3, 20), (4, 20), (5, 20), (6, 20), (7, 20), (8, 20), (9, 20)...] | |
[(1, 30), (2, 30), (3, 30), (4, 30), (5, 30), (6, 30), (7, 30), (8, 30), (9, 30)...] | |
[(1, 50), (2, 50), (3, 50), (4, 50), (5, 50), (6, 50), (7, 50), (8, 50), (9, 50)...] | |
test output: | |
RESULT: | |
[ (1, 50), | |
. (2, 50), | |
. (3, 50), | |
. (4, 50), | |
. (5, 50), | |
. (6, 50), | |
. (7, 50), | |
. (8, 50), | |
. ...] | |
<============================================================================ | |
>============================================================================ | |
fn pair(a Scalar, b Scalar) = (a, b) | |
let x = 0 inlet | |
let y = pair(by(1,1) ever, x) | |
-- y typeName println | |
x set(10); y get println | |
x set(20); y get println | |
x set(30); y get println | |
x set(40); x set(50); y get println | |
[[(1, 10), (2, 10), (3, 10), (4, 10), (5, 10), (6, 10), (7, 10), (8, 10), (9, 10)...], [(1, 10), (2, 10), (3, 10), (4, 10), (5, 10), (6, 10), (7, 10), (8, 10), (9, 10)...], [(1, 10), (2, 10), (3, 10), (4, 10), (5, 10), (6, 10), (7, 10), (8, 10), (9, 10)...], [(1, 10), (2, 10), (3, 10), (4, 10), (5, 10), (6, 10), (7, 10), (8, 10), (9, 10)...], [(1, 10), (2, 10), (3, 10), (4, 10), (5, 10), (6, 10), (7, 10), (8, 10), (9, 10)...], [(1, 10), (2, 10), (3, 10), (4, 10), (5, 10), (6, 10), (7, 10), (8, 10), (9, 10)...], [(1, 10), (2, 10), (3, 10), (4, 10), (5, 10), (6, 10), (7, 10), (8, 10), (9, 10)...], [(1, 10), (2, 10), (3, 10), (4, 10), (5, 10), (6, 10), (7, 10), (8, 10), (9, 10)...], [(1, 10), (2, 10), (3, 10), (4, 10), (5, 10), (6, 10), (7, 10), (8, 10), (9, 10)...]...] | |
[[(1, 20), (2, 20), (3, 20), (4, 20), (5, 20), (6, 20), (7, 20), (8, 20), (9, 20)...], [(1, 20), (2, 20), (3, 20), (4, 20), (5, 20), (6, 20), (7, 20), (8, 20), (9, 20)...], [(1, 20), (2, 20), (3, 20), (4, 20), (5, 20), (6, 20), (7, 20), (8, 20), (9, 20)...], [(1, 20), (2, 20), (3, 20), (4, 20), (5, 20), (6, 20), (7, 20), (8, 20), (9, 20)...], [(1, 20), (2, 20), (3, 20), (4, 20), (5, 20), (6, 20), (7, 20), (8, 20), (9, 20)...], [(1, 20), (2, 20), (3, 20), (4, 20), (5, 20), (6, 20), (7, 20), (8, 20), (9, 20)...], [(1, 20), (2, 20), (3, 20), (4, 20), (5, 20), (6, 20), (7, 20), (8, 20), (9, 20)...], [(1, 20), (2, 20), (3, 20), (4, 20), (5, 20), (6, 20), (7, 20), (8, 20), (9, 20)...], [(1, 20), (2, 20), (3, 20), (4, 20), (5, 20), (6, 20), (7, 20), (8, 20), (9, 20)...]...] | |
[[(1, 30), (2, 30), (3, 30), (4, 30), (5, 30), (6, 30), (7, 30), (8, 30), (9, 30)...], [(1, 30), (2, 30), (3, 30), (4, 30), (5, 30), (6, 30), (7, 30), (8, 30), (9, 30)...], [(1, 30), (2, 30), (3, 30), (4, 30), (5, 30), (6, 30), (7, 30), (8, 30), (9, 30)...], [(1, 30), (2, 30), (3, 30), (4, 30), (5, 30), (6, 30), (7, 30), (8, 30), (9, 30)...], [(1, 30), (2, 30), (3, 30), (4, 30), (5, 30), (6, 30), (7, 30), (8, 30), (9, 30)...], [(1, 30), (2, 30), (3, 30), (4, 30), (5, 30), (6, 30), (7, 30), (8, 30), (9, 30)...], [(1, 30), (2, 30), (3, 30), (4, 30), (5, 30), (6, 30), (7, 30), (8, 30), (9, 30)...], [(1, 30), (2, 30), (3, 30), (4, 30), (5, 30), (6, 30), (7, 30), (8, 30), (9, 30)...], [(1, 30), (2, 30), (3, 30), (4, 30), (5, 30), (6, 30), (7, 30), (8, 30), (9, 30)...]...] | |
[[(1, 50), (2, 50), (3, 50), (4, 50), (5, 50), (6, 50), (7, 50), (8, 50), (9, 50)...], [(1, 50), (2, 50), (3, 50), (4, 50), (5, 50), (6, 50), (7, 50), (8, 50), (9, 50)...], [(1, 50), (2, 50), (3, 50), (4, 50), (5, 50), (6, 50), (7, 50), (8, 50), (9, 50)...], [(1, 50), (2, 50), (3, 50), (4, 50), (5, 50), (6, 50), (7, 50), (8, 50), (9, 50)...], [(1, 50), (2, 50), (3, 50), (4, 50), (5, 50), (6, 50), (7, 50), (8, 50), (9, 50)...], [(1, 50), (2, 50), (3, 50), (4, 50), (5, 50), (6, 50), (7, 50), (8, 50), (9, 50)...], [(1, 50), (2, 50), (3, 50), (4, 50), (5, 50), (6, 50), (7, 50), (8, 50), (9, 50)...], [(1, 50), (2, 50), (3, 50), (4, 50), (5, 50), (6, 50), (7, 50), (8, 50), (9, 50)...], [(1, 50), (2, 50), (3, 50), (4, 50), (5, 50), (6, 50), (7, 50), (8, 50), (9, 50)...]...] | |
test output: | |
RESULT: | |
[ [ (1, 50), | |
. . (2, 50), | |
. . (3, 50), | |
. . (4, 50), | |
. . (5, 50), | |
. . (6, 50), | |
. . (7, 50), | |
. . (8, 50), | |
. . ...], | |
. [ (1, 50), | |
. . (2, 50), | |
. . (3, 50), | |
. . (4, 50), | |
. . (5, 50), | |
. . (6, 50), | |
. . (7, 50), | |
. . (8, 50), | |
. . ...], | |
. [ (1, 50), | |
. . (2, 50), | |
. . (3, 50), | |
. . (4, 50), | |
. . (5, 50), | |
. . (6, 50), | |
. . (7, 50), | |
. . (8, 50), | |
. . ...], | |
. [ (1, 50), | |
. . (2, 50), | |
. . (3, 50), | |
. . (4, 50), | |
. . (5, 50), | |
. . (6, 50), | |
. . (7, 50), | |
. . (8, 50), | |
. . ...], | |
. [ (1, 50), | |
. . (2, 50), | |
. . (3, 50), | |
. . (4, 50), | |
. . (5, 50), | |
. . (6, 50), | |
. . (7, 50), | |
. . (8, 50), | |
. . ...], | |
. [ (1, 50), | |
. . (2, 50), | |
. . (3, 50), | |
. . (4, 50), | |
. . (5, 50), | |
. . (6, 50), | |
. . (7, 50), | |
. . (8, 50), | |
. . ...], | |
. [ (1, 50), | |
. . (2, 50), | |
. . (3, 50), | |
. . (4, 50), | |
. . (5, 50), | |
. . (6, 50), | |
. . (7, 50), | |
. . (8, 50), | |
. . ...], | |
. [ (1, 50), | |
. . (2, 50), | |
. . (3, 50), | |
. . (4, 50), | |
. . (5, 50), | |
. . (6, 50), | |
. . (7, 50), | |
. . (8, 50), | |
. . ...], | |
. ...] | |
<============================================================================ | |
>============================================================================ | |
fn pair(a Scalar, b Scalar) = (a, b) | |
let x = 0 inlet | |
let y = pair(by(1,1) take(2), x) | |
-- y typeName println | |
x set(10); y get println | |
x set(20); y get println | |
x set(30); y get println | |
x set(40); x set(50); y get println | |
x set(40); x set(50); y get println | |
x set(40); x set(50); y get println | |
[(1, 10), (2, 10)] | |
[(1, 20), (2, 20)] | |
[(1, 30), (2, 30)] | |
[(1, 50), (2, 50)] | |
[(1, 50), (2, 50)] | |
[(1, 50), (2, 50)] | |
test output: | |
RESULT: | |
[(1, 50), (2, 50)] | |
<============================================================================ | |
>============================================================================ | |
--- 2023 09 27 --- | |
fn pair(a Scalar, b Scalar) = (a, b) | |
let x = 0 inlet | |
let a = 1 inlet | |
let y = pair(by(0,a) take(4), x) | |
-- y typeName println | |
x set(10); y println | |
x set(20); y println | |
x set(30); y get println | |
x set(40); a set(2); y get println | |
x set(50); a set(5); y get println | |
x set(60); a set(9); y get println | |
[(0, 10), (1, 10), (2, 10), (3, 10)] | |
[(0, 20), (1, 20), (2, 20), (3, 20)] | |
[(0, 30), (1, 30), (2, 30), (3, 30)] | |
[(0, 40), (2, 40), (4, 40), (6, 40)] | |
[(0, 50), (5, 50), (10, 50), (15, 50)] | |
[(0, 60), (9, 60), (18, 60), (27, 60)] | |
test output: | |
RESULT: | |
[(0, 60), (9, 60), (18, 60), (27, 60)] | |
<============================================================================ | |
>============================================================================ | |
fn pair(a Scalar, b Scalar) = (a, b) | |
let x = 0 inlet | |
let y = pair(by(1,1) once, x) | |
-- y typeName println | |
x set(10); y get println | |
x set(20); y get println | |
x set(30); y get println | |
x set(40); x set(50); y get println | |
x set(40); x set(50); y get println | |
x set(40); x set(50); y get println | |
[[(1, 10), (2, 10), (3, 10), (4, 10), (5, 10), (6, 10), (7, 10), (8, 10), (9, 10)...]] | |
[[(1, 20), (2, 20), (3, 20), (4, 20), (5, 20), (6, 20), (7, 20), (8, 20), (9, 20)...]] | |
[[(1, 30), (2, 30), (3, 30), (4, 30), (5, 30), (6, 30), (7, 30), (8, 30), (9, 30)...]] | |
[[(1, 50), (2, 50), (3, 50), (4, 50), (5, 50), (6, 50), (7, 50), (8, 50), (9, 50)...]] | |
[[(1, 50), (2, 50), (3, 50), (4, 50), (5, 50), (6, 50), (7, 50), (8, 50), (9, 50)...]] | |
[[(1, 50), (2, 50), (3, 50), (4, 50), (5, 50), (6, 50), (7, 50), (8, 50), (9, 50)...]] | |
test output: | |
RESULT: | |
[ [ (1, 50), | |
. . (2, 50), | |
. . (3, 50), | |
. . (4, 50), | |
. . (5, 50), | |
. . (6, 50), | |
. . (7, 50), | |
. . (8, 50), | |
. . ...]] | |
<============================================================================ | |
>============================================================================ | |
fn +/(x) = x reduce(+,0); [1,2,3,4,5,6,7] +/ | |
test output: | |
RESULT: | |
28 | |
<============================================================================ | |
>============================================================================ | |
fn */(x) = x reduce(*,1); [1,2,3,4,5,6,7] */ | |
test output: | |
RESULT: | |
5040 | |
<============================================================================ | |
>============================================================================ | |
[[[1,2],[3,4]],[[5,6],[7,8]]] reverse | |
test output: | |
RESULT: | |
[[[5, 6], [7, 8]], [[1, 2], [3, 4]]] | |
<============================================================================ | |
>============================================================================ | |
[[[1,2],[3,4]],[[5,6],[7,8]]] @ reverse | |
test output: | |
RESULT: | |
[[[3, 4], [1, 2]], [[7, 8], [5, 6]]] | |
<============================================================================ | |
>============================================================================ | |
[[[1,2],[3,4]],[[5,6],[7,8]]] @@ reverse | |
test output: | |
RESULT: | |
[[[2, 1], [4, 3]], [[6, 5], [8, 7]]] | |
<============================================================================ | |
>============================================================================ | |
[[[1,2],[3,4]],[[5,6],[7,8]]] @@@ reverse | |
test output: | |
CALL FRAMES SIZE 0 BASE 0 | |
-> ? lm 0x0 pc 0x0 sb 0 ssz 1 ksz XXX | |
num args: 1 | |
0 I64 | |
error: 3 No applicable method found for function 'reverse'. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
[[[1,2],[3,4]],[[5,6],[7,8]]] @@@@ reverse | |
test output: | |
CALL FRAMES SIZE 0 BASE 0 | |
-> ? lm 0x0 pc 0x0 sb 0 ssz 1 ksz XXX | |
num args: 1 | |
0 I64 | |
error: 3 No applicable method found for function 'reverse'. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
[[#i32[1,2],#i32[3,4]],[#i32[5,6],#i32[7,8]]] @@ reverse | |
test output: | |
RESULT: | |
[[#i32[2, 1], #i32[4, 3]], [#i32[6, 5], #i32[8, 7]]] | |
<============================================================================ | |
>============================================================================ | |
fn pair(a,b) = (a,b); pair([[1,2],[3,4]], [[5,6],[7,8]]) | |
test output: | |
RESULT: | |
([[1, 2], [3, 4]], [[5, 6], [7, 8]]) | |
<============================================================================ | |
>============================================================================ | |
fn pair(a,b) = (a,b) | |
pair([[1,2],[3,4]] @, [[5,6],[7,8]] @) println | |
pair([[-1,-2],[-3,-4]] @, [[-5,-6],[-7,-8]] @) println | |
[([1, 2], [5, 6]), ([3, 4], [7, 8])] | |
[([-1, -2], [-5, -6]), ([-3, -4], [-7, -8])] | |
test output: | |
RESULT: | |
[([-1, -2], [-5, -6]), ([-3, -4], [-7, -8])] | |
<============================================================================ | |
>============================================================================ | |
fn pair(a,b) = (a,b) | |
pair([#i32[1,2],#i32[3,4]] @@, [#i32[5,6],#i32[7,8]] @@) println | |
pair([#f32[-1,-2],#f32[-3,-4]] @@, [#f32[-5,-6],#f32[-7,-8]] @@) println | |
[[(1, 5), (2, 6)], [(3, 7), (4, 8)]] | |
[[(-1., -5.), (-2., -6.)], [(-3., -7.), (-4., -8.)]] | |
test output: | |
RESULT: | |
[[(-1., -5.), (-2., -6.)], [(-3., -7.), (-4., -8.)]] | |
<============================================================================ | |
>============================================================================ | |
fn pair(a,b) = (a,b); pair([[1,2],[3,4]] @@, [[5,6],[7,8]] @@) | |
test output: | |
RESULT: | |
[[(1, 5), (2, 6)], [(3, 7), (4, 8)]] | |
<============================================================================ | |
>============================================================================ | |
fn pair(a,b) = (a,b); pair([[1,2],[3,4]], [[5,6],[7,8]] @) | |
test output: | |
RESULT: | |
[([[1, 2], [3, 4]], [5, 6]), ([[1, 2], [3, 4]], [7, 8])] | |
<============================================================================ | |
>============================================================================ | |
fn pair(a,b) = (a,b); pair([[1,2],[3,4]] @, [[5,6],[7,8]]) | |
test output: | |
RESULT: | |
[([1, 2], [[5, 6], [7, 8]]), ([3, 4], [[5, 6], [7, 8]])] | |
<============================================================================ | |
>============================================================================ | |
fn pair(a,b) = (a,b); pair([1,2,3,4] @1, [5,6,7,8] @2) | |
test output: | |
RESULT: | |
[ [(1, 5), (1, 6), (1, 7), (1, 8)], | |
. [(2, 5), (2, 6), (2, 7), (2, 8)], | |
. [(3, 5), (3, 6), (3, 7), (3, 8)], | |
. [(4, 5), (4, 6), (4, 7), (4, 8)]] | |
<============================================================================ | |
>============================================================================ | |
fn pair(a,b) = (a,b); pair([1,2,3,4] @2, [5,6,7,8] @1) | |
test output: | |
RESULT: | |
[ [(1, 5), (2, 5), (3, 5), (4, 5)], | |
. [(1, 6), (2, 6), (3, 6), (4, 6)], | |
. [(1, 7), (2, 7), (3, 7), (4, 7)], | |
. [(1, 8), (2, 8), (3, 8), (4, 8)]] | |
<============================================================================ | |
>============================================================================ | |
([1,2,3],[4,5,6]) | |
test output: | |
RESULT: | |
([1, 2, 3], [4, 5, 6]) | |
<============================================================================ | |
>============================================================================ | |
([1,2,3] @,[4,5,6]) | |
test output: | |
RESULT: | |
[(1, [4, 5, 6]), (2, [4, 5, 6]), (3, [4, 5, 6])] | |
<============================================================================ | |
>============================================================================ | |
([1,2,3],[4,5,6] @) | |
test output: | |
RESULT: | |
[([1, 2, 3], 4), ([1, 2, 3], 5), ([1, 2, 3], 6)] | |
<============================================================================ | |
>============================================================================ | |
([1,2,3] @,[4,5,6] @) | |
test output: | |
RESULT: | |
[(1, 4), (2, 5), (3, 6)] | |
<============================================================================ | |
>============================================================================ | |
[[1,2,3],[4,5,6]] | |
test output: | |
RESULT: | |
[[1, 2, 3], [4, 5, 6]] | |
<============================================================================ | |
>============================================================================ | |
[[1,2,3] @,[4,5,6]] | |
test output: | |
RESULT: | |
[[1, [4, 5, 6]], [2, [4, 5, 6]], [3, [4, 5, 6]]] | |
<============================================================================ | |
>============================================================================ | |
[[1,2,3],[4,5,6] @] | |
test output: | |
RESULT: | |
[[[1, 2, 3], 4], [[1, 2, 3], 5], [[1, 2, 3], 6]] | |
<============================================================================ | |
>============================================================================ | |
[[1,2,3] @,[4,5,6] @] | |
test output: | |
RESULT: | |
[[1, 4], [2, 5], [3, 6]] | |
<============================================================================ | |
>============================================================================ | |
[(1,2,3) @,(4,5,6) @] -- tuples are not iterated | |
test output: | |
RESULT: | |
[ [(1, 2, 3), (4, 5, 6)], | |
. [(1, 2, 3), (4, 5, 6)], | |
. [(1, 2, 3), (4, 5, 6)], | |
. [(1, 2, 3), (4, 5, 6)], | |
. [(1, 2, 3), (4, 5, 6)], | |
. [(1, 2, 3), (4, 5, 6)], | |
. [(1, 2, 3), (4, 5, 6)], | |
. [(1, 2, 3), (4, 5, 6)], | |
. ...] | |
<============================================================================ | |
>============================================================================ | |
[[1,2,3] @,8 @] -- @ has no effect on an integer | |
test output: | |
RESULT: | |
[[1, 8], [2, 8], [3, 8]] | |
<============================================================================ | |
>============================================================================ | |
{a:[1,2,3] @, b:[4,5,6]} | |
test output: | |
RESULT: | |
[{a: 1, b: [4, 5, 6]}, {a: 2, b: [4, 5, 6]}, {a: 3, b: [4, 5, 6]}] | |
<============================================================================ | |
>============================================================================ | |
{a:[1,2,3] @, b:[4,5,6] @} | |
test output: | |
RESULT: | |
[{a: 1, b: 4}, {a: 2, b: 5}, {a: 3, b: 6}] | |
<============================================================================ | |
>============================================================================ | |
{a:[1,2,3] @1, b:[4,5,6] @2} | |
test output: | |
RESULT: | |
[ [{a: 1, b: 4}, {a: 1, b: 5}, {a: 1, b: 6}], | |
. [{a: 2, b: 4}, {a: 2, b: 5}, {a: 2, b: 6}], | |
. [{a: 3, b: 4}, {a: 3, b: 5}, {a: 3, b: 6}]] | |
<============================================================================ | |
>============================================================================ | |
{a:[1,2,3] @2, b:[4,5,6] @1} | |
test output: | |
RESULT: | |
[ [{a: 1, b: 4}, {a: 2, b: 4}, {a: 3, b: 4}], | |
. [{a: 1, b: 5}, {a: 2, b: 5}, {a: 3, b: 5}], | |
. [{a: 1, b: 6}, {a: 2, b: 6}, {a: 3, b: 6}]] | |
<============================================================================ | |
>============================================================================ | |
#i32[[1,2,3],[4,5,6]] | |
error: 6 Object of class List_obj cannot be converted to integer. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
#i32[[1,2,3] @,[4,5,6]] | |
test output: | |
error: 6 Object of class List_obj cannot be converted to integer. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
#i32[[1,2,3],[4,5,6] @] | |
test output: | |
error: 6 Object of class List_obj cannot be converted to integer. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
#i32[[1,2,3] @,[4,5,6] @] | |
test output: | |
RESULT: | |
[#i32[1, 4], #i32[2, 5], #i32[3, 6]] | |
<============================================================================ | |
>============================================================================ | |
#i32[[1,2,3] @1,[4,5,6] @2] | |
test output: | |
RESULT: | |
[ [#i32[1, 4], #i32[1, 5], #i32[1, 6]], | |
. [#i32[2, 4], #i32[2, 5], #i32[2, 6]], | |
. [#i32[3, 4], #i32[3, 5], #i32[3, 6]]] | |
<============================================================================ | |
>============================================================================ | |
#i32[[1,2,3] @2,[4,5,6] @1] | |
test output: | |
RESULT: | |
[ [#i32[1, 4], #i32[2, 4], #i32[3, 4]], | |
. [#i32[1, 5], #i32[2, 5], #i32[3, 5]], | |
. [#i32[1, 6], #i32[2, 6], #i32[3, 6]]] | |
<============================================================================ | |
>============================================================================ | |
#f32[[1,2,3] @,[4,5,6] @] | |
test output: | |
RESULT: | |
[#f32[1.f, 4.f], #f32[2.f, 5.f], #f32[3.f, 6.f]] | |
<============================================================================ | |
>============================================================================ | |
#r32[([1,2,3]/7) @,([4,5,6]/7) @] | |
test output: | |
RESULT: | |
[#r32[1/7, 4/7], #r32[2/7, 5/7], #r32[3/7, 6/7]] | |
<============================================================================ | |
>============================================================================ | |
#x32[[1,2,3] @, [4,5,6] @] | |
test output: | |
RESULT: | |
[ #x32[x32(1.f, 0.f), x32(4.f, 0.f)], | |
. #x32[x32(2.f, 0.f), x32(5.f, 0.f)], | |
. #x32[x32(3.f, 0.f), x32(6.f, 0.f)]] | |
<============================================================================ | |
>============================================================================ | |
to(0,9) | |
test output: | |
RESULT: | |
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | |
<============================================================================ | |
>============================================================================ | |
by(0,1) println | |
[0, 1, 2, 3, 4, 5, 6, 7, 8...] | |
test output: | |
RESULT: | |
[0, 1, 2, 3, 4, 5, 6, 7, ...] | |
<============================================================================ | |
>============================================================================ | |
by(0,1) take(2) println | |
[0, 1] | |
test output: | |
RESULT: | |
[0, 1] | |
<============================================================================ | |
>============================================================================ | |
by(0,1) take(1) println | |
[0] | |
test output: | |
RESULT: | |
[0] | |
<============================================================================ | |
>============================================================================ | |
by(0,1) take(0) println | |
[] | |
test output: | |
RESULT: | |
[] | |
<============================================================================ | |
>============================================================================ | |
by(0,1) take(to(0,5)) println | |
[[], [0], [0, 1], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4]] | |
test output: | |
RESULT: | |
[[], [0], [0, 1], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4]] | |
<============================================================================ | |
>============================================================================ | |
by(0,1) take([1,2,3,4,5]) println | |
[[0], [0, 1], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4]] | |
test output: | |
RESULT: | |
[[0], [0, 1], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4]] | |
<============================================================================ | |
>============================================================================ | |
by(0,1) take([0,1,2,3,4,5]) println | |
[[], [0], [0, 1], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4]] | |
test output: | |
RESULT: | |
[[], [0], [0, 1], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4]] | |
<============================================================================ | |
>============================================================================ | |
by(0,0) take(to(0,5)) @ $ [1] println | |
[1] | |
test output: | |
RESULT: | |
[ [1], | |
. [0, 1], | |
. [0, 0, 1], | |
. [0, 0, 0, 1], | |
. [0, 0, 0, 0, 1], | |
. [0, 0, 0, 0, 0, 1]] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4][[1,0,2,1,3,4,5,6,7,-1,-2,-3]] | |
test output: | |
RESULT: | |
[2, 1, 3, 2, 4, 1, 2, 3, 4, 4, 3, 2] | |
<============================================================================ | |
>============================================================================ | |
[1,2][to(0,5)] | |
test output: | |
RESULT: | |
[1, 2, 1, 2, 1, 2] | |
<============================================================================ | |
>============================================================================ | |
[[1,2,3],[4,5,6]][to(0,5)] | |
test output: | |
RESULT: | |
[[1, 2, 3], [4, 5, 6], [1, 2, 3], [4, 5, 6], [1, 2, 3], [4, 5, 6]] | |
<============================================================================ | |
>============================================================================ | |
[[1,2,3],[4,5,6]][to(0,5), to(0,5)] | |
test output: | |
RESULT: | |
[1, 5, 3, 4, 2, 6] | |
<============================================================================ | |
>============================================================================ | |
[[1,2,3],[4,5,6]][to(0,5) @1, to(0,3) @2] | |
test output: | |
RESULT: | |
[ [1, 2, 3, 1], | |
. [4, 5, 6, 4], | |
. [1, 2, 3, 1], | |
. [4, 5, 6, 4], | |
. [1, 2, 3, 1], | |
. [4, 5, 6, 4]] | |
<============================================================================ | |
>============================================================================ | |
(by(0,1) take(3))[to(0,5)] | |
test output: | |
RESULT: | |
[0, 1, 2, 0, 1, 2] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) drop(4) | |
test output: | |
RESULT: | |
[5, 6, 7, 8, 9, 10, 11, 12, ...] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) dropWhile(true repeat(3) $ false) | |
test output: | |
RESULT: | |
[4, 5, 6, 7, 8, 9, 10, 11, ...] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) dropWhile(\x[x<5]) | |
test output: | |
RESULT: | |
[5, 6, 7, 8, 9, 10, 11, 12, ...] | |
<============================================================================ | |
>============================================================================ | |
true repeat(3) $ false ever | |
test output: | |
RESULT: | |
[true, true, true, false, false, false, false, false, ...] | |
<============================================================================ | |
>============================================================================ | |
true repeat(3) $ false | |
test output: | |
RESULT: | |
[true, true, true, false] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) takeWhile(true repeat(3) $ false) | |
test output: | |
RESULT: | |
[1, 2, 3] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) takeWhile(\x[x<5]) | |
test output: | |
RESULT: | |
[1, 2, 3, 4] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) takeWhile((true repeat([2,3,4]) @ $ false) @) | |
test output: | |
RESULT: | |
[[1, 2], [1, 2, 3], [1, 2, 3, 4]] | |
<============================================================================ | |
>============================================================================ | |
true repeat([2,3,4]) | |
test output: | |
RESULT: | |
[[true, true], [true, true, true], [true, true, true, true]] | |
<============================================================================ | |
>============================================================================ | |
true repeat([2,3,4]) @ $ false | |
test output: | |
RESULT: | |
[ [true, true, false], | |
. [true, true, true, false], | |
. [true, true, true, true, false]] | |
<============================================================================ | |
>============================================================================ | |
to(1,3) $ to(6,9) | |
test output: | |
RESULT: | |
[1, 2, 3, 6, 7, 8, 9] | |
<============================================================================ | |
>============================================================================ | |
[1/3, 2/5, 3/7, 4/9, 5/11, 6/13] clump(3) println | |
[[1/3, 2/5, 3/7], [4/9, 5/11, 6/13]] | |
test output: | |
RESULT: | |
[[1/3, 2/5, 3/7], [4/9, 5/11, 6/13]] | |
<============================================================================ | |
>============================================================================ | |
[1/3, 2/5, 3/7, 4/9, 5/11, 6/13] clump(99) println | |
[] | |
test output: | |
RESULT: | |
[] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] clump([1,2,3]) @ take(2) println | |
[[1], [2, 3]] | |
test output: | |
RESULT: | |
[[1], [2, 3]] | |
<============================================================================ | |
>============================================================================ | |
by(0,1) clump([1,2,3]) println | |
[[0], [1, 2], [3, 4, 5]] | |
test output: | |
RESULT: | |
[[0], [1, 2], [3, 4, 5]] | |
<============================================================================ | |
>============================================================================ | |
by(0,1) clump([0,1,2]) println | |
[[0], [1], [2, 3]] | |
test output: | |
RESULT: | |
[[0], [1], [2, 3]] | |
<============================================================================ | |
>============================================================================ | |
[0,1,2,3,4,5,6,7,8] clump([1,2,3]) println | |
[[0], [1, 2], [3, 4, 5]] | |
test output: | |
RESULT: | |
[[0], [1, 2], [3, 4, 5]] | |
<============================================================================ | |
>============================================================================ | |
to(0,8) clump([1,2,3]) println | |
[[0], [1, 2], [3, 4, 5]] | |
test output: | |
RESULT: | |
[[0], [1, 2], [3, 4, 5]] | |
<============================================================================ | |
>============================================================================ | |
by(0,1) println | |
[0, 1, 2, 3, 4, 5, 6, 7, 8...] | |
test output: | |
RESULT: | |
[0, 1, 2, 3, 4, 5, 6, 7, ...] | |
<============================================================================ | |
>============================================================================ | |
by(0,1) clump([1,2,3]) println | |
[[0], [1, 2], [3, 4, 5]] | |
test output: | |
RESULT: | |
[[0], [1, 2], [3, 4, 5]] | |
<============================================================================ | |
>============================================================================ | |
by(0,1) clump([0,1,2]) println | |
[[0], [1], [2, 3]] | |
test output: | |
RESULT: | |
[[0], [1], [2, 3]] | |
<============================================================================ | |
>============================================================================ | |
to(1,3) println | |
[1, 2, 3] | |
test output: | |
RESULT: | |
[1, 2, 3] | |
<============================================================================ | |
>============================================================================ | |
by(0,1) clump(to(1,3)) println | |
[[0], [1, 2], [3, 4, 5]] | |
test output: | |
RESULT: | |
[[0], [1, 2], [3, 4, 5]] | |
<============================================================================ | |
>============================================================================ | |
by(0,1) clump(by(1,1)) println | |
[[0], [1, 2], [3, 4, 5], [6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19, 20], [21, 22, 23, 24, 25, 26, 27], [28, 29, 30, 31, 32, 33, 34, 35], [36, 37, 38, 39, 40, 41, 42, 43, 44]...] | |
test output: | |
RESULT: | |
[ [0], | |
. [1, 2], | |
. [3, 4, 5], | |
. [6, 7, 8, 9], | |
. [10, 11, 12, 13, 14], | |
. [15, 16, 17, 18, 19, 20], | |
. [21, 22, 23, 24, 25, 26, 27], | |
. [28, 29, 30, 31, 32, 33, 34, 35], | |
. ...] | |
<============================================================================ | |
>============================================================================ | |
to(1,4) rotate(0) println | |
[1, 2, 3, 4] | |
test output: | |
RESULT: | |
[1, 2, 3, 4] | |
<============================================================================ | |
>============================================================================ | |
to(1,4) rotate(1) println | |
[4, 1, 2, 3] | |
test output: | |
RESULT: | |
[4, 1, 2, 3] | |
<============================================================================ | |
>============================================================================ | |
to(1,4) rotate(2) println | |
[3, 4, 1, 2] | |
test output: | |
RESULT: | |
[3, 4, 1, 2] | |
<============================================================================ | |
>============================================================================ | |
to(1,4) rotate(3) println | |
[2, 3, 4, 1] | |
test output: | |
RESULT: | |
[2, 3, 4, 1] | |
<============================================================================ | |
>============================================================================ | |
to(1,4) rotate(4) println | |
[1, 2, 3, 4] | |
test output: | |
RESULT: | |
[1, 2, 3, 4] | |
<============================================================================ | |
>============================================================================ | |
to(1,4) rotate(5) println | |
[4, 1, 2, 3] | |
test output: | |
RESULT: | |
[4, 1, 2, 3] | |
<============================================================================ | |
>============================================================================ | |
to(1,4) rotate(-1) println | |
[2, 3, 4, 1] | |
test output: | |
RESULT: | |
[2, 3, 4, 1] | |
<============================================================================ | |
>============================================================================ | |
to(1,4) rotate(-2) println | |
[3, 4, 1, 2] | |
test output: | |
RESULT: | |
[3, 4, 1, 2] | |
<============================================================================ | |
>============================================================================ | |
to(1,4) rotate(-3) println | |
[4, 1, 2, 3] | |
test output: | |
RESULT: | |
[4, 1, 2, 3] | |
<============================================================================ | |
>============================================================================ | |
to(1,4) rotate(-4) println | |
[1, 2, 3, 4] | |
test output: | |
RESULT: | |
[1, 2, 3, 4] | |
<============================================================================ | |
>============================================================================ | |
to(1,4) rotate(-5) println | |
[2, 3, 4, 1] | |
test output: | |
RESULT: | |
[2, 3, 4, 1] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) take(24) println | |
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21...] | |
test output: | |
RESULT: | |
[ 1, | |
. 2, | |
. 3, | |
. 4, | |
. 5, | |
. 6, | |
. 7, | |
. 8, | |
. 9, | |
. 10, | |
. 11, | |
. 12, | |
. 13, | |
. 14, | |
. 15, | |
. 16, | |
. 17, | |
. 18, | |
. 19, | |
. 20, | |
. ...] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) take(24) clump(6) println | |
[[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12], [13, 14, 15, 16, 17, 18], [19, 20, 21, 22, 23, 24]] | |
test output: | |
RESULT: | |
[ [1, 2, 3, 4, 5, 6], | |
. [7, 8, 9, 10, 11, 12], | |
. [13, 14, 15, 16, 17, 18], | |
. [19, 20, 21, 22, 23, 24]] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) take(24) clump(6) rotate(1) println | |
[[19, 20, 21, 22, 23, 24], [1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12], [13, 14, 15, 16, 17, 18]] | |
test output: | |
RESULT: | |
[ [19, 20, 21, 22, 23, 24], | |
. [1, 2, 3, 4, 5, 6], | |
. [7, 8, 9, 10, 11, 12], | |
. [13, 14, 15, 16, 17, 18]] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) take(24) clump(6) rotate(1) @ rotate(2) println | |
[[23, 24, 19, 20, 21, 22], [5, 6, 1, 2, 3, 4], [11, 12, 7, 8, 9, 10], [17, 18, 13, 14, 15, 16]] | |
test output: | |
RESULT: | |
[ [23, 24, 19, 20, 21, 22], | |
. [5, 6, 1, 2, 3, 4], | |
. [11, 12, 7, 8, 9, 10], | |
. [17, 18, 13, 14, 15, 16]] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) take(24) clump(6) rotate(1) @ rotate(2) drop(-1) println | |
[[23, 24, 19, 20, 21, 22], [5, 6, 1, 2, 3, 4], [11, 12, 7, 8, 9, 10]] | |
test output: | |
RESULT: | |
[[23, 24, 19, 20, 21, 22], [5, 6, 1, 2, 3, 4], [11, 12, 7, 8, 9, 10]] | |
<============================================================================ | |
>============================================================================ | |
by(1,1) take(24) clump(6) rotate(1) @ rotate(2) drop(-1) @ take(4) println | |
[[23, 24, 19, 20], [5, 6, 1, 2], [11, 12, 7, 8]] | |
test output: | |
RESULT: | |
[[23, 24, 19, 20], [5, 6, 1, 2], [11, 12, 7, 8]] | |
<============================================================================ | |
>============================================================================ | |
let x = [1,2,3,4] clump(2) pop | |
test output: | |
RESULT: | |
[3, 4] | |
<============================================================================ | |
>============================================================================ | |
let x = [1,2,3,4] clump(2) push(7) | |
test output: | |
RESULT: | |
[[1, 2], [3, 4], 7] | |
<============================================================================ | |
>============================================================================ | |
let x = [1,2,3,4] clump(2) push(7); 0 cons(x) | |
test output: | |
RESULT: | |
[0, [1, 2], [3, 4], 7] | |
<============================================================================ | |
>============================================================================ | |
5(1,-2,3) | |
syntax error, line 1: expected a parenthesized operator name after value and '('. | |
this line: | |
5(1,-2,3) | |
next token: [3] 8 tokComma ',' | |
syntax error, line 1: expected statements | |
this line: | |
5(1,-2,3) | |
next token: [9] 1 tokEOF | |
PARSE FAILED | |
============================================================================= | |
unknown error | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
5(1,-2,3) | |
syntax error, line 1: expected a parenthesized operator name after value and '('. | |
this line: | |
5(1,-2,3) | |
next token: [3] 8 tokComma ',' | |
syntax error, line 1: expected statements | |
this line: | |
5(1,-2,3) | |
next token: [9] 1 tokEOF | |
PARSE FAILED | |
============================================================================= | |
unknown error | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
defGeneric(#foo) | |
defMethod(foo, [Int,Int,Int], \a,b[(b,a)]) | |
error: 6 The number of argument types is more than the max arguments to the function. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
[] pop | |
error: 1 pop: empty list. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
defClass(#Florg, [I64], {}) | |
error: 1 Florg cannot inherit from sealed class I64. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
defClass(#Florg, [7], {}) | |
error: 6 non-Class found in Class vector. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
defGeneric(#foo) | |
defMethod(foo, [Int,7], \a,b[(b,a)]) | |
error: 6 non-Class found in Class vector. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
let x = #f32[1,2,3,4] pop | |
CALL FRAMES SIZE 1 BASE 1 | |
0 ? lm 0x0 pc 0x0 sb 0 ssz 0 istry 0 ksz XXX | |
-> ? lm 0x10512faa0 pc 0x11f5782dc sb 0 ssz 1 ksz 2 | |
num args: 1 | |
0 List_f32 | |
error: 3 No applicable method found for function 'pop'. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
let x = #f32[1,2,3,4] push(5.) | |
CALL FRAMES SIZE 1 BASE 1 | |
0 ? lm 0x0 pc 0x0 sb 0 ssz 0 istry 0 ksz XXX | |
-> ? lm 0x105131aa0 pc 0x11f59ea40 sb 0 ssz 2 ksz 3 | |
num args: 2 | |
0 List_f32 | |
1 F64 | |
error: 3 No applicable method found for function 'push'. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
Int{x:1} println | |
error: 1 class Int cannot be instantiated via apply | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
Int new println | |
error: 1 class Int cannot be instantiated via new | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
let Zorg = 7; fn foo(z Zorg) { z println } | |
error: 6 global variable 'Zorg' is not a class. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
defGeneric(#foo) defMethod([Int, Int]) \a,b[(b,a)] | |
foo(5,6) println | |
(6, 5) | |
test output: | |
RESULT: | |
(6, 5) | |
<============================================================================ | |
>============================================================================ | |
import stuff : x | |
x println | |
codeImportNames | |
1 | |
test output: | |
RESULT: | |
1 | |
<============================================================================ | |
>============================================================================ | |
import stuff : y | |
y println | |
codeImportNames | |
error: 3 Symbol 'y' not found in module 'stuff' | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
import fluff : y | |
y println | |
codeImportNames | |
error: 3 Module 'fluff' was not found. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
import stuff : x | |
x println | |
syntax error, line 1: expected symbol or string after '#'. | |
next token: [5] 15 tokNewLine | |
syntax error, line 1: expected statements | |
next token: [6] 1 tokEOF | |
error: 12 Parse failed for module 'stuff'. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
import stuff : x | |
x() println | |
error: 12 Name 'y' is already in use in this scope. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
Record(5) println | |
CALL FRAMES SIZE 1 BASE 1 | |
0 ? lm 0x0 pc 0x0 sb 0 ssz 0 istry 0 ksz XXX | |
-> ? lm 0x10513a020 pc 0x12047bd0c sb 0 ssz 2 ksz 2 | |
num args: 2 | |
0 Record | |
1 I64 | |
error: 3 No applicable method found for function 'init'. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
let x = 1; x = 2 | |
error: 12 Name 'x' is immutable. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
fn foo(x Glork) { x println } | |
error: 3 argument class named 'Glork' undefined. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
foo(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32) println | |
error: 12 too many arguments in expression. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
foo(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33) println | |
error: 12 too many arguments in expression. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
let f = \x[let y = x]; f(3) println | |
3 | |
test output: | |
RESULT: | |
3 | |
<============================================================================ | |
>============================================================================ | |
let f = \x[ | |
(let y = x)+2 | |
] | |
f(3) println | |
syntax error, line 2: expected ')' A | |
this line: | |
(let y = x)+2 | |
next token: [9] 19 tokName 'y' | |
syntax error, line 3: expected statements | |
this line: | |
] | |
next token: [16] 5 tokCloseSquare ']' | |
syntax error, line 4: errors occurred while parsing. | |
this line: | |
f(3) println | |
next token: [23] 1 tokEOF | |
PARSE FAILED | |
============================================================================= | |
unknown error | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
[1,2,3] class println | |
List_obj | |
test output: | |
RESULT: | |
List_obj | |
<============================================================================ | |
>============================================================================ | |
\x,x[x + 5](2,3) println | |
error: 12 Name 'x' is already in use in this scope. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
let x = 1; \[ x println; x = 5 ]() println | |
error: 12 Name 'x' is immutable. | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
let x = 1; \[ x println; var x = 5 ]() println | |
1 | |
5 | |
test output: | |
RESULT: | |
5 | |
<============================================================================ | |
>============================================================================ | |
5 \x,y[(x,y) println](3) | |
(5, 3) | |
test output: | |
RESULT: | |
(5, 3) | |
<============================================================================ | |
>============================================================================ | |
let f = \x,y[(x,y) println]; 5 f(3) | |
(5, 3) | |
test output: | |
RESULT: | |
(5, 3) | |
<============================================================================ | |
>============================================================================ | |
{} class println | |
[1,1,2,3] idset class println | |
[1,1,2,3] eqset class println | |
EqMap new class println | |
let e = EqMap new | |
e put(1,2) | |
e put(3,4) | |
e println | |
e put(1,5) | |
e println | |
[1,1,2,3] idset println | |
[1,1,2,3] eqset println | |
Record | |
IdSet | |
EqSet | |
EqMap | |
EqMap{3:4, 1:2} | |
EqMap{3:4, 1:5} | |
{≡ 3, 2, 1} | |
{3, 2, 1} | |
test output: | |
RESULT: | |
{3, 2, 1} | |
<============================================================================ | |
>============================================================================ | |
IdMap new([1,2,3],[4,5,6]) | |
test output: | |
RESULT: | |
IdMap{3: 6, 2: 5, 1: 4} | |
<============================================================================ | |
>============================================================================ | |
IdMap new([1,1,2,3],[4,5,6,7]) | |
test output: | |
RESULT: | |
IdMap{3: 7, 2: 6, 1: 5} | |
<============================================================================ | |
>============================================================================ | |
EqMap new([1,2,3],[4,5,6]) | |
test output: | |
RESULT: | |
EqMap{3: 6, 2: 5, 1: 4} | |
<============================================================================ | |
>============================================================================ | |
EqMap new([1,1,2,3],[4,5,6,7]) | |
test output: | |
RESULT: | |
EqMap{3: 7, 2: 6, 1: 5} | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] forEach \x{x println} | |
1 | |
2 | |
3 | |
4 | |
5 | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5] | |
<============================================================================ | |
>============================================================================ | |
[1,2,3,4,5] forEach \x,i{(x,i) println} | |
(1, 0) | |
(2, 1) | |
(3, 2) | |
(4, 3) | |
(5, 4) | |
test output: | |
RESULT: | |
[1, 2, 3, 4, 5] | |
<============================================================================ | |
>============================================================================ | |
EqMap new([1,2,3],[4,5,6]) forEach \k,v{(k,v) println} | |
(1, 4) | |
(2, 5) | |
(3, 6) | |
test output: | |
RESULT: | |
EqMap{3: 6, 2: 5, 1: 4} | |
<============================================================================ | |
>============================================================================ | |
IdMap new([1,2,3],[4,5,6]) forEach \k,v{(k,v) println} | |
(1, 4) | |
(2, 5) | |
(3, 6) | |
test output: | |
RESULT: | |
IdMap{3: 6, 2: 5, 1: 4} | |
<============================================================================ | |
>============================================================================ | |
"%1%2%3" fmt("a", "b", "c") println | |
abc | |
test output: | |
RESULT: | |
abc | |
<============================================================================ | |
>============================================================================ | |
"%3%2%1" fmt("a", "b", "c") println | |
cba | |
test output: | |
RESULT: | |
cba | |
<============================================================================ | |
>============================================================================ | |
"%3-%2❤%1❤%2~%3...%%...%9..." fmt("aa", "b👄b", "c🌮🌮c") println) | |
syntax error, line 1: Parser did not consume all input. next token: [10] 3 tokCloseRound ')' | |
this line: | |
"%3-%2❤%1❤%2~%3...%%...%9..." fmt("aa", "b👄b", "c🌮🌮c") println) | |
next token: [10] 3 tokCloseRound ')' | |
PARSE FAILED | |
============================================================================= | |
unknown error | |
an expected error occurred. | |
============================================================================= | |
>============================================================================ | |
"%3-%2❤%1❤%2~%3...%%...%9..." fmt("aa", "b👄b", "c🌮🌮c") println | |
c🌮🌮c-b👄b❤aa❤b👄b~c🌮🌮c...%...... | |
test output: | |
RESULT: | |
c🌮🌮c-b👄b❤aa❤b👄b~c🌮🌮c...%...... | |
<============================================================================ | |
>============================================================================ | |
"%3-%2\u2764%1\u2764%2~%3...%%...%9..." fmt("aa", "b\U0001f444b", "c\U0001f32e\U0001f32ec") println | |
c🌮🌮c-b👄b❤aa❤b👄b~c🌮🌮c...%...... | |
test output: | |
RESULT: | |
c🌮🌮c-b👄b❤aa❤b👄b~c🌮🌮c...%...... | |
<============================================================================ | |
>============================================================================ | |
"%b%a%c" fmt("x", "y", "z") println | |
yxz | |
test output: | |
RESULT: | |
yxz | |
<============================================================================ | |
>============================================================================ | |
"%C%A%B" fmt("x", "y", "z") println | |
zxy | |
test output: | |
RESULT: | |
zxy | |
<============================================================================ | |
>============================================================================ | |
"%B%C%B%A" fmt("x", "y", "z") println | |
yzyx | |
test output: | |
RESULT: | |
yzyx | |
<============================================================================ | |
>============================================================================ | |
"(%B,%C,%B,%A)" fmt("x", "y", "z") println | |
(y,z,y,x) | |
test output: | |
RESULT: | |
(y,z,y,x) | |
<============================================================================ | |
>============================================================================ | |
"%B%%%C%B%%A" fmt("x", "y", "z") println | |
y%zy%A | |
test output: | |
RESULT: | |
y%zy%A | |
<============================================================================ | |
>============================================================================ | |
"(%a, %b, %c, %d, %e, %f)" fmt(123, 4.56, (7,8,9), 4/5, 2π, {x:7, y:4}) println | |
(123, 4.56, (7, 8, 9), 4/5, 6.283185307179586, {x:7, y:4}) | |
test output: | |
RESULT: | |
(123, 4.56, (7, 8, 9), 4/5, 6.283185307179586, {x:7, y:4}) | |
<============================================================================ | |
>============================================================================ | |
"(%^, %^, %^, %^, %^, %^)" fmt(123, 4.56, (7,8,9), 4/5, 2π, {x:7, y:4}) println | |
(123, 4.56, (7, 8, 9), 4/5, 6.283185307179586, {x:7, y:4}) | |
test output: | |
RESULT: | |
(123, 4.56, (7, 8, 9), 4/5, 6.283185307179586, {x:7, y:4}) | |
<============================================================================ | |
>============================================================================ | |
println(123, 4.56, (7,8,9), 4/5, 2π, {x:7, y:4}); | |
123 4.56 (7, 8, 9) 4/5 6.283185307179586 {x:7, y:4} | |
test output: | |
RESULT: | |
123 | |
<============================================================================ | |
>============================================================================ | |
printcsv(123, 4.56, (7,8,9), 4/5, 2π, {x:7, y:4}); println() | |
123, 4.56, (7, 8, 9), 4/5, 6.283185307179586, {x:7, y:4} | |
test output: | |
RESULT: | |
nil | |
<============================================================================ | |
>============================================================================ | |
var x={a:1,b:2,c:3} | |
x.c = x | |
"(%a, %b, %c, %d, %e, %f, %g)" fmt(123, 4.56, (7,8,9), 4/5, 2π, #f32[1.1,2.2,3.3], x) println | |
(123, 4.56, (7, 8, 9), 4/5, 6.283185307179586, #f32[1.1f, 2.2f, 3.3f], {a:1, b:2, c:{ ⟘^1 }}) | |
test output: | |
RESULT: | |
(123, 4.56, (7, 8, 9), 4/5, 6.283185307179586, #f32[1.1f, 2.2f, 3.3f], {a:1, b:2, c:{ ⟘^1 }}) | |
<============================================================================ | |
>============================================================================ | |
-- 100 doors http://rosettacode.org/wiki/100_doors | |
let N = 100 | |
fn zeroes(n Int) = 0 ever take(n) | |
fn f(n Int) = cyc(n zeroes $ [1]) take(N) | |
fn absdif(a,b) = abs(a-b) | |
let result = to(0,N-1) f reduce(absdif, N zeroes) | |
fn prall(list) = list forEach \x[ x println ] | |
result clump(10) prall | |
[1, 0, 0, 1, 0, 0, 0, 0, 1, 0] | |
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0] | |
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0] | |
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0] | |
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0] | |
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0] | |
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0] | |
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0] | |
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0] | |
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1] | |
test output: | |
RESULT: | |
[ [1, 0, 0, 1, 0, 0, 0, 0, 1, 0], | |
. [0, 0, 0, 0, 0, 1, 0, 0, 0, 0], | |
. [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], | |
. [0, 0, 0, 0, 0, 1, 0, 0, 0, 0], | |
. [0, 0, 0, 0, 0, 0, 0, 0, 1, 0], | |
. [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], | |
. [0, 0, 0, 1, 0, 0, 0, 0, 0, 0], | |
. [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], | |
. [1, 0, 0, 0, 0, 0, 0, 0, 0, 0], | |
. [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]] | |
<============================================================================ | |
>============================================================================ | |
-- factorial, recursive version http://rosettacode.org/wiki/Factorial | |
fn fac(n Int) = n <= 1 ? 1 : n * fac(n-1) | |
fac([0,1,5,7,10]) | |
test output: | |
RESULT: | |
[1, 1, 120, 5040, 3628800] | |
<============================================================================ | |
>============================================================================ | |
-- factorial, iterative version http://rosettacode.org/wiki/Factorial | |
fn fac(n Int) = to(1,max(1,n)) reduce(*,1) | |
fac([0,1,5,7,10]) | |
test output: | |
RESULT: | |
[1, 1, 120, 5040, 3628800] | |
<============================================================================ | |
>============================================================================ | |
-- accumulator factory http://rosettacode.org/wiki/Accumulator_factory | |
fn foo(a) { var x = a; \z[ x = x + z ] } | |
let x = foo(1) | |
x(5) | |
x(2.3) println | |
8.3 | |
test output: | |
RESULT: | |
8.3 | |
<============================================================================ | |
>============================================================================ | |
-- hailstone sequence http://rosettacode.org/wiki/Hailstone_sequence | |
fn even(n Int) = (n & 1) == 0 | |
fn hailNext(n Int) = n even ? n/2 : n>1 ? 3*n+1 : eos | |
fn hail(n Int) = n iter(hailNext) take(10000) | |
hail(7) println | |
--hail(9) println | |
--hail(27) println | |
fn longestHailstoneSeq(n Int) { | |
let (maxlen, maxi, j) = to(1,n) @ hail @ len reduce(\x,y[let (m,i,j)=x; let z=max(y,m); (z, z>m?j:i, j+1)], (0,0,1)) | |
"The longest hailstone sequence less than %1 has length %2 and starting value %3." fmt(n,maxlen,maxi) println | |
} | |
longestHailstoneSeq(100) | |
[7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1] | |
The longest hailstone sequence less than 100 has length 119 and starting value 97. | |
test output: | |
RESULT: | |
The longest hailstone sequence less than 100 has length 119 and starting value 97. | |
<============================================================================ | |
>============================================================================ | |
-- hailstone sequence http://rosettacode.org/wiki/Hailstone_sequence | |
fn even(n Int) = (n & 1) == 0 | |
fn hailNext(n Int) = n even ? n/2 : 3*n+1 | |
fn hail(n Int) { | |
let out = [] | |
var k = n; | |
while (k != 1) { | |
out push(k) | |
k = k even ? k/2 : 3*k+1 | |
} | |
out push(1) | |
out | |
} | |
hail(7) println | |
fn longestHailstoneSeq(n Int) { | |
var maxlen = 0 | |
var maxi = nil | |
var i = 1; | |
while (i < n) { | |
let l = hail(i) len | |
if (l > maxlen) { | |
maxlen = l | |
maxi = i | |
} | |
i = i+1 | |
} | |
let s = "The longest hailstone sequence less than %1 has length %2 and starting value %3." fmt(n,maxlen,maxi) | |
s println | |
} | |
longestHailstoneSeq(100) | |
[7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1] | |
The longest hailstone sequence less than 100 has length 119 and starting value 97. | |
test output: | |
RESULT: | |
The longest hailstone sequence less than 100 has length 119 and starting value 97. | |
<============================================================================ | |
>============================================================================ | |
3 iter \x[x==0 ? eos : x-1] | |
test output: | |
RESULT: | |
[3, 2, 1, 0] | |
<============================================================================ | |
>============================================================================ | |
let z = [{a:1, x:{y:8}},{a:2, x:{y:8}},{a:3, x:{y:8}}] | |
z forEach \t { | |
t.x.y = 9 | |
} | |
z println | |
[{a:1, x:{y:8}}, {a:2, x:{y:8}}, {a:3, x:{y:8}}] | |
test output: | |
RESULT: | |
[{a: 1, x: {y: 8}}, {a: 2, x: {y: 8}}, {a: 3, x: {y: 8}}] | |
<============================================================================ | |
>============================================================================ | |
-- This example will be a compiler for SynthDefs from this language's code to C++. | |
-- It will follow the same design as what already works in Python. | |
-- It is not finished. | |
-- For this example, I only define those functions needed to create the "analog-bubbles" example from SuperCollider. | |
--------------------------------------------------------------------------- | |
let DO_REWRITE = true | |
let DEBUG_REWRITE = false | |
let DEBUG_HASHCONS = true | |
--------------------------------------------------------------------------- | |
fn prod(x) = x reduce(*,1) | |
--------------------------------------------------------------------------- | |
--- Rate | |
defClass(#Rate, Scalar, {}) | |
defClass(#TBDRate, Rate, {value:-2}) | |
defClass(#IncompatibleRate, Rate, {value:-1}) | |
defClass(#ConstRate, Rate, {value:0}) | |
defClass(#InitRate, Rate, {value:1}) | |
defClass(#ResetRate, Rate, {value:2}) | |
defClass(#EventRate, Rate, {value:3}) | |
defClass(#AudioRate, Rate, {value:4, ratio:1/1}) | |
-- The 'init' function is called when creating a new instance of a class. | |
-- Rather than 'this' or 'self', by convention I use 'o' as the first argument of a generic function. | |
fn init(o EventRate, rateID Int) { | |
o.rateID = rateID | |
o | |
} | |
fn init(o AudioRate, ratio Rational) { | |
o.ratio = ratio | |
o | |
} | |
-- singleton rates | |
Rate.TBD = TBDRate new | |
Rate.Incompatible = IncompatibleRate new | |
Rate.Const = ConstRate new | |
Rate.Init = InitRate new | |
Rate.Reset = ResetRate new | |
Rate.Audio = AudioRate() | |
fn min(a Rate, b Rate) { a.value <= b.value ? a : b } | |
fn max(a Rate, b Rate) { a.value >= b.value ? a : b } | |
--------------------------------------------------------------------------- | |
--- Classes | |
-- A signal graph contains UGens that are computed at the same time. One pull unit. | |
defClass(#SignalGraph, Scalar, {}, {curSignalGraph: nil}) | |
-- A SynthDef defines a plug-in for the audio engine. | |
defClass(#SynthDef, Scalar, {}, {curSynthDef: nil}) | |
-- Signals are inputs to unit generators. | |
-- Signals have a rate, element type and shape. | |
defClass(#Signal, Scalar, {}, {serialNos: 0}) | |
-- A unit generator (UGen) is a processor of signals. | |
-- Here UGens are just math ops, time series ops, and I/O (jacks, buffers, controls). | |
-- Most things that are UGens in SuperCollider, are just functions in this language, built on the above operations. | |
defClass(#UGen, Signal, {}) | |
defClass(#PullUGen, UGen, {}) | |
-- a tree of UGens in an expression. | |
defClass(#UGenTree, Scalar, {}) | |
-- A UGen for a TimeSeriesVar | |
defClass(#TSUGen, UGen, {}) | |
-- A ConstSignal is a wrapper for constant values that makes them Signals. | |
defClass(#ConstSignal, Signal, {rate:}) | |
-- A TimeSeriesVar defines some recursive state of a signal graph. A delay line. | |
defClass(#TimeSeriesVar, Scalar, {}, {serialNos: 0}) | |
defClass(#MathOpUGen, UGen, {}) | |
defClass(#UnopUGen, MathOpUGen, { | |
isMonotonicUp: false, | |
isMonotonicDn: false, | |
}) | |
defClass(#FloatUnop, UnopUGen, {}) | |
defClass(#FloatOrComplexUnop, UnopUGen, {}) | |
defClass(#CastOp, UnopUGen, {}) | |
defClass(#BinopUGen, MathOpUGen, {}, { | |
isAssociative: false, | |
isCommutative: false | |
}) | |
defClass(#BitwiseBinop, BinopUGen, {}) | |
defClass(#OpAdd, BinopUGen, {}, { | |
cname: "+", | |
isAssociative: true, | |
isCommutative: true, | |
gf:+, | |
}) | |
defClass(#OpSub, BinopUGen, {}, { cname: "-", gf:- }) | |
defClass(#OpMod, BinopUGen, {}, { | |
cname: "mod", | |
gf:%, | |
}) | |
defClass(#OpMul, BinopUGen, {}, { | |
cname: "*", | |
isAssociative: true, | |
isCommutative: true, | |
gf:*, | |
}) | |
defClass(#OpDiv, BinopUGen, {}, { cname: "/", gf:/ }) | |
defClass(#OpPow, BinopUGen, {}, { cname: "pow", gf:^ }) | |
defClass(#OpATan2, BinopUGen, {}, { cname: "atan2", gf:atan2 }) | |
defClass(#OpHypot, BinopUGen, {}, { cname: "hypot", gf:hypot, | |
isAssociative: true, | |
isCommutative: true }) | |
defClass(#OpMin, BinopUGen, {}, { cname: "min", gf:min, | |
isAssociative: true, | |
isCommutative: true }) | |
defClass(#OpMax, BinopUGen, {}, { cname: "max", gf:max, | |
isAssociative: true, | |
isCommutative: true }) | |
defClass(#OpLT, BinopUGen, {}, { cname: "<", gf:< }) | |
defClass(#OpLE, BinopUGen, {}, { cname: "<=", gf:<= }) | |
defClass(#OpGT, BinopUGen, {}, { cname: ">", gf:> }) | |
defClass(#OpGE, BinopUGen, {}, { cname: ">=", gf:>= }) | |
defClass(#OpEQ, BinopUGen, {}, { cname: "==", gf:==, isCommutative: true }) | |
defClass(#OpNE, BinopUGen, {}, { cname: "!=", gf:!=, isCommutative: true }) | |
defClass(#OpF32, CastOp, {}, { cname: "f32", gf:defGeneric(#f32) }) | |
defClass(#OpF64, CastOp, {}, { cname: "f64", gf:defGeneric(#f64) }) | |
defClass(#OpNeg, UnopUGen, {}, { cname: "-", gf:- }) | |
defClass(#OpAbs, UnopUGen, {}, { cname: "abs", gf:abs }) | |
defClass(#OpBitNot, UnopUGen, {}, { cname: "~", gf:~ }) | |
defClass(#OpFloor, FloatUnop, {}, { cname: "floor", gf:floor, isMonotonicUp: true }) | |
defClass(#OpCeil, FloatUnop, {}, { cname: "ceil", gf:ceil, isMonotonicUp: true }) | |
--defClass(#OpRound, FloatUnop, {}, { cname: "rint", gf:rint, isMonotonicUp: true }) | |
defClass(#OpSqrt, FloatUnop, {}, { cname: "sqrt", gf:sqrt, isMonotonicUp: true }) | |
defClass(#OpCbrt, FloatUnop, {}, { cname: "cbrt", gf:cbrt, isMonotonicUp: true }) | |
defClass(#OpExp, FloatOrComplexUnop, {}, { cname: "exp", gf:exp, isMonotonicUp: true }) | |
defClass(#OpExp2, FloatOrComplexUnop, {}, { cname: "exp2", gf:exp2, isMonotonicUp: true }) | |
defClass(#OpExp10, FloatOrComplexUnop, {}, { cname: "exp10", gf:exp10, isMonotonicUp: true }) | |
defClass(#OpExpm1, FloatOrComplexUnop, {}, { cname: "expm1", gf:expm1, isMonotonicUp: true }) | |
defClass(#OpLog, FloatOrComplexUnop, {}, { cname: "log", gf:log, isMonotonicUp: true }) | |
defClass(#OpLog2, FloatOrComplexUnop, {}, { cname: "log2", gf:log2, isMonotonicUp: true }) | |
defClass(#OpLog10, FloatOrComplexUnop, {}, { cname: "log10", gf:log10, isMonotonicUp: true }) | |
defClass(#OpLog1p, FloatOrComplexUnop, {}, { cname: "log1p", gf:log1p, isMonotonicUp: true }) | |
defClass(#OpSin, FloatOrComplexUnop, {}, { cname: "sin", gf:sin }) | |
defClass(#OpCos, FloatOrComplexUnop, {}, { cname: "cos", gf:cos }) | |
defClass(#OpTan, FloatOrComplexUnop, {}, { cname: "tan", gf:tan }) | |
defClass(#OpASin, FloatOrComplexUnop, {}, { cname: "asin", gf:asin, isMonotonicUp:true }) | |
defClass(#OpACos, FloatOrComplexUnop, {}, { cname: "acos", gf:acos, isMonotonicDn:true }) | |
defClass(#OpATan, FloatOrComplexUnop, {}, { cname: "atan", gf:atan, isMonotonicUp:true }) | |
defClass(#OpSinh, FloatOrComplexUnop, {}, { cname: "sinh", gf:sinh, isMonotonicUp:true }) | |
defClass(#OpCosh, FloatOrComplexUnop, {}, { cname: "cosh", gf:cosh }) | |
defClass(#OpTanh, FloatOrComplexUnop, {}, { cname: "tanh", gf:tanh, isMonotonicUp:true }) | |
defClass(#OpASinh, FloatOrComplexUnop, {}, { cname: "asinh", gf:asinh, isMonotonicUp:true }) | |
defClass(#OpACosh, FloatOrComplexUnop, {}, { cname: "acosh", gf:acosh, isMonotonicUp:true }) | |
defClass(#OpATanh, FloatOrComplexUnop, {}, { cname: "atanh", gf:atanh, isMonotonicUp:true }) | |
defClass(#OpSinPi, FloatOrComplexUnop, {}, { cname: "__sinpi", gf:sinpi }) | |
defClass(#OpCosPi, FloatOrComplexUnop, {}, { cname: "__cospi", gf:cospi }) | |
defClass(#ControlUGen, UGen, {}) | |
defClass(#JackIn, UGen, {}, { inputIDs: 0 }) | |
defClass(#JackOut, UGen, {}, { outputIDs: 0 }) | |
defClass(#TSFixRead, TSUGen, {rate: Rate.Audio}) | |
defClass(#TSVarRead, TSUGen, {rate: Rate.Audio}) | |
defClass(#TSWrite, TSUGen, {rate: Rate.Audio}) | |
defClass(#TSInit, TSUGen, {rate: Rate.Reset}) | |
defClass(#SampleRateUGen, UGen, {rate: Rate.Init}) | |
defClass(#SignalVecUGen, UGen, {}) | |
defClass(#SelectUGen, UGen, {}) | |
defClass(#DebugUGen, UGen, {}) | |
defClass(#RandomUGenBase, UGen, {}) | |
defClass(#URandUGen, RandomUGenBase, {}) | |
defClass(#BRandUGen, RandomUGenBase, {}) | |
--------------------------------------------------------------------------- | |
-- Rate functions | |
fn max(a, b) = a < b ? b : a | |
fn <(a Rate, b Rate) = a.value < b.value | |
fn <=(a Rate, b Rate) = a.value <= b.value | |
fn ==(a Rate, b Rate) = a.value == b.value | |
fn calcOutputRate(aa Rate, bb Rate) { | |
var (a, b) = (aa, bb) | |
if (a == b) { | |
if (a isa(EventRate)) { | |
if (a.rateID != b.rateID) { | |
return EventRate(a.rateID | b.rateID) | |
} | |
} else if (a isa(AudioRate)) { | |
if (a.ratio != b.ratio) { | |
return Rate.Incompatible | |
} | |
} | |
return a | |
} else if (b < a) { | |
(a, b) = (b, a) | |
} | |
if (a <= Rate.Reset) { | |
return b | |
} | |
-- mixed combinations of Audio and Event rates are not allowed. | |
return Rate.Incompatible | |
} | |
--------------------------------------------------------------------------- | |
-- ElemType | |
fn isPowerOfTwo(x Int) = (x & (x-1)) == 0 | |
defClass(#ElemType, Scalar, {}) | |
fn init(o ElemType, value Int) { | |
o.value = value | |
o | |
} | |
fn ~(a ElemType) { | |
ElemType(~a.value) | |
} | |
fn |(a ElemType, b ElemType) { | |
ElemType(a.value | b.value) | |
} | |
fn &(a ElemType, b ElemType) { | |
ElemType(a.value & b.value) | |
} | |
ElemType.EMPTY = ElemType(0) | |
-- types with 32 bit elements | |
ElemType.INT32 = ElemType(1) | |
ElemType.FLOAT32 = ElemType(2) | |
ElemType.COMPLEX32 = ElemType(4) | |
-- types with 64 bit elements | |
ElemType.INT64 = ElemType(8) | |
ElemType.FLOAT64 = ElemType(16) | |
ElemType.COMPLEX64 = ElemType(32) | |
-- combinations | |
ElemType.ANY_INT = ElemType.INT32 | ElemType.INT64 | |
ElemType.ANY_FLOAT = ElemType.FLOAT32 | ElemType.FLOAT64 | |
ElemType.ANY_COMPLEX = ElemType.COMPLEX32 | ElemType.COMPLEX64 | |
ElemType.ANY_FLOAT_OR_COMPLEX = ElemType.ANY_FLOAT | ElemType.ANY_COMPLEX | |
ElemType.ANY_REAL = ElemType.ANY_INT | ElemType.ANY_FLOAT | |
ElemType.ANY_NUM = ElemType.ANY_REAL | ElemType.ANY_COMPLEX | |
ElemType.ANY_32_BITS = ElemType.INT32 | ElemType.FLOAT32 | ElemType.COMPLEX32 | |
ElemType.ANY_64_BITS = ElemType.INT64 | ElemType.FLOAT64 | ElemType.COMPLEX64 | |
ElemType.ANY_ELEM = ElemType.ANY_NUM | |
fn rstr(o ElemType) { | |
if (o.value == 0) { return "EMPTY" } | |
if (o.value == 63) { return "ANY_NUM" } | |
var s = "" | |
if (o.value & 1 != 0) { s = s $ "i" } | |
if (o.value & 8 != 0) { s = s $ "I" } | |
if (o.value & 2 != 0) { s = s $ "f" } | |
if (o.value & 16 != 0) { s = s $ "F" } | |
if (o.value & 4 != 0) { s = s $ "x" } | |
if (o.value & 32 != 0) { s = s $ "X" } | |
s | |
} | |
fn isConcrete(o ElemType) = o.value isPowerOfTwo | |
fn isEmpty(o ElemType) = o.value == 0 | |
fn notEmpty(o ElemType) = o.value != 0 | |
fn is32bits(o ElemType) = (o & ElemType.ANY_32_BITS) notEmpty | |
fn is64bits(o ElemType) = (o & ElemType.ANY_64_BITS) notEmpty | |
fn isInt(o ElemType) = (o & ElemType.ANY_INT) notEmpty | |
fn isFloat(o ElemType) = (o & ElemType.ANY_FLOAT) notEmpty | |
fn isComplex(o ElemType) = (o & ElemType.ANY_COMPLEX) notEmpty | |
fn isReal(o ElemType) = (o & ElemType.ANY_COMPLEX) isEmpty | |
fn to64bits(o ElemType) { | |
let lower = (o & ElemType.ANY_32_BITS).value | |
let upper = (o & ElemType.ANY_64_BITS).value | |
ElemType((lower << 3) | upper) | |
} | |
fn to32bits(o ElemType) { | |
let lower = (o & ElemType.ANY_32_BITS).value | |
let upper = (o & ElemType.ANY_64_BITS).value | |
ElemType(lower | (upper >> 3)) | |
} | |
fn complex_to_float(o ElemType) { | |
-- create a type mask for operations that return float output for complex input. e.g. absolute value | |
let cmplx = (o & ElemType.ANY_COMPLEX).value | |
let other = (o & ~ElemType.ANY_COMPLEX).value | |
ElemType(other | (cmplx >> 1)) | |
} | |
fn float_to_complex(o ElemType) { | |
-- create a type mask for operations that return complex output for float input. e.g. complex(real, imag) | |
let flt = (o & ElemType.ANY_FLOAT).value | |
let other = (o & ~ElemType.ANY_FLOAT).value | |
ElemType(other | (flt << 1)) | |
} | |
fn int_to_float(o ElemType) { | |
-- create a type mask for operations that return float output for integer input. e.g. 'true' division | |
let intg = (o & ElemType.ANY_INT).value | |
let other = (o & ~ElemType.ANY_INT).value | |
ElemType(other | (intg << 1)) | |
} | |
fn commonType(aa ElemType, bb ElemType, mask ElemType = ElemType.ANY_ELEM) { | |
let a = aa & mask | |
let b = bb & mask | |
if (a is64bits || b is64bits) { | |
if (a isComplex || b isComplex) { | |
ElemType.COMPLEX64 | |
} else if (a isFloat || b isFloat) { | |
ElemType.FLOAT64 | |
} else { | |
ElemType.INT64 | |
} | |
} else { | |
if (a isComplex || b isComplex) { | |
ElemType.COMPLEX32 | |
} else if (a isFloat || b isFloat) { | |
ElemType.FLOAT32 | |
} else { | |
ElemType.INT32 | |
} | |
} | |
} | |
fn isInf(o Float) = o === inf | |
fn isInf(o) = false | |
fn isInt(o Float) = o == floor(o) | |
fn isInt(o Fraction) = o de == 1 | |
fn isReal(o Complex) = o im == 0. | |
fn getElemType(o Signal) = o.elemType | |
fn getElemType(o Bool) = ElemType.INT32 | |
fn getElemType(o Int) = ElemType.ANY_NUM | |
fn getElemType(o Real) = o isInt ? ElemType.ANY_NUM : ElemType.ANY_FLOAT_OR_COMPLEX | |
fn getElemType(o Complex) = o isReal ? o re getElemType : ElemType.ANY_COMPLEX | |
fn getElemType(o List_int) = ElemType.ANY_NUM | |
fn getElemType(o List_frac) = o all(isInt) ? ElemType.ANY_NUM : ElemType.ANY_FLOAT_OR_COMPLEX | |
fn getElemType(o List_float) = o all(isInt) ? ElemType.ANY_NUM : ElemType.ANY_FLOAT_OR_COMPLEX | |
fn getElemType(o List_complex) = o all(isReal) ? o re getElemType : ElemType.ANY_COMPLEX | |
fn getElemType(o List_obj) = o reduce(\a, b[a & b getElemType], ElemType.ANY_NUM) | |
-- test ElemType | |
[ElemType.ANY_INT, ElemType.ANY_FLOAT, ElemType.ANY_REAL, ElemType.ANY_ELEM] println | |
commonType(ElemType.COMPLEX32, ElemType.INT64) println | |
"F" println | |
--------------------------------------------------------------------------- | |
-- GraphCut | |
defClass(#GraphCut, Scalar, {}) | |
defClass(#GraphCut_NoVar, GraphCut, {}) | |
defClass(#GraphCut_None, GraphCut_NoVar, {value:0}) | |
defClass(#GraphCut_Sink, GraphCut_NoVar, {value:1}) | |
defClass(#GraphCut_TempVar, GraphCut, {}) | |
defClass(#GraphCut_Temp, GraphCut_TempVar, {value:2}) | |
defClass(#GraphCut_FanOut, GraphCut_TempVar, {value:3}) | |
defClass(#GraphCut_InstVar, GraphCut, {}) | |
defClass(#GraphCut_Rate, GraphCut_InstVar, {value:4}) | |
defClass(#GraphCut_Input, GraphCut_InstVar, {value:5}) | |
defClass(#GraphCut_Pull, GraphCut_InstVar, {value:6}) | |
GraphCut.None = GraphCut_None new | |
GraphCut.Sink = GraphCut_Sink new | |
GraphCut.Temp = GraphCut_Temp new | |
GraphCut.FanOut = GraphCut_FanOut new | |
GraphCut.Rate = GraphCut_Rate new | |
GraphCut.Input = GraphCut_Input new | |
GraphCut.Pull = GraphCut_Pull new | |
fn isTempVar(x GraphCut) = x isa(GraphCut_TempVar) | |
fn isInstVar(x GraphCut) = x isa(GraphCut_InstVar) | |
fn <(a GraphCut, b GraphCut) = a.value < b.value | |
proc setGraphCut(o UGen, g GraphCut) { o.graphCut = max(o.graphCut, g) } | |
proc findInputGraphCut(index Int, src Signal, dst UGen) { nil } | |
proc findInputGraphCut(index Int, src UGen, dst UGen) { | |
if (src.graph !== dst.graph) { | |
src setGraphCut(GraphCut.Pull) | |
} else if (src.rate !== dst.rate) { | |
src setGraphCut(GraphCut.Rate) | |
} else if (dst isa(SelectUGen) && index > 0) { | |
src setGraphCut(GraphCut.Temp) | |
} | |
if (src.shape prod == 1 && dst.shape prod > 1) { | |
src setGraphCut(GraphCut.FanOut) | |
} | |
} | |
proc findGraphCutA(o UGen) { | |
if (o isa(JackIn)) { | |
o setGraphCut(GraphCut.Input); | |
} else if (o isa(SignalVecUGen)) { | |
o setGraphCut(GraphCut.Temp); | |
} | |
to(0, o.ins len) findInputGraphCut(o.ins, o) | |
} | |
proc findGraphCutB(o UGen) { | |
let numConsumers = o.consumers len | |
if (numConsumers == 0) { | |
o setGraphCut(GraphCut.Sink) | |
} else if (numConsumers > 1) { | |
o setGraphCut(GraphCut.FanOut) | |
} | |
} | |
proc findGraphCutTS(o) { nil } | |
proc findGraphCutTS(o UGen) { | |
o setGraphCut(GraphCut.Temp) | |
} | |
proc findGraphCuts(ugens, tsvars) { | |
ugens findGraphCutA | |
ugens findGraphCutB | |
tsvars.maxDelay @ findGraphCutTS | |
} | |
--------------------------------------------------------------------------- | |
fn init(o SignalGraph, synth SynthDef, parent SignalGraph = nil) { | |
o.synth = synth -- SynthDef | |
o.parent = parent -- SignalGraph | |
o.puller = nil -- UGen | |
o.trees = [] -- list of UGenTrees | |
o.subgraphs = [] -- list of SignalGraph | |
if (o.parent !== nil) { | |
o.parent.subgraphs add(o) | |
} | |
o | |
} | |
fn init(o SynthDef) { | |
o.rootGraph = SignalGraph(o) | |
o.graphs = [] -- list[SignalGraph] | |
o.ugenTable = IdMap new | |
o.pulls = [] idset -- of UGen | |
o.roots = [] idset -- of Signal | |
o.signals = [] idset -- of Signal | |
o.ugens = [] idset -- of UGen | |
o.controlUgens = [] idset -- of ControlUGen | |
o.inputs = [] idset -- of UGen | |
o.outputs = [] idset -- of UGen | |
o.scalars = [] idset -- of ConstSignal | |
o.arrays = IdMap new -- of List -> array id | |
o.tsvars = [] idset -- of TimeSeriesVar | |
o.rootsToTrees = IdMap new -- of UGen (root) -> UGenTree | |
o.tsallocs = [] -- of TimeSeriesVar. These are the tsvars which allocate. | |
o.allTrees = [] -- list of UGenTree | |
o.initTrees = [] -- ditto.. | |
o.resetTrees = [] | |
o.eventTrees = [] | |
o | |
} | |
fn init(o TimeSeriesVar, slots Record) { | |
o setContents(slots) | |
o.serialNo = TimeSeriesVar.serialNos | |
TimeSeriesVar.serialNos = TimeSeriesVar.serialNos + 1 | |
o.graph = SignalGraph.curSignalGraph | |
o.fixreaders = [] | |
o.varreaders = [] | |
o.initters = [] | |
o.writer = nil | |
o.shape = [] | |
o.elemType = ElemType.ANY_ELEM | |
o.rate = TBDRate() | |
o | |
} | |
fn asSignal(o Signal) = o | |
fn asSignal(o ConcreteNumeric) = ConstSignal(o) | |
fn asSignal(o Seq) { | |
let type = o isTensor | |
type ? ConstSignal(o) : o @ asSignal | |
} | |
fn initSignal(o Signal) { | |
o.hash = nil -- lazy | |
o.shape = [] | |
o.serialNo = Signal.serialNos | |
Signal.serialNos = Signal.serialNos + 1 | |
o.consumers = [] | |
if (!o.rate) { | |
o.rate = Rate.TBD | |
} | |
o.elemType = ElemType.ANY_ELEM | |
o.graphCut = GraphCut.None | |
o.graph = SignalGraph.curSignalGraph | |
o.constraintWasChanged = false | |
o | |
} | |
fn init(o UGen, slots Record) { | |
-- ("new", o class name) println | |
o setContents(slots) | |
o initSignal | |
o rateInference | |
o | |
} | |
fn init(o JackOut, slots Record) { | |
o setContents(slots) | |
o initSignal | |
o.outputID = JackOut.outputIDs | |
JackOut.outputIDs = JackOut.outputIDs + 1 | |
o rateInference | |
o | |
} | |
fn init(o JackIn, slots Record) { | |
o setContents(slots) | |
o initSignal | |
o.inputID = JackIn.inputIDs | |
JackIn.inputIDs = JackIn.inputIDs + 1 | |
o rateInference | |
o | |
} | |
fn init(o ConstSignal, value) { | |
o setContents({value: value}) | |
o initSignal | |
o.rate = Rate.Const | |
o.elemType = value getElemType | |
let (shape, _) = value isTensor | |
o.shape = shape | |
-- "... ConstSignal %1 %2 %3 %4 %5" fmt(o.serialNo, o.value, o.value class name, o.elemType, o.shape) println | |
o | |
} | |
fn init(o RandomUGenBase, shape List = [], seed Int = 0) { | |
o initSignal | |
o.seed = seed != 0 ? seed : rand64() | |
o.shape = [] | |
o.rate = Rate.Audio | |
o | |
} | |
fn call(o SelectUGen_class, a, b, c) { | |
SelectUGen{ins:[a, b, c] asSignal} | |
} | |
fn call(o DebugUGen_class, label, x) { | |
DebugUGen{ins:[x asSignal], label: label} | |
} | |
fn with(o SignalGraph, fun) { | |
let saved = SignalGraph.curSignalGraph | |
SignalGraph.curSignalGraph = o | |
-- put a try/protect here. | |
let out = o fun | |
SignalGraph.curSignalGraph = saved | |
out | |
} | |
fn with(o SynthDef, fun) { | |
if (SynthDef.curSynthDef !== nil) { | |
"SynthDefs should not be nested" throw | |
} | |
SynthDef.curSynthDef = o | |
SignalGraph.curSignalGraph = o.rootGraph | |
-- put a try/protect here. | |
let out = o fun | |
SignalGraph.curSignalGraph = nil | |
SynthDef.curSynthDef = nil | |
out | |
} | |
fn signalStr(o Signal) { | |
"%1 %2" fmt(o class name, o.serialNo) | |
} | |
fn lispStr(o ConstSignal, level) { | |
o.value str | |
} | |
fn lispStr(o UGen, level) { | |
let ugenName = "%^_%^" fmt(o class name, o.serialNo) | |
if (level == 0 && o.ins len != 0) { | |
"(%^ …)" fmt(ugenName) | |
} else { | |
var s = "(%^" fmt(ugenName) | |
let levelm1 = level-1 | |
o.ins forEach \u, i { | |
s = s $ " " | |
s = s $ lispStr(u, levelm1) | |
} | |
s $ ")" | |
} | |
} | |
fn rstr(o TimeSeriesVar) = "TSVar:%^" fmt(o.serialNo) | |
fn calc_eqhash(o UGen) { | |
if (o.hash !== nil) { | |
o.hash | |
} else { | |
let h = (o class idhash, o.ins eqhash, SignalGraph.curSignalGraph idhash) eqhash | |
o.hash = h | |
h | |
} | |
} | |
fn calc_eqhash(o TSUGen) { | |
if (o.hash !== nil) { | |
o.hash | |
} else { | |
let tuple = (o class idhash, o.ins eqhash, SignalGraph.curSignalGraph idhash, o.ts idhash) | |
let h = tuple eqhash | |
o.hash = h | |
h | |
} | |
} | |
fn calc_eqhash(o ConstSignal) { | |
if (o.hash !== nil) { | |
o.hash | |
} else { | |
-- ConstSignal hash depends on its class and value. | |
let h = (o class idhash, o.value eqhash) eqhash | |
o.hash = h | |
h | |
} | |
} | |
fn rateInference(o UGen) { | |
let inputRates = o.ins.rate | |
let outRate = o.ins.rate reduce(calcOutputRate, o.rate) | |
-- "rateInference %1 %2 %3 %4 %5" fmt(o class name, o.serialNo, o.rate, inputRates, outRate) println | |
if (outRate isa(IncompatibleRate)) { | |
-- raise ValueError("incompatible rates.") | |
"incompatible rates." println | |
9 crashme | |
} | |
o.rate = outRate | |
} | |
fn hashCons(o UGen) { | |
let ugenTable = SynthDef.curSynthDef.ugenTable | |
let h = o eqhash | |
let u = if (ugenTable has(h)) { | |
if (DEBUG_HASHCONS) { | |
let v = ugenTable get(h) | |
println("HASH MATCH", o class name, o.serialNo, v.serialNo, h, o.hash, v.hash) | |
o lispStr(3) println | |
v lispStr(3) println | |
} | |
ugenTable get(h) | |
} else { | |
if (DEBUG_HASHCONS) { | |
"MISS %1 %2 %3\n" fmt(o class name, o.serialNo, h hexstr) println | |
} | |
ugenTable put(h, o) | |
o | |
} | |
u | |
} | |
fn hashCons(o TSUGen) = o | |
fn newMathUGen(cls Class, ins List) { | |
var u = cls{ins: ins} | |
-- hash consing | |
let u0 = u | |
u = u hashCons | |
-- rewrite | |
if (DO_REWRITE) { | |
u = u rewrite | |
} | |
u | |
} | |
fn newUnop(cls Class, a Signal) { | |
cls newMathUGen([a]) | |
} | |
fn newBinop(cls Class, a Signal, b Signal) { | |
cls newMathUGen([a, b]) | |
} | |
proc defUGen(cls BinopUGen_class) { | |
let f = \a,b[ cls newBinop(a asSignal, b asSignal) ] | |
let gf = cls.gf | |
defMethod(gf, [UGen, UGen], f) | |
defMethod(gf, [UGen, Obj], f) | |
defMethod(gf, [Obj, UGen], f) | |
} | |
proc defUGen(cls UnopUGen_class) { | |
let f = \a[ cls newUnop(a) ] | |
let gf = cls.gf | |
defMethod(gf, [UGen], f) | |
} | |
[OpAdd, OpSub, OpMul, OpDiv, OpPow, OpATan2, OpHypot, OpMin, OpMax, | |
OpLT, OpLE, OpGT, OpGE, OpEQ, OpNE] defUGen | |
[ | |
OpNeg, OpAbs, OpBitNot, | |
OpF32, OpF64, | |
OpFloor, OpExp2, OpSinPi, OpCosPi, | |
OpSin, OpCos, OpTan, OpASin, OpACos, OpATan, | |
OpSinh, OpCosh, OpTanh, OpASinh, OpACosh, OpATanh, | |
OpLog, OpLog2, OpLog10, OpLog1p, | |
OpExp, OpExp2, OpExp10, OpExpm1, | |
OpSqrt, OpCbrt, | |
] defUGen | |
fn init(o UGenTree, root) { | |
o.root = root | |
o.graph = root.graph | |
-- "UGenTree init" println(o.root class name, o.graph class name) | |
o.ugens = [] idset | |
o.antecedents = [] idset | |
o.index = nil | |
o | |
} | |
--------------------------------------------------------------------------- | |
proc traceGraph(o ConstSignal, visited IdSet) { | |
visited add(o) | |
} | |
proc printOneInput(o ConstSignal) = o.value print | |
proc printOneInput(o UGen) { | |
print(o class name, o.serialNo, o.ins len) | |
} | |
proc printInputs(o UGen) { | |
print(" ins: ") | |
o.ins forEach \u, i { | |
if (i>0) { print(", ") } | |
u printOneInput | |
} | |
print("\n") | |
} | |
proc traceGraph(o UGen, visited IdSet) { | |
if (visited has(o)) { return o } | |
visited add(o) | |
o.ins traceGraph(visited) | |
} | |
proc traceGraph(o TSUGen, visited IdSet) { | |
if (visited has(o)) { return o } | |
visited add(o) | |
o.ins traceGraph(visited) | |
o.ts traceGraph(visited) | |
} | |
proc traceGraph(o TimeSeriesVar, visited IdSet) { | |
if (visited has(o)) { return o } | |
visited add(o) | |
o.initters traceGraph(visited) | |
o.fixreaders traceGraph(visited) | |
o.varreaders traceGraph(visited) | |
o.writer traceGraph(visited) | |
if (o.maxDelay isa(UGen)) { | |
o.maxDelay traceGraph(visited) | |
} | |
o | |
} | |
proc traceGraph(o Nil, visited IdSet) { | |
nil crashme | |
} | |
--------------------------------------------------------------------------- | |
proc categorize(o UGen, sd SynthDef) { | |
sd.signals add(o) | |
sd.ugens add(o) | |
} | |
proc categorize(o JackIn, sd SynthDef) { | |
sd.signals add(o) | |
sd.ugens add(o) | |
sd.inputs add(o) | |
} | |
proc categorize(o JackOut, sd SynthDef) { | |
sd.signals add(o) | |
sd.ugens add(o) | |
sd.outputs add(o) | |
} | |
proc categorize(o ControlUGen, sd SynthDef) { | |
sd.signals add(o) | |
sd.ugens add(o) | |
sd.controlUgens add(o) | |
} | |
proc categorize(o ConstSignal, sd SynthDef) { | |
sd.signals add(o) | |
if (o.value isa(List)) { | |
sd.arrays put(o, sd.arrays len) | |
} else { | |
sd.scalars add(o) | |
} | |
} | |
proc categorize(o TimeSeriesVar, sd SynthDef) { | |
sd.tsvars add(o) | |
} | |
--------------------------------------------------------------------------- | |
proc traceGraph(sd SynthDef, root) { | |
sd.roots = root isa(Signal) ? [root] : root | |
let visited = [] idset | |
root traceGraph(visited) | |
sd.pulls vec traceGraph(visited) | |
println("traceGraph visited", visited len) | |
visited forEach \x, i { | |
println(i, x class name) | |
} | |
visited vec categorize(sd) | |
} | |
proc addConsumer(o Signal, u UGen) { | |
o.consumers add(u) | |
} | |
proc collectConsumers(o UGen) { | |
o.ins addConsumer(o) | |
} | |
--------------------------------------------------------------------------- | |
fn replaceUGen(ugens, oldugen, newugen) { | |
ugens remove(oldugen) | |
ugens vec .ins @ replace(oldugen, newugen) | |
} | |
fn mergeFixReaders(tsvars, ugens) { | |
let head = tsvars head | |
let tail = tsvars tail | |
let d = IdMap new(head.fixreaders.delay, head.fixreaders) | |
println("merge fix map", d) | |
tail.fixreaders forEach \r { | |
let key = r.delay | |
if (d has(key)) { | |
ugens replaceUGen(r, d get(key)) | |
} else { | |
primary.fixreaders add(r) | |
d put(key, r) | |
} | |
} | |
} | |
fn mergeVarReaders(tsvars, ugens) { | |
let head = tsvars head | |
let tail = tsvars tail | |
let d = IdMap new(head.varreaders.delay, head.varreaders) | |
println("merge var map", d) | |
tail.varreaders forEach \r { | |
let key = r.delay | |
if (d has(key)) { | |
ugens replaceUGen(r, d get(key)) | |
} else { | |
primary.varreaders add(r) | |
d put(key, r) | |
} | |
} | |
} | |
fn mergeTSVarsHelper(tsvars, ugens) { | |
let head = tsvars head | |
let tail = tsvars tail | |
if (tsvars len > 1) { | |
"PRIMARY TSVAR %^" fmt(head.serialNo) | |
tsvars mergeFixReaders(ugens) | |
tsvars mergeVarReaders(ugens) | |
tail forEach \ t { | |
" DUPLICATE TSVAR %^" fmt(t.serialNo) | |
t.writer.ts = head | |
ugens remove(t.writer) | |
(t.fixreaders $ t.varreaders $ t.initters) forEach \u { | |
u.ts = head | |
} | |
} | |
} | |
head | |
} | |
proc mergeTSVars(tsvars, ugens) { | |
-- Group tsvars together if they have the same writer, initters and max delay. | |
let d = EqMap new([],[],\[[]]) | |
tsvars forEach \t { | |
let initterKey = \x[(x.ins[0] pointer, x.delay pointer)](t.initters @) asTuple | |
let key = (t.writer.ins[0] pointer, t.graph pointer, | |
t.maxDelay pointer, initterKey) | |
d get(key) add(t) | |
} | |
-- If any entries have multiple values, merge those together. | |
let newTSVars = [] idset | |
d values forEach \t { | |
newTSVars add(t mergeTSVarsHelper(ugens)) | |
} | |
} | |
--------------------------------------------------------------------------- | |
fn calcDelayLengths(tsvars) { | |
-- Determine a maximum fixed delay for any time series vars that have one. | |
-- A tsvar must either have an explicit max delay set when created, or only be | |
-- called with fixed delay reads. | |
var tsallocs = [] | |
tsvars forEach \v { | |
var maxFixedDelay = v.maxDelay | |
if (maxFixedDelay === nil) { | |
maxFixedDelay = v.fixreaders.delay reduce(max, 0) | |
maxFixedDelay = v.initters.delay reduce(max, maxFixedDelay) | |
if (maxFixedDelay === 0) { | |
"the delay line has no specified bound" println | |
9 crashme | |
} | |
} | |
if (maxFixedDelay isa(Real)) { | |
v.maxFixedDelay = maxFixedDelay nextPowerOfTwo | |
v.mask = v.maxFixedDelay - 1 | |
} else if (maxFixedDelay isa(UGen)) { | |
tsallocs add(v) | |
} | |
} | |
tsallocs | |
} | |
--------------------------------------------------------------------------- | |
fn shortName(o UGen) = "%1 %2" fmt(o.serialNo, o class name) | |
fn shortName(o ConstSignal) { | |
let valueStr = o.value isa(List) ? "<array>" : o.value str | |
"%1 %2 %3" fmt(o.serialNo, o class name, valueStr) | |
} | |
fn shortName(o TSUGen) = "%1 %2 %3" fmt(o.serialNo, o class name, o.ts.serialNo) | |
--------------------------------------------------------------------------- | |
fn constrainTypes(o UGen, inTypes, outType) { | |
-- "constrainTypes UGen %1 %2" fmt(o class name, o.ins @ class name) println | |
let newType = inTypes reduce(&, outType) | |
(newType repeat(inTypes len), newType) | |
} | |
fn constrainTypes(o SelectUGen, inTypes, outType) { | |
-- "constrainTypes SelectUGen" println | |
let newTestType = inTypes[0] & ElemType.ANY_REAL | |
let newType = inTypes[1] & inTypes[2] & outType | |
([newTestType, newType, newType], newType) | |
} | |
fn constrainTypes(o PullUGen, inTypes, outType) { | |
-- "constrainTypes PullUGen" println | |
-- A pull ugen is a sink, so has no consumers. | |
-- The input is a gate, which must be real. | |
let gateType = inTypes[0] & ElemType.ANY_REAL | |
([gateType], ElemType.EMPTY) | |
} | |
fn constrainTypes(o UnopUGen, inTypes, outType) { | |
-- "constrainTypes UnopUGen %1 %2" fmt(o class name, o.ins @ class name) println | |
let newType = inTypes[0] & outType | |
([newType], newType) | |
} | |
fn constrainTypes(o BinopUGen, inTypes, outType) { | |
-- "constrainTypes BinopUGen %1 %2" fmt(o class name, o.ins @ class name) println | |
-- (inTypes[0], inTypes[1], outType) println | |
let newType = inTypes[0] & inTypes[1] & outType | |
([newType, newType], newType) | |
} | |
fn constrainTypes(o OpAbs, inTypes, outType) { | |
-- "constrainTypes OpAbs" println | |
let newType = inTypes[0] & outType |> complexToFloat | |
([newType], newType) | |
} | |
fn constrainTypes(o OpBitNot, inTypes, outType) { | |
-- "constrainTypes OpBitNot" println | |
let newType = inTypes[0] & outType & ElemType.ANY_INT | |
([newType], newType) | |
} | |
fn constrainTypes(o FloatUnop, inTypes, outType) { | |
-- "constrainTypes FloatUnop %1 %2" fmt(o class name, o.ins @ class name) println | |
let newType = inTypes[0] & outType & ElemType.ANY_FLOAT | |
([newType], newType) | |
} | |
fn constrainTypes(o FloatOrComplexUnop, inTypes, outType) { | |
-- "constrainTypes FloatOrComplexUnop %1 %2" fmt(o class name, o.ins @ class name) println | |
let newType = inTypes[0] & outType & ElemType.ANY_FLOAT_OR_COMPLEX | |
([newType], newType) | |
} | |
fn constrainTypes(o CastOp, inTypes, outType) { | |
-- "constrainTypes CastOp" println | |
let newType = inTypes[0] & o.inTypeMask | |
([newType], outType & o.outType) | |
} | |
fn constrainTypes(o BitwiseBinop, inTypes, outType) { | |
let newType = inTypes[0] & inTypes[1] & outType & ElemType.ANY_INT | |
([newType, newType], newType) | |
} | |
fn constrainTypes(o TSUGen, inTypes, outType) { | |
-- "constrainTypes TSUGen %1 %2" fmt(o.ts class name, o.ts.elemType) println | |
let newType = inTypes reduce(&, outType & o.ts.elemType) | |
(newType repeat(inTypes len), newType) | |
} | |
--------------------------------------------------------------------------- | |
proc typeInferenceInputs(o UGen, worklist IdSet, in Signal, oldType ElemType, newType ElemType) { | |
if (newType isEmpty) { | |
let msg = "Incompatible type constraints for %1 -> %2" fmt( | |
in shortName, o shortName) | |
msg println | |
TypeError(msg) throw | |
} | |
if (newType != oldType) { | |
in.elemType = newType | |
in.constraintWasChanged = true | |
worklist add(in) | |
} | |
} | |
proc typeInference(o UGen, worklist IdSet) { | |
--"typeInference UGen" println | |
-- get input and output types | |
let inTypesOld = o.ins.elemType | |
let outTypeOld = o.elemType | |
-- apply constraints | |
let (inTypesNew, outTypeNew) = o constrainTypes(inTypesOld, outTypeOld) | |
-- propagate constraints to inputs | |
typeInferenceInputs(o, worklist, o.ins, inTypesOld, inTypesNew) | |
if (o isa(TimeSeriesVar)) { | |
if (outTypeNew != outTypeOld || o.constraintWasChanged) { | |
o.ts typeInference(worklist, outTypeNew) | |
} | |
} | |
if (o.consumers len > 0) { | |
-- Output type is irrelevant for sinks. | |
if (outTypeNew isEmpty) { | |
"%1 -> %2" fmt(inTypesOld, outTypeOld) println | |
"%1 -> %2" fmt(inTypesNew, outTypeNew) println | |
let msg = "Incompatible type constraints for %1" fmt(o shortName) | |
msg println | |
TypeError(msg) throw | |
} | |
-- propagate out type constraint to consumers | |
if (outTypeNew != outTypeOld || o.constraintWasChanged) { | |
o.elemType = outTypeNew | |
worklist addAll(o.consumers) | |
} | |
} else { | |
o.elemType = outTypeNew | |
} | |
o.constraintWasChanged = false | |
} | |
proc typeInferenceNoInputs(o Signal, worklist IdSet) { | |
--"typeInferenceNoInputs" println | |
-- propagate out type constraint to consumers | |
if (o.constraintWasChanged) { | |
worklist addAll(o.consumers) | |
} | |
o.constraintWasChanged = false | |
} | |
proc typeInference(o ConstSignal, worklist IdSet) { | |
--"typeInference ConstSignal" println | |
o typeInferenceNoInputs(worklist) | |
} | |
proc typeInference(o SampleRateUGen, worklist IdSet) { | |
--"typeInference SampleRateUGen" println | |
o typeInferenceNoInputs(worklist) | |
} | |
proc typeInference(o RandomUGenBase, worklist IdSet) { | |
--"typeInference RandomUGenBase" println | |
o typeInferenceNoInputs(worklist) | |
} | |
proc typeInference(o TimeSeriesVar, worklist IdSet, elemType ElemType) { | |
--"typeInference TimeSeriesVar" println | |
if (o.elemType != elemType) { | |
o.elemType = elemType | |
let f = \u[ | |
if (u.elemType != elemType) { | |
worklist add(u) | |
} | |
] | |
o.initters forEach(f) | |
o.fixreaders forEach(f) | |
o.varreaders forEach(f) | |
f(o.writer) | |
} | |
} | |
proc typeInference(o UGen) { | |
--"typeInference top" println | |
let worklist = [] idset | |
worklist add(o) | |
while (worklist len > 0) { | |
worklist pop typeInference(worklist) | |
} | |
} | |
--------------------------------------------------------------------------- | |
let elemTypePreferenceOrder = [ | |
ElemType.INT32, ElemType.INT64, | |
ElemType.FLOAT32, ElemType.FLOAT64, | |
ElemType.COMPLEX32, ElemType.COMPLEX64 | |
] | |
proc setUndeterminedElemTypeToDefault(o Scalar) { | |
let inElemType = o.elemType | |
o.elemType = elemTypePreferenceOrder find(\prefElemType { | |
--println("suettd", prefElemType, inElemType) | |
(prefElemType & inElemType) notEmpty}, ElemType.EMPTY) | |
--println("o.elemType", o.elemType); | |
} | |
--------------------------------------------------------------------------- | |
fn equalizeRank(aa List, bb List) { | |
var (a, b) = (aa, bb) | |
if (a len > b len) { | |
b = 1 repeat(a len - b len) $ b | |
} else if (a len < b len) { | |
a = 1 repeat(b len - a len) $ a | |
} | |
return (a, b) | |
} | |
fn broadcastDim(a Int, b Int) { | |
if (b == 1 || a == b) { return a } | |
if (a == 1) { return b } | |
let msg = "shapes are not compatible" | |
msg println | |
TypeError("shapes are not compatible") throw | |
} | |
fn broadcastShapes(aa List, bb List) { | |
var (a, b) = equalizeRank(aa, bb) | |
broadcastDim(a, b) | |
} | |
proc shapeInference(ugens) { | |
-- ">shapeInference ugens" println | |
let worklist = [] idset | |
worklist addAll(ugens) | |
while (worklist len > 0) { | |
worklist pop shapeInference(worklist) | |
} | |
-- "<shapeInference ugens" println | |
} | |
proc shapeInference(o ConstSignal, worklist, initShape List = [], start=0) { | |
-- "-shapeInference ConstSignal" println | |
nil | |
} | |
proc shapeInference(o UGen, worklist, initShape List = [], start=0) { | |
-- ">shapeInference UGen %1" fmt(o pointer hexstr) println | |
var outShape = o.shape | |
if (initShape) { | |
outShape = broadcastShapes(outShape, initShape) | |
} | |
outShape = (o.ins drop(start)).shape reduce(broadcastShapes, outShape) | |
if (outShape !=` o.shape) { | |
o.shape = outShape | |
worklist addAll(o.consumers) | |
} | |
-- "<shapeInference UGen %1" fmt(o pointer hexstr) println | |
} | |
proc shapeInference(o TSUGen, worklist, initShape List = [], start=0) { | |
-- ">shapeInference TSUGen %1" fmt(o pointer hexstr) println | |
var outShape = broadcastShapes(o.shape, o.ts.shape) | |
outShape = o.ins.shape reduce(broadcastShapes, outShape) | |
if (outShape !=` o.shape) { | |
o.shape = outShape | |
worklist addAll(o.consumers) | |
} | |
o.ts shapeInference(worklist, o.shape) | |
-- "<shapeInference TSUGen %1" fmt(o pointer hexstr) println | |
} | |
proc shapeInference(o TimeSeriesVar, worklist, shape List) { | |
-- ">shapeInference TimeSeriesVar %1" fmt(o pointer hexstr) println | |
o.shape = shape | |
let f = \u[ | |
if (u.shape !=` shape) { | |
worklist add(u) | |
} | |
] | |
o.initters forEach(f) | |
o.fixreaders forEach(f) | |
o.varreaders forEach(f) | |
f(o.writer) | |
-- "<shapeInference TimeSeriesVar %1" fmt(o pointer hexstr) println | |
} | |
--------------------------------------------------------------------------- | |
fn isTreeRoot(o UGen) { | |
o.graphCut !== GraphCut.None | |
} | |
fn isntTreeRoot(o UGen) = o.graphCut === GraphCut.None | |
proc traceTree_(o Signal, tree, visited) { | |
-- "traceTree_?? %1" fmt(o class name) println | |
nil | |
} | |
proc traceTree_(o UGen, tree, visited) { | |
-- "traceTree_ %1 %2 %3" fmt(o class name, o.serialNo, o.ins len) println | |
-- Find all ugens within a tree, by searching from the root up to any graph cuts. | |
if (visited has(o)) { return o } | |
visited add(o) | |
-- println("o isntTreeRoot", o isntTreeRoot, "o === tree.root", o === tree.root) | |
-- println(o pointer hexstr, tree.root pointer hexstr) | |
if (o isntTreeRoot || o === tree.root) { | |
tree.ugens add(o) | |
o.root = tree.root | |
-- "ROOT %1 %2 %5 .root = %3 %4" fmt(o class name, o.serialNo, | |
-- tree.root class name, tree.root.serialNo, | |
-- o.ins len) println | |
o.ins traceTree_(tree, visited) | |
} else { | |
tree.antecedents add(o) | |
-- println("ANT.", o lispStr(2), "=>", tree.root lispStr(2)) | |
} | |
} | |
fn traceTree(o UGen) { | |
-- Find all ugens within a tree. traceTree_ does the work. | |
let tree = UGenTree(o) | |
traceTree_(o, tree, IdSet new) | |
tree | |
} | |
fn cutGraphToTrees(ugens) { | |
-- Cut the graph into trees by cutting at each ugen which has a GraphCut. | |
let rootsToTrees = IdMap new | |
var index = 0 | |
ugens filter(isTreeRoot) forEach(\u[ | |
let tree = u traceTree | |
tree.index = index | |
index = index + 1 | |
rootsToTrees put(u, tree) | |
]) | |
rootsToTrees | |
} | |
--------------------------------------------------------------------------- | |
fn addTSVarAntecedents(o UGen, rootsToTrees) { nil } | |
fn addTSVarAntecedents(o TSWrite, rootsToTrees) { | |
-- Make sure that time series writers get put after their readers | |
-- by putting an antecedent link in the graph. | |
let tswTree = rootsToTrees get(o.root) | |
let f = \tsr[ | |
if (tsr.root !== o.root) { -- the reader is in the same statement | |
tswTree.antecedents add(tsr.root) | |
} | |
] | |
o.ts.fixreaders forEach(f) | |
o.ts.varreaders forEach(f) | |
} | |
fn highestSubParent(o, s) { | |
-- if self is an ancestor of sub, then return the immediate descendent of self on that path, else nil | |
var sub = s | |
while (sub) { | |
if (sub.parent === o) { return sub } | |
sub = sub.parent | |
} | |
nil | |
} | |
fn addPullAntecedents(src, dst, rootsToTrees) { nil } | |
fn addPullAntecedents(src UGen, dst UGen, rootsToTrees) { | |
if (src.graph === dst.graph) { return nil } | |
let p1 = highestSubParent(src.graph, dst.graph) | |
if (p1 && p1.puller) { | |
let pull_tree = rootsToTrees get(dst.root) | |
pull_tree.antecedents add(src.root) | |
} | |
-- src is in a subgraph | |
let p2 = highestSubParent(dst.graph, src.graph) | |
if (p2 && p2.puller) { | |
let pull_tree = rootsToTrees get(dst.root) | |
pull_tree.antecedents add(p2.puller) | |
} | |
} | |
fn addPullAntecedents(dst UGen, rootsToTrees) { | |
addPullAntecedents(dst.inputs, dst, rootsToTrees) | |
} | |
proc sortTrees_(root UGen, rootsToTrees, visited, sortedTrees) { | |
if (visited has(root)) { return nil } | |
visited add(root) | |
let tree = rootsToTrees get(root) | |
if (!tree) { | |
"root not found" throw | |
} | |
tree.antecedents vec sortTrees_(rootsToTrees, visited, sortedTrees) | |
sortedTrees add(tree) | |
} | |
fn sortTrees(rootsToTrees) { | |
let visited = IdSet new | |
let sortedTrees = [] | |
rootsToTrees keys sortTrees_(rootsToTrees, visited, sortedTrees) | |
sortedTrees | |
} | |
proc splitClocks_(synth SynthDef, tree UGenTree, rate InitRate) { | |
synth.initTrees add(tree) } | |
proc splitClocks_(synth SynthDef, tree UGenTree, rate ResetRate) { | |
synth.resetTrees add(tree) } | |
proc splitClocks_(synth SynthDef, tree UGenTree, rate EventRate) { | |
synth.eventTrees add(tree) } | |
proc splitClocks_(synth SynthDef, tree UGenTree, rate AudioRate) { | |
tree.graph.trees add(tree) | |
} | |
proc splitClocks_(synth SynthDef, tree UGenTree, rate ConstRate) { | |
-- "CONST TREE? %^" fmt(tree.root lispStr(3)) println | |
tree.graph.trees add(tree) | |
} | |
fn splitClocks(synth SynthDef, sortedTrees) { | |
-- "splitClocks top" println | |
-- "sortedTrees %^" fmt(sortedTrees len) println | |
splitClocks_(synth, sortedTrees, sortedTrees.root.rate) | |
} | |
--------------------------------------------------------------------------- | |
let nullop_fun_names = [ | |
"urand", "birand" | |
] | |
let float_unop_fun_names = [ | |
"__sinpi", "__cospi", "__tanpi", "__exp10", | |
"sin", "cos", "tan", "asin", "acos", "atan", | |
"sinh", "cosh", "tanh", "asinh", "acosh", "atanh", | |
"exp", "exp2", "expm1", "log", "log2", "log1p", "log10", | |
"sqrt", "cbrt", | |
"ceil", "floor", "round", "trunc", "rint", | |
"copysign", | |
] | |
let float_binop_fun_names = [ | |
"atan2", "pow", "hypot", "copysign" | |
] | |
let int_float_unop_fun_names = [ | |
"abs", "min", "max" | |
] | |
-- create function name translations | |
funNameTranslation = EqMap new | |
nullop_fun_names forEach \name { | |
funNameTranslation put((name, ElemType.FLOAT32), name $ "f") | |
funNameTranslation put((name, ElemType.FLOAT64), name) | |
} | |
float_unop_fun_names forEach \name { | |
funNameTranslation put((name, ElemType.FLOAT32), name $ "f") | |
funNameTranslation put((name, ElemType.FLOAT64), name) | |
} | |
float_binop_fun_names forEach \name { | |
funNameTranslation put((name, ElemType.FLOAT32), name $ "f") | |
funNameTranslation put((name, ElemType.FLOAT64), name) | |
} | |
int_float_unop_fun_names forEach \name { | |
funNameTranslation put((name, ElemType.INT32), name) | |
funNameTranslation put((name, ElemType.INT64), "l" $ name) | |
funNameTranslation put((name, ElemType.FLOAT32), "f" $ name $ "f") | |
funNameTranslation put((name, ElemType.FLOAT64), "f" $ name) | |
} | |
funNameTranslation put(("%", ElemType.INT32), "%") | |
funNameTranslation put(("%", ElemType.INT64), "%") | |
funNameTranslation put(("%", ElemType.FLOAT32), "fmodf") | |
funNameTranslation put(("%", ElemType.FLOAT64), "fmod") | |
fn nonNil(a, b) { a !== nil ? a : b } | |
fn genShape(shape) { | |
shape reduce(\s, i[s $ "[%^]" fmt(i)], "") | |
} | |
fn genNumType(elemType) { | |
elemType is64bits ? "f64" : "f32" | |
} | |
fn genIndex(shape, indexExprs) { | |
var s = "" | |
\dim, index{ | |
s = s $ "[%^]" fmt(dim > 1 ? index : "0") | |
}(shape @, indexExprs @) | |
s | |
} | |
defClass(#CCodeGen, Scalar, {}) | |
fn init(o CCodeGen, synthName String, synth SynthDef, unrollLoops Bool = true) { | |
o.synthName = synthName | |
o.synth = synth | |
o.dataName = synthName $ "_data" | |
o.curRoot = nil | |
o.indent = 1 | |
o.unrollLoops = unrollLoops | |
o | |
} | |
fn tabindent(o CCodeGen) { | |
return "\t" * o.indent | |
} | |
fn genTree(o CCodeGen, tree) { | |
var s = "" | |
let root = tree.root | |
o.curRoot = root | |
-- debug | |
s = s $ o tabindent $ "// " $ root lispStr(4) $ "\n" | |
let isInput = root.graphCut isa(GraphCut_Input) | |
if (isInput) { | |
s = s $ o genTreeInput(tree) | |
} else { | |
let elemType = root.elemType | |
let shape = root.shape | |
let needsTempVar = root.graphCut isTempVar | |
if (needsTempVar) { | |
s = s $ o tabindent | |
s = s $ "%^ v%^%^;\n" fmt(elemType genNumType, tree.index, shape genShape) | |
} | |
if (root isa(SignalVecUGen)) { | |
s = s $ o genSignalVecUGenTree(tree) | |
} else { | |
s = s $ o genTreeRoot(root, root, tree.index, nil) | |
} | |
} | |
s | |
} | |
fn genTreeList(o CCodeGen, trees List) { | |
-- Generate code for a list of expression trees. | |
trees reduce(\s, tree[s $ "\n" $ o genTree(tree)], "") | |
} | |
fn genTreeRoot(o CCodeGen, root, branch, varIndex, rootIndexExprs) { | |
-- Generate the code for the root of an expression tree. | |
var s = "" | |
let shape = branch.shape | |
if (root isa(PullUGen)) { | |
s = s $ o tabindent | |
s = s $ "if (%^) {\n" fmt(o genExpr(root.ins[0], [])) | |
o.indent = o.indent + 1 | |
s = s $ o genSubgraphCode(root.subGraph) | |
o.indent = o.indent - 1 | |
s = s $ o tabindent | |
s = s $ "\n}\n" | |
return s | |
} | |
let loopBody = \indexExprs { | |
var s = "" | |
s = s $ o tabindent | |
if (!(root isa(UGen) && root.graphCut isa(GraphCut_Sink))) { | |
if (!(root.graphCut isTempVar)) { | |
s = s $ "u->" | |
} | |
let xExprs = rootIndexExprs nonNil(indexExprs) | |
s = s $ "v%^%^ = " fmt(varIndex, root.shape genIndex(xExprs)) | |
} | |
s = s $ o genExpr(branch, indexExprs) | |
s = s $ ";\n" | |
-- insert debug signals code | |
s | |
} | |
s = s $ o genLoops(shape, loopBody, o.unrollLoops) | |
s | |
} | |
fn genTreeInput(o CCodeGen, tree) { | |
var s = "" | |
let root = tree.root | |
let jackIndex = root.inputID | |
let normalled = root.ins[0] | |
-- one or both of these will be nil | |
let scalar = normalled.scalar | |
let array = normalled.array | |
o.indent = 1 | |
s = s $ o tabindent | |
if (scalar !== nil && scalar !== 0.) { | |
-- if there is a scalar then we need a temp var | |
s = s $ normalled.elemType genNumType | |
s = s $ " tmp%^ = %^;\n" fmt(tree.index, o genExpr(scalar, [])) | |
s = s $ o tabindent | |
} | |
s = s $ "pull_input(e, &node->ins.p[%^], " fmt(jackIndex) | |
if (normalled isa(UGen)) { | |
if (normalled.rank == 0) { | |
s = s $ "&" | |
} | |
let normalledIndex = o.synth.rootsToTrees get(normalled).index | |
if (!(normalled.graphCut isTempVar)) { | |
s = s $ "u->" | |
} | |
if (normalled.graphCut isa(GraphCut_Input)) { | |
s = s $ "in" | |
} else { | |
s = s $ "v" | |
} | |
s = s $ normalledIndex str | |
} else if (array !== nil) { | |
s = s $ "u->a%^" o.synth.arrays get(array) | |
} else if (scalar !== nil) { | |
if (scalar == 0.) { | |
s = s $ "NULL" | |
} else { | |
if (normalled.rank == 0) { | |
s = s $ "&" | |
} | |
s = s $ "tmp" $ tree.index str | |
} | |
} else { | |
"unsupported type" println | |
9 crashme | |
} | |
s = s $ ");\n" | |
s | |
} | |
fn genSubgraphCode(o CCodeGen, subgraph) { | |
-- Generate the code to evaluate a subgraph. | |
var s = "" | |
s = s $ o genTreeList(subgraph.trees) | |
s = s $ o genUpdateDelayCounters(subgraph) | |
s | |
} | |
fn genUpdateDelayCounters(o CCodeGen, graph) { | |
-- Generate code to update delay line counters. | |
var s = "" | |
o.synth.tsvars forEach \tsvar{ | |
if (tsvar.graph === graph && tsvar.maxFixedDelay !== 1) { | |
s = s $ o tabindent | |
s = s $ "++u->d%^_wrpos;\n" fmt(tsvar.serialNo) | |
} | |
} | |
s | |
} | |
fn genInstVars(o CCodeGen) { | |
-- Generate the instance variable declarations for the synth. | |
var s = "" | |
-- Declare buffers for the input and output jacks. | |
o.synth.inputs forEach \u{ | |
s = s $ "\t%^ in%^%^;\n" fmt( | |
u.elemType genNumType, u.inputID, u.shape genShape | |
) | |
} | |
o.synth.outputs forEach \u{ | |
s = s $ "\t%^ out%^%^;\n" fmt( | |
u.elemType genNumType, u.outputID, u.shape genShape | |
) | |
} | |
-- Declare instance variables for GraphCuts. | |
o.synth.rootsToTrees values forEach \tree { | |
if (tree.root.graphCut isInstVar) { | |
s = s $ "\t%^ v%^%^;\n" fmt( | |
tree.root.elemType genNumType, | |
tree.index, | |
tree.root.shape genShape) | |
} | |
} | |
-- Declare buffers for delay lines. | |
o.synth.tsvars forEach \tsvar { | |
--"tsvar %^ %^ %^" fmt(tsvar.serialNo, tsvar.maxFixedDelay, tsvar.maxDelay) println | |
--"%^ %^ %^" fmt(tsvar.initters len, tsvar.fixreaders len, tsvar.varreaders len) println | |
s = s $ "\t%^ " fmt(tsvar.elemType genNumType) | |
if (tsvar.maxFixedDelay !== nil) { | |
s = s $ "d%^%^" fmt(tsvar.serialNo, tsvar.shape genShape) | |
if (tsvar.maxFixedDelay > 1) { | |
s = s $ "[%^]" fmt(tsvar.maxFixedDelay) | |
} | |
} else if (tsvar.maxDelay !== nil) { | |
s = s $ "*d%^%^" fmt(tsvar.serialNo, tsvar.shape genShape) | |
} else { | |
"delay length of zero" println | |
s = s $ "/* ERROR: delay length of zero! */" | |
} | |
s = s $ ";\n" | |
} | |
-- Declare position counters and masks for delay lines. | |
o.synth.tsvars forEach \tsvar { | |
if (tsvar.maxFixedDelay !== 1) { | |
s = s $ "\ti64 d%^_wrpos;\n" fmt(tsvar.serialNo) | |
} | |
if (tsvar.maxDelay !== nil) { | |
s = s $ "\ti64 d%^_mask%^;\n" fmt(tsvar.serialNo, tsvar.shape genShape) | |
} | |
} | |
s | |
} | |
fn flatTensorStr(o, level, elemType) { | |
if (level == 0) { | |
o constSignalStr(elemType) | |
} else { | |
var s = "" | |
o forEach \v, i { | |
if (i > 0) { s = s $ ", " } | |
s = s $ v flatTensorStr(level-1, elemType) | |
} | |
s | |
} | |
} | |
fn constSignalStr(value Number, elemType) { | |
if (elemType isInt) { return value asInt str } | |
if (elemType isFloat) { | |
if (elemType == ElemType.FLOAT32) { | |
return value asFloat str $ "f" | |
} else { return value asFloat str } | |
} | |
if (elemType isComplex) { | |
let (ctor, ftype) = elemType == ElemType.COMPLEX32 ? | |
("x32", ElemType.FLOAT32) : ("x64", ElemType.FLOAT64) | |
let (r, i) = value isa(Real) ? | |
(value constSignalStr(ftype), 0 constSignalStr(ftype)) : | |
(value real constSignalStr(ftype), value imag constSignalStr(ftype)) | |
"%^(%^, %^)" fmt(ctor, r, i) | |
} | |
} | |
fn constSignalStr(value List, elemType) { | |
(shape, _) = value isTensor | |
value flatTensorStr(shape len, elemType) | |
} | |
fn genConstArrayData(o CCodeGen, constSignal) { | |
"{%^}" fmt(constSignal.value constSignalStr(constSignal.elemType)) | |
} | |
fn genConstArrayVars(o CCodeGen) { | |
var s = "" | |
let arrays = o.synth.arrays | |
arrays forEach \a { | |
s = s $ "\t%^ a%^%^;\n" fmt ( | |
a.elemType genNumType, | |
arrays get(a), | |
a.shape genShape) | |
} | |
s | |
} | |
fn genTimeSeriesAlloc(o CCodeGen) { | |
-- Allocate the buffers for delay lines. | |
var s = "" | |
o.synth.tsallocs forEach \tsvar { | |
let tree = o.synth.rootsToTrees get(tsvar.maxDelay) | |
let shape = tsvar.shape | |
let treeIndexStr = tree.index str | |
let varName = "u->d%^" fmt(tsvar.serialNo) | |
let allocSizeVarName = (tree.root.graphCut isInstVar ? "u->" : "") $ "v" $ treeIndexStr | |
let allocSizeShape = tree.root.shape | |
let typeStr = tsvar.elemType genNumType | |
let loopBody = \indexExprs { | |
let indexStr = shape genIndex(indexExprs) | |
var s = "" | |
s = s $ o tabindent | |
s = s $ "size_t size%^ = nextPowerOfTwo((size_t)%^%^);\n" fmt( | |
treeIndexStr, allocSizeVarName, | |
allocSizeShape genIndex(indexExprs)) | |
s = s $ o tabindent | |
s = s $ "%^_mask%^ = size%^ - 1;\n" fmt(varName, indexStr, treeIndexStr) | |
s = s $ o tabindent | |
s = s $ "%^%^ = (%^*)calloc(1, sizeof(%^) * size%^);\n" fmt( | |
varName, indexStr, typeStr, typeStr, treeIndexStr) | |
s | |
} | |
o.indent = 1 | |
s = s $ o genLoops(shape, loopBody) | |
} | |
s | |
} | |
fn genTimeSeriesDealloc(o CCodeGen) { | |
-- Deallocate the buffers for delay lines. | |
var s = "" | |
o.synth.tsallocs forEach \tsvar { | |
let shape = tsvar.shape | |
let varName = "u->d%^" fmt(tsvar.serialNo) | |
let loopBody = \indexExprs { | |
let indexStr = shape genIndex(indexExprs) | |
var s = "" | |
s = s $ o tabindent | |
s = s $ "free(%^%^);\n" fmt(varName, indexStr) | |
s | |
} | |
o.indent = 1 | |
s = s $ o genLoops(shape, loopBody) | |
} | |
s | |
} | |
fn genConstArrayInit(o CCodeGen) { | |
-- Generate code to initialize constant arrays. | |
var s = "" | |
o.synth.arrays forEach \a { | |
let varName = "a" $ o.synth.arrays get(a) str | |
s = s $ "\t%^ %^%^ = %^;\n" fmt( | |
a.elemType genNumType, varName, a.shape genShape, | |
o genConstArrayData(a)) | |
s = s $ "\tmemcpy(u->%1, %1, sizeof(%1));\n" fmt(varName) | |
} | |
s | |
} | |
let elemTypeEnumKeys = IdMap new( | |
[ ElemType.INT32, ElemType.INT64, | |
ElemType.FLOAT32, ElemType.FLOAT64, | |
ElemType.COMPLEX32, ElemType.COMPLEX64 ], | |
[ "kInt32", "kInt64", | |
"kFloat32", "kFloat64", | |
"kComplex32", "kComplex64" ]) | |
fn genPortDefs(o CCodeGen, io, ports) { | |
-- Generate code to define ports. | |
var s = "" | |
ports forEach \u, i { | |
let rank = u.shape len | |
let enumKey = elemTypeEnumKeys get(u.elemType) | |
let shapeStr = "{%^}" fmt(u.shape strjoin(", ")); | |
s = s $ "\tPortInfo %1%2 = {\"%1%2\", {%3, %4, %5, %6}, offsetof(%7, %1%2)};\n" fmt( | |
io, i, enumKey, u.rate.value, rank, shapeStr, o.dataName) | |
s = s $ "\tinfo.%1s.push_back(%1%2);\n" fmt(io, i) | |
} | |
s | |
} | |
fn genNodeDefFun(o CCodeGen) { | |
-- Generate code for the alloc function. | |
var s = "" | |
s = s $ "void define_%^(Engine* e)\n{\n" fmt(o.synthName) | |
s = s $ "\tNodeDefInfo info;\n" | |
s = s $ "\tinfo.name = \"%^\";\n" fmt(o.synthName) | |
s = s $ "\tinfo.dataSize = sizeof(%^);\n" fmt(o.dataName) | |
if (o.synth.inputs len) { | |
s = s $ o genPortDefs("in", o.synth.inputs) | |
} | |
if (o.synth.outputs len) { | |
s = s $ o genPortDefs("out", o.synth.outputs) | |
} | |
s = s $ "\tNodeFuns & funs = info.funs;\n" | |
["init", "uninit", "reset", "pull", "push"] forEach \funname { | |
s = s $ "\tfuns.%1 = %2_%1;\n" fmt(funname, o.synthName) | |
} | |
s = s $ "\taddNodeDef(e, info);\n" | |
s = s $ "}\n\n" | |
s | |
} | |
fn genInitFun(o CCodeGen) { | |
-- Generate code for the init function. | |
var s = "" | |
o.indent = 1 | |
-- Allocate render resources. Run init time code on non-real-time thread. | |
s = s $ "int %^_init(PlugInNode* node) {\n" fmt(o.synthName) | |
-- debug signal code goes here | |
if (o.synth.arrays || o.synth.initTrees || o.synth.tsallocs) { | |
s = s $ "\t%1 *u = (%1 *)node->data;\n" fmt(o.dataName) | |
s = s $ o genConstArrayInit() | |
s = s $ o genTreeList(o.synth.initTrees) | |
s = s $ o genTimeSeriesAlloc() | |
} | |
s = s $ "\treturn errNone;\n}\n" | |
s | |
} | |
fn genUninitFun(o CCodeGen) { | |
-- Generate code for the uninit function. | |
-- uninit - deallocates render resources. done off of the render thread. | |
var s = "" | |
s = s $ "int %^_uninit(PlugInNode* node) {\n" fmt(o.synthName) | |
if (o.synth.tsallocs) { | |
s = s $ "\t%1 *u = (%1 *)node->data;\n" fmt(o.dataName) | |
s = s $ o genTimeSeriesDealloc | |
} | |
s = s $ "\treturn errNone;\n}\n" | |
s | |
} | |
fn genResetFun(o CCodeGen) { | |
-- Generate code for the reset function. | |
-- Resets variable values back to initial settings without reallocation. | |
-- Reset may be called on the render thread. | |
var s = "" | |
o.indent = 1 | |
s = s $ "int %^_reset(PlugInNode* node) {\n" fmt(o.synthName) | |
-- set all delay line write positions to zero. | |
-- if the reset function has any content. | |
if (o.synth.resetTrees || o.synth.tsvars) { | |
s = s $ "\t%1 *u = (%1 *)node->data;\n" fmt(o.dataName) | |
o.synth.tsvars forEach \ tsvar { | |
if (tsvar.maxFixedDelay !== 1) { | |
s = s $ "\tu->d%^_wrpos = 0;\n" fmt(tsvar.serialNo) | |
} | |
} | |
s = s $ o genTreeList(o.synth.resetTrees) | |
} | |
s = s $ "\treturn errNone;\n}\n" | |
s | |
} | |
fn genPushFun(o CCodeGen) { | |
o.indent = 1 | |
var s = "" | |
s = s $ "int %^_push(PlugInNode* node, int inputIndex, " fmt(o.synthName) | |
s = s $ "int numChannels, void* data) {\n" | |
s = s $ "\treturn errNone;\n}\n" | |
s | |
} | |
fn genPullFun(o CCodeGen) { | |
o.indent = 1 | |
var s = "" | |
s = s $ "void %^_pull(PlugInNode* node, int outputIndex) {\n" fmt(o.synthName) | |
s = s $ "\t%1 *u = (%1 *)node->data;\n" fmt(o.dataName) | |
-- TO DO insert debug signals code | |
s = s $ o genSubgraphCode(o.synth.rootGraph) | |
s = s $ "\n}\n" | |
s | |
} | |
fn genSetParamFun(o CCodeGen) { | |
o.indent = 1 | |
var s = "" | |
s = s $ "int %^_setControl(PlugInNode* node, u64 controlID, f64 value) {\n" fmt(o.synthName) | |
-- TO DO | |
s = s $ "\treturn errNone;\n}\n" | |
s | |
} | |
fn genUpdateParamsFun(o CCodeGen) { | |
o.indent = 1 | |
var s = "" | |
s = s $ "int %^_updateControls(PlugInNode* node) {\n" fmt(o.synthName) | |
-- TO DO | |
s = s $ "\treturn errNone;\n}\n" | |
s | |
} | |
fn genClass(o CCodeGen) { | |
-- Generate all the code for a synth class. | |
var s = "" | |
-- generate includes | |
s = s $ "\n" | |
localCppIncludes = ["sapf_plugin_interface"] | |
angleCIncludes = ["math", "stdio", "string", "stdlib"] | |
angleCppIncludes = ["vector"] | |
s = localCppIncludes reduce(\a, f{a $ "#include \"%^.hpp\"\n" fmt(f)}, s) | |
s = angleCIncludes reduce(\a, f{a $ "#include <%^.h>\n" fmt(f)}, s) | |
s = angleCppIncludes reduce(\a, f{a $ "#include <%^>\n" fmt(f)}, s) | |
s = s $ "\n" | |
s = s $ "\nusing namespace sapf;\n\n" | |
-- Generate the data structure for the synth's state. | |
s = s $ "typedef struct %^ {\n" fmt(o.dataName) | |
s = s $ o genInstVars | |
s = s $ o genConstArrayVars | |
s = s $ "} %^;\n\n" fmt(o.dataName) | |
-- generate the synth API functions | |
s = s $ o genInitFun | |
s = s $ o genUninitFun | |
s = s $ o genResetFun | |
s = s $ o genSetParamFun | |
s = s $ o genUpdateParamsFun | |
s = s $ o genPullFun | |
s = s $ o genPushFun | |
s = s $ o genNodeDefFun | |
s = s $ "extern \"C\" void load(Engine* e) {\n" | |
s = s $ "\tdefine_%^(e);\n" fmt(o.synthName) | |
s = s $ "}\n\n\n" | |
s | |
} | |
fn genLoops(o CCodeGen, shape, loopBody, unrolled=false) { | |
-- Generate code for (possibly nested) for-loops. | |
indexExprs = [] | |
if (unrolled) { | |
o genLoopsUnrolled(0, shape, indexExprs, loopBody) | |
} else { | |
var s = "" | |
s = s $ o genLoopsOpen(shape, indexExprs) | |
s = s $ loopBody(indexExprs) | |
s = s $ o genLoopsClose(shape) | |
s | |
} | |
} | |
fn genLoopsUnrolled(o CCodeGen, level, shape, indexExprs, loopBody) { | |
-- Generate (possibly nested) unrolled loops. | |
var s = "" | |
rank = shape len | |
if (rank == 0) { | |
s = s $ loopBody(indexExprs) | |
} else { | |
to(0, shape[level]-1) forEach \i { | |
indexExprs add(str(i)) | |
if (level < rank - 1) { | |
s = s $ o genLoopsUnrolled(level + 1, shape, indexExprs, loopBody) | |
} else { | |
s = s $ loopBody(indexExprs) | |
} | |
indexExprs pop | |
} | |
} | |
s | |
} | |
fn genLoopsOpen(o CCodeGen, shape, indexExprs) { | |
-- Generate opening heads for (possibly nested) loops. | |
var s = "" | |
rank = len(shape) | |
to(0, rank-1) forEach \i { | |
index = "i%^" fmt(rank - i - 1) | |
indexExprs add(index) | |
dim = shape[i] | |
if (dim !== 1) { | |
s = s $ o tabindent | |
s = s $ "for (int %1 = 0; %1 < %2; ++ %1) {\n" fmt(index, dim) | |
o.indent = o.indent + 1 | |
} | |
} | |
s | |
} | |
fn genLoopsClose(o CCodeGen, shape) { | |
-- Generate closing brackets for (possibly nested) loops. | |
var s = "" | |
shape forEach \dim { | |
if (dim !== 1) { | |
o.indent = o.indent - 1 | |
s = s $ o tabindent | |
s = s $ "}\n" | |
} | |
} | |
s | |
} | |
fn genExpr(o CCodeGen, signal ConstSignal, indexExprs) { | |
o genConstantExpr(signal, indexExprs) | |
} | |
fn genExpr(o CCodeGen, ugen UGen, indexExprs) { | |
if (ugen isTreeRoot && ugen !== o.curRoot) { | |
-- when other roots are encountered, generate code to reference their variable. | |
return o genVarRef(ugen, indexExprs) | |
} | |
o genUGenExpr(ugen, indexExprs) | |
} | |
fn genUGenExpr(o CCodeGen, ugen MathOpUGen, indexExprs) { | |
-- Generate code for a math operator. | |
let c_operator_chars = "~!%^&*-+=|<>/" | |
if (c_operator_chars has(ugen.cname byteAt(0))) { | |
let opname = ugen.cname | |
if (ugen isa(UnopUGen)) { | |
let a = o genExpr(ugen.ins[0], indexExprs) | |
return "%^%^" fmt(opname, a) | |
} | |
if (ugen isa(BinopUGen)) { | |
let [a, b] = o genExpr(ugen.ins @, indexExprs) | |
return "(%^ %^ %^)" fmt(a, opname, b) | |
} | |
} else { | |
let key = (ugen.cname, ugen.elemType) | |
let opname = funNameTranslation get(key) | |
let c = opname byteAt(0) | |
if (c isalpha || c == "_" byteAt(0)) { | |
let args = o genExpr(ugen.ins @, indexExprs) strjoin(", ") | |
return "%^(%^)" fmt(opname, args) | |
} | |
} | |
"Don't know how to generate code for %^" fmt(ugen.cname) println | |
9 crashme | |
} | |
fn genUGenExpr(o CCodeGen, ugen SampleRateUGen, indexExprs) { | |
"(%^)node->fs" fmt(ugen.elemType genNumType) | |
} | |
fn genUGenExpr(o CCodeGen, ugen SelectUGen, indexExprs) { | |
let [a, b, c] = o genExpr(ugen.ins @, indexExprs) | |
"(%^ ? %^ : %^)" fmt(a, b, c) | |
} | |
fn genUGenExpr(o CCodeGen, ugen DebugUGen, indexExprs) { | |
let expr = o genExpr(ugen.ins[0], indexExprs) | |
"debugSignal(%^, %^, %^)" fmt(ugen.label, expr, indexExprs str) | |
} | |
fn genUGenExpr(o CCodeGen, ugen JackOut, indexExprs) { | |
let index = ugen.shape genIndex(indexExprs) | |
let expr = o genExpr(ugen.ins[0], indexExprs) | |
"(u->out%^%^ = %^)" fmt(ugen.outputID, index, expr) | |
} | |
fn genUGenExpr(o CCodeGen, ugen JackIn, indexExprs) { | |
"jackin should have been taken care of in gen_tree." throw | |
} | |
fn genUGenExpr(o CCodeGen, ugen URandUGen, indexExprs) { | |
(ugen.elemType is32bits ? "urandf" : "urand") $ "(node->randState)" | |
} | |
fn genUGenExpr(o CCodeGen, ugen BRandUGen, indexExprs) { | |
(ugen.elemType is32bits ? "birandf" : "birand") $ "(node->randState)" | |
} | |
fn genUGenExpr(o CCodeGen, ugen TSUGen, indexExprs) { | |
let tsvar = ugen.ts | |
varName = "u->d%^" fmt(tsvar.serialNo) | |
indexExpr = ugen.shape genIndex(indexExprs) | |
tsIndexExpr = tsvar.shape genIndex(indexExprs) | |
if (ugen isa(TSInit)) { | |
var s = varName | |
if (tsvar.maxFixedDelay !== 1) { | |
s = s $ "[(%^_wrpos - %^) & %^]" fmt(varName, ugen.delay, tsvar.mask) | |
} | |
s = s $ "%^ = %^" fmt(indexExpr, o genExpr(ugen.ins[0], indexExprs)) | |
return s | |
} | |
var s = varName $ indexExpr | |
if (ugen isa(TSFixRead)) { | |
if (tsvar.maxFixedDelay !== 1) { | |
s = s $ "[(%^_wrpos - %^) & %^]" fmt(varName, ugen.delay, tsvar.mask) | |
} | |
return s | |
} | |
if (ugen isa(TSVarRead)) { | |
let delayExpr = o genExpr(ugen.ins[0], indexExprs) | |
let maskExpr = "%^_mask%^" fmt(varName, tsIndexExpr) | |
s = s $ "[(%^_wrpos - (i64)(%^)) & %^]" fmt(varName, delayExpr, maskExpr) | |
return s | |
} | |
if (ugen isa(TSWrite)) { | |
if (tsvar.maxDelay !== nil) { | |
s = s $ "[%1_wrpos & %1_mask%2]" fmt(varName, tsIndexExpr) | |
} else if (tsvar.maxFixedDelay !== 1) { | |
s = s $ "[%^_wrpos & %^]" fmt(varName, tsvar.mask) | |
} | |
s = s $ " = %^" fmt(o genExpr(ugen.ins[0], indexExprs)) | |
return s | |
} | |
} | |
fn genConstantExpr(o CCodeGen, signal, indexExprs) { | |
-- Generate a scalar or array in an expression. | |
if (signal isScalarConstant) { | |
return constSignalStr(signal.value, signal.elemType) | |
} | |
"u->a%^%^" fmt(o.synth.arrays get(signal), signal.shape genIndex(indexExprs)) | |
} | |
fn genVarRef(o CCodeGen, ugen, indexExprs) { | |
-- Generate a variable reference. | |
var s = "" | |
if (!(ugen.graphCut isTempVar)) { | |
s = s $ "u->" | |
} | |
if (ugen.graphCut == GraphCut.INPUT) { | |
s = s $ "in%^" fmt(ugen.inputID) | |
} else { | |
let tree = o.synth.rootsToTrees get(ugen) | |
s = s $ "v%^" fmt(tree.index) | |
} | |
s = s $ ugen.shape genIndex(indexExprs) | |
s | |
} | |
--------------------------------------------------------------------------- | |
fn isScalarConstant(o Signal) = false | |
fn isScalarConstant(o ConstSignal) = o.value isa(Number) | |
fn isArrayConstant(o Signal) = false | |
fn isArrayConstant(o ConstSignal) = o.value isa(List) | |
--------------------------------------------------------------------------- | |
-- dictionary clear method | |
let lowRateVars = {#i, #j, #k} | |
let highRateVars = {#x, #y, #z} | |
fn minval(o List, z) = o reduce(min, z) | |
fn maxval(o List, z) = o reduce(max, z) | |
fn whichAreIn(o List, set) = o filter(\x[set has(x)]) | |
fn checkVarRates(subs) { | |
-- In order to be a match, the matching low rate variable names i,j,k must all | |
-- be lower rate than any of the matching the high rate variable names x,y,z. | |
var maxLowRate = Rate.TBD | |
var minHighRate = Rate.Audio | |
subs forEach \k, v { | |
if (lowRateVars has(k)) { | |
maxLowRate = max(maxLowRate, v.rate) | |
} else if (highRateVars has(k)) { | |
minHighRate = min(minHighRate, v.rate) | |
} | |
} | |
"checkVarRates %^ %^" fmt(maxLowRate, minHighRate) | |
maxLowRate < minHighRate | |
} | |
defClass(#RewriteRule, Scalar, {}) | |
-- An expression tree for pattern matching (lhs) or production (rhs). | |
defClass(#RewriteExpr, Scalar, {}) | |
fn init(o RewriteRule, lhs RewriteExpr, rhs RewriteExpr, trace Bool = false) { | |
o.lhs = lhs | |
o.rhs = rhs | |
o.trace = trace | |
o | |
} | |
fn rewrite(o RewriteRule, x) { | |
let subs = IdMap new -- A dictionary of matched subexpressions. | |
-- Does the rule match? | |
if (o.lhs match(x, subs) && subs checkVarRates) { | |
if (DEBUG_REWRITE) { | |
"RULE MATCH %^" fmt(o str) println | |
"IN: %^" fmt(x lispStr(3)) println | |
subs len println | |
subs forEach \k, v, i { | |
"sub %^ %^ -> %^" fmt(i, k, v lispStr(3)) println | |
} | |
">rewrite expr" println | |
} | |
-- If so, then rewrite the expression using the matched subexpressions. | |
let out = o.rhs rewrite(subs) | |
if (DEBUG_REWRITE) { | |
"OUT: %^" fmt(out lispStr(3)) println | |
} | |
out | |
} else { | |
nil | |
} | |
} | |
fn rstr(o RewriteRule) { | |
"%^ => %^" fmt(o.lhs, o.rhs) | |
} | |
fn rule(lhs RewriteExpr, rhs RewriteExpr, trace Bool = false) { | |
-- Convenience function to create a rewrite rule. | |
RewriteRule(lhs, rhs, trace) | |
} | |
fn matchingSignals(a Signal, b Signal) { | |
-- True if the signals are identical or are equal constant values. | |
if (a === b) { | |
return true | |
} | |
a isa(ConstSignal) && b isa(ConstSignal) && a.value == b.value | |
} | |
fn matchArgs(o RewriteExpr, rv, sv, subs, isCommutative) { | |
if (rv len != sv len) { -- Arity doesn't match. | |
return false | |
} | |
var subs2 = subs copy | |
-- If any arguments don't match, then fail. | |
if (all(rv, sv) \r, s { r match(s, subs2) }) { | |
-- replace the content of subs with subs2 | |
subs clear | |
subs addAll(subs2) | |
return true | |
} | |
-- For commutative operators, try matching both orderings of subexpressions. | |
if (isCommutative && rv[0] !== rv[1]) { | |
subs2 = subs copy | |
if (all(rv reverse, sv) \r, s { r match(s, subs2) }) { | |
-- replace the content of subs with subs2 | |
subs clear | |
subs addAll(subs2) | |
return true | |
} | |
} | |
return false | |
} | |
fn rewriteArgs(o RewriteExpr, rv, subs) = rv rewrite(subs) | |
-- overload operators so that these expressions can be built algebraically. | |
fn +(a RewriteExpr, b RewriteExpr) = UGenRewriteExpr(OpAdd, [a, b]) | |
fn -(a RewriteExpr, b RewriteExpr) = UGenRewriteExpr(OpSub, [a, b]) | |
fn *(a RewriteExpr, b RewriteExpr) = UGenRewriteExpr(OpMul, [a, b]) | |
fn /(a RewriteExpr, b RewriteExpr) = UGenRewriteExpr(OpDiv, [a, b]) | |
fn %(a RewriteExpr, b RewriteExpr) = UGenRewriteExpr(OpMod, [a, b]) | |
fn <(a RewriteExpr, b RewriteExpr) = UGenRewriteExpr(OpLT, [a, b]) | |
fn <=(a RewriteExpr, b RewriteExpr) = UGenRewriteExpr(OpLE, [a, b]) | |
fn >(a RewriteExpr, b RewriteExpr) = UGenRewriteExpr(OpGT, [a, b]) | |
fn >=(a RewriteExpr, b RewriteExpr) = UGenRewriteExpr(OpGE, [a, b]) | |
fn ==(a RewriteExpr, b RewriteExpr) = UGenRewriteExpr(OpEQ, [a, b]) | |
fn !=(a RewriteExpr, b RewriteExpr) = UGenRewriteExpr(OpNE, [a, b]) | |
fn -(a RewriteExpr) = UGenRewriteExpr(OpNeg, [a]) | |
fn rstr(a RewriteExpr) { | |
"Not Implemented" throw | |
} | |
defClass(#VarRewriteExpr, RewriteExpr, {}) | |
-- Matches any subexpression and binds a variable to it. If there are multiple | |
-- occurences of the same variable name, they must all match identical expressions | |
-- or equal constants. | |
fn init(o VarRewriteExpr, varName) { | |
-- super init | |
o.varName = varName | |
o | |
} | |
fn match(o VarRewriteExpr, x, subs) { | |
if (subs has(o.varName)) { | |
matchingSignals(subs get(o.varName), x) | |
} else { | |
subs put(o.varName, x) | |
true | |
} | |
} | |
fn rewrite(o VarRewriteExpr, subs) = subs get(o.varName) | |
fn rstr(o VarRewriteExpr) = o.varName | |
defClass(#ScalarRewriteExpr, RewriteExpr, {}) | |
-- Matches a scalar constant. | |
fn init(o ScalarRewriteExpr, value) { | |
-- super init | |
o.value = value | |
o | |
} | |
fn match(o ScalarRewriteExpr, x, _subs) { | |
if (x isa(ConstSignal) && x.value isa(Number)) { | |
x.value == o.value | |
} else { | |
false | |
} | |
} | |
fn rewrite(o ScalarRewriteExpr, subs) = o.value asSignal | |
fn rstr(o ScalarRewriteExpr) = o.value str | |
defClass(#PosNumRewriteExpr, RewriteExpr, {}) | |
-- Matches a positive scalar constant. | |
fn match(o PosNumRewriteExpr, x, subs) { | |
if (x isa(ConstSignal) && x.value isa(Real) && x.value > 0) { | |
subs put(#pos, x) | |
true | |
} else { | |
false | |
} | |
} | |
fn rewrite(o PosNumRewriteExpr, subs) = subs get(#pos) | |
fn rstr(o PosNumRewriteExpr) = "pos" | |
defClass(#NegNumRewriteExpr, RewriteExpr, {}) | |
-- Matches a negative scalar constant. | |
fn match(o NegNumRewriteExpr, x, subs) { | |
if (x isa(ConstSignal) && x.value isa(Real) && x.value < 0) { -- XXX | |
subs put(#neg, x) | |
true | |
} else { | |
false | |
} | |
} | |
fn rewrite(o NegNumRewriteExpr, subs) = subs get(#neg) | |
fn rstr(o NegNumRewriteExpr) = "neg" | |
defClass(#NonInfRewriteExpr, RewriteExpr, {}) | |
-- Matches a non-infinite scalar constant. | |
fn match(o NonInfRewriteExpr, x, subs) { | |
if (x isa(ConstSignal) && x.value isa(Real) && !(x.value isInf)) { | |
subs put(#noninf, x) | |
true | |
} else { | |
false | |
} | |
} | |
fn rewrite(o NonInfRewriteExpr, subs) = subs get(#noninf) | |
fn rstr(o NonInfRewriteExpr) = "noninf" | |
fn isCommutativeBinop(x) = x isa(BinopUGen) && x.isCommutative | |
defClass(#UGenRewriteExpr, RewriteExpr, {}) | |
-- Matches the subclass of MathOpUGen that was given as the constructor argument. | |
fn init(o UGenRewriteExpr, ugenClass, exprArgs) { | |
-- super init | |
o.ugenClass = ugenClass | |
o.exprArgs = exprArgs | |
o | |
} | |
fn match(o UGenRewriteExpr, x, subs) { | |
if (x class != o.ugenClass) { | |
return false | |
} | |
o matchArgs(o.exprArgs, x.ins, subs, isCommutativeBinop(x)) | |
} | |
fn rewrite(o UGenRewriteExpr, subs) { | |
-- ">rewrite UGenRewriteExpr" println | |
let args = o rewriteArgs(o.exprArgs, subs) | |
newMathUGen(o.ugenClass, args) | |
} | |
let underscore = "_" byteAt(0) | |
fn rstr(o UGenRewriteExpr) { | |
let args = o.exprArgs | |
let cname = o.ugenClass.cname | |
let c = cname byteAt(0) | |
if (c isalpha || c == underscore) { | |
return "%^(%^)" fmt(cname, args strjoin(", ")) | |
} else if (len(args) == 2) { | |
return "(%^ %^ %^)" fmt(args[0], cname, args[1]) | |
} else if (len(args) == 1) { | |
return "%^ %^" fmt(cname, args[0]) | |
} else { | |
return "%^(%^)" fmt(cname, args strjoin(", ")) | |
} | |
} | |
defClass(#MonoUpRewriteExpr, RewriteExpr, {}) | |
-- Matches any monotonically increasing UnopUGen. Multiple occurrences of monoup | |
-- must match the identical subexpression. | |
fn init(o MonoUpRewriteExpr, exprArgs) { | |
-- super init | |
o.exprArgs = exprArgs | |
o | |
} | |
fn match(o MonoUpRewriteExpr, x, subs) { | |
if (subs has(#monoup)) { | |
return matchingSignals(subs get(#monoup), x) | |
} | |
if (x isa(UnopUGen) && x.isMonotonicUp && o matchArgs(x.ins, o.exprArgs, subs, false)) { | |
subs put(#monoup, x) | |
return true | |
} else { | |
return false | |
} | |
} | |
fn rewrite(o MonoUpRewriteExpr, subs) { | |
args = o rewriteArgs(o.exprArgs, subs) | |
newMathUGen(type(subs get(#monoup)), args) | |
} | |
fn rstr(o MonoUpRewriteExpr) = "monoup" | |
defClass(#MonoDownRewriteExpr, RewriteExpr, {}) | |
-- Matches any monotonically decreasing UnopUGen. Multiple occurrences of monodn | |
-- must match the identical subexpression. | |
fn init(o MonoDownRewriteExpr, exprArgs) { | |
-- super init | |
o.exprArgs = exprArgs | |
o | |
} | |
fn match(o MonoDownRewriteExpr, x, subs) { | |
if (subs has(#monodn)) { | |
return matchingSignals(subs get(#monodn), x) | |
} | |
if (x isa(UnopUGen) && x.isMonotonicDn && o matchArgs(x.ins, o.exprArgs, subs, false)) { | |
subs put(#monodn, x) | |
return true | |
} else { | |
return false | |
} | |
} | |
fn rewrite(o MonoDownRewriteExpr, subs) { | |
args = o rewriteArgs(o.exprArgs, subs) | |
newMathUGen(type(subs get(#monodn)), args) | |
} | |
fn rstr(o MonoDownRewriteExpr) = "monodn" | |
fn min(a RewriteExpr, b RewriteExpr) = UGenRewriteExpr(OpMin, [a, b]) | |
fn max(a RewriteExpr, b RewriteExpr) = UGenRewriteExpr(OpMax, [a, b]) | |
fn pow(a RewriteExpr, b RewriteExpr) = UGenRewriteExpr(OpPow, [a, b]) | |
fn hypot(a RewriteExpr, b RewriteExpr) = UGenRewriteExpr(OpHypot, [a, b]) | |
fn atan2(a RewriteExpr, b RewriteExpr) = UGenRewriteExpr(OpATan2, [a, b]) | |
-- fn logical_not_(a RewriteExpr) = UGenRewriteExpr(OpNot, [a]) | |
fn abs(a RewriteExpr) = UGenRewriteExpr(OpAbs, [a]) | |
fn ceil(a RewriteExpr) = UGenRewriteExpr(OpCeil, [a]) | |
fn floor(a RewriteExpr) = UGenRewriteExpr(OpFloor, [a]) | |
fn rint(a RewriteExpr) = UGenRewriteExpr(OpRound, [a]) | |
-- fn trunc(a RewriteExpr) = UGenRewriteExpr(OpTrunc, [a]) | |
fn sin(a RewriteExpr) = UGenRewriteExpr(OpSin, [a]) | |
fn cos(a RewriteExpr) = UGenRewriteExpr(OpCos, [a]) | |
fn tan(a RewriteExpr) = UGenRewriteExpr(OpTan, [a]) | |
fn asin(a RewriteExpr) = UGenRewriteExpr(OpASin, [a]) | |
fn acos(a RewriteExpr) = UGenRewriteExpr(OpACos, [a]) | |
fn atan(a RewriteExpr) = UGenRewriteExpr(OpATan, [a]) | |
fn sinh(a RewriteExpr) = UGenRewriteExpr(OpSinh, [a]) | |
fn cosh(a RewriteExpr) = UGenRewriteExpr(OpCosh, [a]) | |
fn tanh(a RewriteExpr) = UGenRewriteExpr(OpTanh, [a]) | |
fn asinh(a RewriteExpr) = UGenRewriteExpr(OpASinh, [a]) | |
fn acosh(a RewriteExpr) = UGenRewriteExpr(OpACosh, [a]) | |
fn atanh(a RewriteExpr) = UGenRewriteExpr(OpATanh, [a]) | |
fn log(a RewriteExpr) = UGenRewriteExpr(OpLog, [a]) | |
fn log2(a RewriteExpr) = UGenRewriteExpr(OpLog2, [a]) | |
fn log10(a RewriteExpr) = UGenRewriteExpr(OpLog10, [a]) | |
fn log1p(a RewriteExpr) = UGenRewriteExpr(OpLog1p, [a]) | |
fn exp(a RewriteExpr) = UGenRewriteExpr(OpExp, [a]) | |
fn exp2(a RewriteExpr) = UGenRewriteExpr(OpExp2, [a]) | |
-- fn exp10(a RewriteExpr) = UGenRewriteExpr(OpExp10, [a]) | |
fn expm1(a RewriteExpr) = UGenRewriteExpr(OpExpm1, [a]) | |
fn sqrt(a RewriteExpr) = UGenRewriteExpr(OpSqrt, [a]) | |
fn cbrt(a RewriteExpr) = UGenRewriteExpr(OpCbrt, [a]) | |
fn f32(a RewriteExpr) = UGenRewriteExpr(OpF32, [a]) | |
fn f64(a RewriteExpr) = UGenRewriteExpr(OpF64, [a]) | |
fn monoup(a RewriteExpr) = MonoUpRewriteExpr([a]) | |
fn monodn(a RewriteExpr) = MonoDownRewriteExpr([a]) | |
fn makeRewriteRules() { | |
let x = VarRewriteExpr(#x) | |
let y = VarRewriteExpr(#y) | |
let z = VarRewriteExpr(#z) | |
let i = VarRewriteExpr(#i) | |
let j = VarRewriteExpr(#j) | |
let k = VarRewriteExpr(#k) | |
let pos = PosNumRewriteExpr() | |
let neg = NegNumRewriteExpr() | |
let zero = ScalarRewriteExpr(0) | |
let half = ScalarRewriteExpr(.5) | |
let one = ScalarRewriteExpr(1) | |
let two = ScalarRewriteExpr(2) | |
let three = ScalarRewriteExpr(3) | |
let negone = ScalarRewriteExpr(-1) | |
let negtwo = ScalarRewriteExpr(-2) | |
let negthree = ScalarRewriteExpr(-3) | |
let posinf = ScalarRewriteExpr(inf) | |
let neginf = ScalarRewriteExpr(-inf) | |
let noninf = NonInfRewriteExpr() | |
-- Some of these rules that you think you will never run into, you do. | |
let rules = [ | |
rule(-(-x), x), | |
rule(-(x-y), y-x), | |
rule(one/(x/y), y/x), | |
rule(tan(atan(x)), x), | |
rule(sinh(asinh(x)), x), | |
rule(asinh(sinh(x)), x), | |
rule(atanh(tanh(x)), x), | |
rule(acosh(cosh(x)), abs(x)), | |
rule(log(exp(x)), x), | |
rule(log2(exp2(x)), x), | |
-- rule(log10(exp10(x)), x), | |
rule(exp(log(x)), x), -- expands the domain to include negative numbers | |
rule(exp2(log2(x)), x), | |
rule(sqrt(x*x), abs(x)), | |
rule(sqrt(x)*sqrt(x), x), -- expands the domain to include negative numbers | |
rule(log(pow(x, y)), y*log(abs(x))), -- expands the domain for values of y that | |
-- cannot be expressed as even rationals. | |
rule(log2(pow(x, y)), y * log2(abs(x))), | |
-- identity functions | |
rule(x/one, x), | |
rule(x/negone, -x), | |
rule(one*x, x), | |
rule(negone*x, -x), | |
rule(x-zero, x), | |
rule(zero+x, x), | |
rule(posinf+noninf, posinf), | |
rule(neginf+noninf, neginf), | |
rule(noninf/posinf, zero), | |
rule(noninf/neginf, zero), | |
rule(pow(x, zero), one), | |
rule(pow(x, one), x), | |
rule(pow(x, two), x*x), | |
rule(pow(x, three), x*x*x), | |
rule(pow(x, negone), one/x), | |
rule(pow(x, negtwo), one/(x*x)), | |
rule(pow(x, negthree), one / (x * x * x)), | |
rule(pow(x, y)*pow(x, z), pow(x, y+z)), | |
rule(pow(x, y)/pow(x, z), pow(x, y-z)), | |
rule(pow(x, z)*pow(y, z), pow(x*y, z)), | |
rule(hypot(zero, x), abs(x)), | |
-- degenerate and reflexive cases | |
rule(zero*x, zero), | |
rule(zero/x, zero), | |
rule(x-x, zero), | |
rule(x-k, (-k)+x), | |
rule(x/k, (one/k)*x), | |
rule(one/(k*x), (one/k)*(one/x)), -- why is this not matching? | |
rule(y/(y/x), x), | |
rule(zero-x, -x), | |
rule(x/x, one), -- expands the domain for x == 0. | |
rule(-x/x, negone), | |
rule(x/(-x), negone), | |
rule(min(x, x), x), | |
rule(max(x, x), x), | |
rule(x < x, zero), -- these rules are not true for Not-A-Number. | |
rule(x > x, zero), | |
rule(x != x, zero), | |
rule(x <= x, one), | |
rule(x >= x, one), | |
rule(x == x, one), | |
rule(k*abs(x), abs(k*x)), | |
-- ... skipping a whole lot for now ... | |
-- redundant applications | |
rule(abs(-x), abs(x)), | |
rule(abs(abs(x)), abs(x)), | |
-- some of these with casting and floor can occur in oscillators. | |
rule(floor(floor(x)), floor(x)), | |
rule(ceil(floor(x)), floor(x)), | |
-- rule(round(floor(x)), floor(x)), | |
-- rule(trunc(floor(x)), floor(x)), | |
rule(floor(floor(x+half)), floor(x)), -- half could be replaced by any number in [0,1) | |
rule(floor(ceil(x)), ceil(x)), | |
rule(ceil(ceil(x)), ceil(x)), | |
-- rule(round(ceil(x)), ceil(x)), | |
-- rule(trunc(ceil(x)), ceil(x)), | |
rule(floor(ceil(x) + half), ceil(x)), | |
rule(floor(x - floor(x)), zero), | |
rule(floor(f32(floor(x))), f32(floor(x))), | |
rule(floor(f64(floor(x))), f64(floor(x))), | |
rule(floor(f32(x - floor(x))), zero), | |
rule(floor(f64(x - floor(x))), zero), | |
rule((x - floor(x)) - floor((x - floor(x)) + half), x - floor(x + half)), | |
rule(f32(x - floor(x)) - floor(f32(x - floor(x)) + half), | |
f32(x - floor(x + half))), | |
rule(f64(x - floor(x)) - floor(f64(x - floor(x)) + half), | |
f64(x - floor(x + half))), | |
rule(max(max(x, y), y), max(x, y)), | |
rule(max(max(x, y), x), max(x, y)), | |
rule(min(min(x, y), y), min(x, y)), | |
rule(min(min(x, y), x), min(x, y)), | |
rule(max(min(x, y), max(x, y)), max(x, y)), | |
rule(min(min(x, y), max(x, y)), min(x, y)), | |
rule(max(x + pos, x), x + pos), | |
rule(max(x - pos, x), x), | |
rule(max(x + neg, x), x), | |
rule(max(x - neg, x), x - neg), | |
rule(max(k + min(x, y), k + max(x, y)), k + max(x, y)), | |
rule(min(k + min(x, y), k + max(x, y)), k + min(x, y)), | |
rule(min(monoup(x), monoup(y)), monoup(min(x, y))), | |
rule(max(monoup(x), monoup(y)), monoup(max(x, y))), | |
rule(min(monodn(x), monodn(y)), monodn(max(x, y))), | |
rule(max(monodn(x), monodn(y)), monodn(min(x, y))), | |
] | |
-- add an empty rules list to each MathOpUGen leaf class. | |
MathOpUGen allLeafSubclasses forEach \c { c.rules = [] } | |
-- add each rule to the rules list of the class of its root node. | |
rules forEach \r{ | |
r.lhs.ugenClass.rules add(r) | |
} | |
} | |
fn rewrite(o MathOpUGen) { | |
o.rules firstNonNil(\r { r rewrite(o) }, o) | |
} | |
--------------------------------------------------------------------------- | |
fn analyzeGraph(o SynthDef, graph Signal) { | |
o traceGraph(graph) | |
o.tsvars mergeTSVars(o.ugens) | |
o.tsallocs = o.tsvars calcDelayLengths | |
o.ugens vec collectConsumers | |
o.ugens vec typeInference | |
o.signals vec setUndeterminedElemTypeToDefault | |
o.tsvars vec setUndeterminedElemTypeToDefault | |
o.signals vec shapeInference | |
findGraphCuts(o.ugens vec, o.tsvars vec) | |
let rootsToTrees = cutGraphToTrees(o.ugens vec) | |
o.rootsToTrees = rootsToTrees | |
o.ugens vec addTSVarAntecedents(rootsToTrees) | |
o.ugens vec addPullAntecedents(rootsToTrees) | |
let sortedTrees = rootsToTrees sortTrees | |
sortedTrees.root forEach \t, i { println(i, t lispStr(4)) } | |
o splitClocks(sortedTrees) | |
} | |
--------------------------------------------------------------------------- | |
-- Random noise | |
fn urand(shape List = [], seed Int = 0) = URandUGen(shape, seed) | |
fn white(shape List = [], seed Int = 0) = BRandUGen(shape, seed) | |
-- Define an output jack. | |
fn jackout(x, index) = jackout_(x asSignal, index) | |
fn jackout_(x Signal, index Int) = JackOut{ins: [x], index:index} | |
-- Define an input jack. | |
fn jackin(x, index) = jackin_(x asSignal, index) | |
fn jackin_(x Signal, index Int) = JackOut{ins: [x], index:index} | |
-- Create a time series var. A maximum delay time can be specified. | |
fn ts() = TimeSeriesVar{ maxDelay: nil } | |
fn ts(maxDelay) = ts_(maxDelay asSignal) | |
fn ts_(maxDelay Signal) = TimeSeriesVar{ maxDelay: maxDelay } | |
-- Write a signal to a time series var. | |
fn wr(ts TimeSeriesVar, x) = wr_(ts, x asSignal) | |
fn wr_(ts TimeSeriesVar, x Signal) { | |
if (ts.writer) { | |
"This TimeSeriesVar already has a writer." println | |
0 someKindOfError | |
} | |
let writer = TSWrite{ts: ts, ins: [x]} | |
ts.writer = writer | |
writer | |
} | |
fn w_(ts TimeSeriesVar, x Signal) { | |
if (ts.writer) { | |
"This TimeSeriesVar already has a writer." println | |
0 someKindOfError | |
} | |
let writer = TSWrite{ts: ts, ins: [x]} | |
ts.writer = writer | |
writer | |
} | |
fn w(ts TimeSeriesVar, x) = w_(ts, x asSignal) | |
-- Set an initial condition for the time series variable. | |
fn i(ts TimeSeriesVar, delay, value) = i_(ts, delay, value asSignal) | |
fn i_(ts TimeSeriesVar, delay, value Signal) { | |
let initter = TSInit{ts: ts, ins: [value], delay: delay} | |
ts.initters push(initter) | |
initter | |
} | |
-- Calling a time series variable with a fixed delay read. | |
fn call(ts TimeSeriesVar, delay Real = 0) { | |
let reader = TSFixRead{ts: ts, ins: [], delay: delay} | |
ts.fixreaders push(reader) | |
reader | |
} | |
-- A variable delay read from a time series variable. | |
fn call(ts TimeSeriesVar, delay UGen) { | |
let reader = TSVarRead{ts: ts, ins: [delay]} | |
ts.varreaders push(reader) | |
reader | |
} | |
fn fs() { | |
var u = SampleRateUGen{ins: []} | |
println(">>fs hash") | |
println("<<fs hash", u eqhash) | |
u hashCons | |
} | |
fn T() = 1. / fs() | |
------------------------------ | |
fn sel(a, b, c ) = a ? b : c | |
fn sel(a, b, c UGen) = SelectUGen(a, b, c) | |
fn sel(a, b UGen, c ) = SelectUGen(a, b, c) | |
fn sel(a, b UGen, c UGen) = SelectUGen(a, b, c) | |
fn sel(a UGen, b, c ) = SelectUGen(a, b, c) | |
fn sel(a UGen, b, c UGen) = SelectUGen(a, b, c) | |
fn sel(a UGen, b UGen, c ) = SelectUGen(a, b, c) | |
fn sel(a UGen, b UGen, c UGen) = SelectUGen(a, b, c) | |
fn sgn(x) = sel(x < 0, -1, sel(x > 0, 1, 0)) | |
fn sgnn(x) = sel(x < 0, -1, 1) | |
fn ustep(x) = sel(x < 0, 0, sel(x > 0, 1, .5)) | |
fn cmp(a, b) = sel(a < b, -1, sel(a > b, 1, 0)) | |
-- round, floor, ceil with a quantum | |
fn round(x, q) = sel(q == 0, x, q * round(x / q)) | |
fn ceil(x, q) = sel(q == 0, x, q * ceil(x / q)) | |
fn floor(x, q) = sel(q == 0, x, q * floor(x / q)) | |
fn sq(x) = x * x | |
fn cb(x) = x * x * x | |
fn qu(x) = x sq sq | |
fn ssq(x) = x * x abs -- signed square | |
fn ssqrt(x) = x sgn * x abs sqrt | |
fn spow(x, y) = x sgn * x abs pow(y) | |
fn evenpow(x, y) = x abs pow(y) | |
fn sin2pi(x) = sinpi(2 * x) | |
fn cos2pi(x) = cospi(2 * x) | |
fn tan2pi(x) = tanpi(2 * x) | |
fn usin2pi(x) = x sin2pi uni | |
fn ucos2pi(x) = x cos2pi uni | |
fn sinc(x) = sel(x == 0, 1, sin(x) / x) | |
fn frac(x) = x - x floor | |
fn princ1(x) = x - x round | |
-- fast approximation of sine | |
fn fsin(x) { | |
let q = x princ1 | |
q * (8 - 16 * abs(q)) | |
} | |
-- fast approximation of sine with extra precision | |
fn fsinx(x) { | |
let a = x fsin | |
a + .224 * a * (abs(a) - 1) | |
} | |
fn fcos(x) = fsin(x+.25) -- fast approximation of cosine | |
fn fcosx(x) = fsinx(x+.25) -- fast approximation of cosine with extra precision | |
fn smoothStep(x) { | |
let t = x uclip | |
t sq * (3 - 2 * t) | |
} | |
fn smoothStep2(x) { | |
let t = x uclip | |
t cb * (10 - t * (15 + 6 * t)) | |
} | |
fn bsmoothStep(x) { -- bipolar in and out | |
let t = x bclip | |
.5 * t * (3 - t sq) | |
} | |
fn smoothAdjustment(a, b, k) = .125 * k * qu(max(0, k - abs(a - b)) / k) | |
fn smoothMin(a, b, k) = min(a, b) - smoothAdjustment(a, b, k) | |
fn smoothMax(a, b, k) = max(a, b) + smoothAdjustment(a, b, k) | |
-- sigmoids | |
fn distort(x) = x / (1 + x abs) | |
fn softclip(x) { | |
let ax = x abs | |
sel(ax < .5, x, (ax - .25) / x) | |
} | |
fn sigmoid0(x) = sel(abs(x)>1.5, sgn(x), x - (4/27)*cb(x)) | |
fn sigmoid1(x) = erf(sqrt(pi)/2*x) | |
fn sigmoid2(x) = 2*x/(abs(2*x)+3/(2+4*sq(x))) | |
fn sigmoid3(x) = (27*x+cb(x))/(27+9*sq(x)) | |
fn sigmoid4(x) = tanh(x) | |
fn sigmoid5(x) = sgn(x)*(1-1/(1+abs(x)+sq(x)+qu(x))) | |
fn sigmoid6(x) = x / sqrt(x sq + 1) | |
fn sigmoid7(x) = (2/pi)*atan(pi/2*x) | |
fn sigmoid8(x) = x/(1+abs(x)) | |
-- clipping | |
fn max0(x) = x max(0) -- a.k.a. relu = recified linear unit | |
fn clip(x, a, b) = x max(a) min(b) -- clip between a <= x <= b | |
fn clip0(x, a) = x clip(0, a) -- clip between 0 <= x <= a | |
fn clip2(x, a) = x clip(-a, a) -- clip between -a <= x <= +a | |
fn uclip(x) = x clip(0, 1) -- clip to unipolar range | |
fn bclip(x) = x clip(-1,1) -- clip to bipolar range | |
fn wrap(x, a, b) = a + (x-a) % (b-a) -- wrap between a <= x < b | |
fn wrap0(x, a) = x % a -- wrap between 0 <= x < a | |
fn wrap2(x, a) = x wrap(-a,a) -- wrap between -a <= x < +a | |
fn uwrap(x) = x frac -- wrap to unipolar range | |
fn bwrap(x) = x wrap(-1,1) -- wrap to bipolar range | |
fn fold(x, a, b) = fold0(x-a, b-a) + a -- fold between a <= x < b | |
fn fold0(x, a) = ufold(x/a)*a -- fold between 0 <= x < a | |
fn fold2(x, a) = x fold(-a,a) -- fold between -a <= x < +a | |
fn ufold(x) = 1 - abs(1 - x + 2 * floor(.5*x)) -- fold to unipolar range | |
fn bfold(x) = x fold(-1,1) -- fold to bipolar range | |
fn excess(x, b) = x - x clip2(b) | |
fn isuni(x) = 0 <= x && x <= 1 -- is in unipolar range | |
fn isbi(x) = -1 <= x && x <= 1 -- is in bipolar range | |
fn isint(x) = x == x floor | |
-- transforming between unipolar and a linear or exponential range | |
-- bipolar to unipolar | |
fn uni(x) = .5 + .5 * x | |
-- unipolar to bipolar | |
fn bi(x) = 2 * x - 1 | |
-- the line formula, m*x + b | |
fn lin(x, m, b) = m * x + b | |
-- the exponential formula a*x^b | |
fn axb(x, m, b) = a * pow(x, b) | |
-- unipolar to linear | |
fn unilin(x, a, b) = a + x * (b - a) | |
-- unipolar to exponential | |
fn uniexp(x, a, b) = a * pow(b / a, x) | |
-- linear to unipolar | |
fn linuni(x, a, b) = (x - a) / (b - a) | |
-- exponential to unipolar | |
fn expuni(x, a, b) = log(x / a) / log(b / a) | |
-- bipolar to linear | |
fn bilin(x, a, b) = x uni unilin(a, b) | |
-- bipolar to exponential | |
fn biexp(x, a, b) = x uni uniexp(a, b) | |
-- linear to bipolar | |
fn linbi(x, a, b) = x linuni(a, b) bi | |
-- exponential to bipolar | |
fn expbi(x, a, b) = x expuni(a, b) bi | |
-- transforming between two ranges | |
-- linear to linear | |
fn linlin(x, a, b, c, d) = x linuni(a, b) unilin(c, d) | |
-- linear to exponential | |
fn linexp(x, a, b, c, d) = x linuni(a, b) uniexp(c, d) | |
-- exponential to linear | |
fn explin(x, a, b, c, d) = x expuni(a, b) unilin(c, d) | |
-- exponential to exponential | |
fn expexp(x, a, b, c, d) = x expuni(a, b) uniexp(c, d) | |
-- unipolar to unipolar warps | |
fn warp_pow(x, p) = pow(x, p) -- reciprocal of p gives a curve inverted around y = x. | |
fn warp_sin(x) = sinpi(.5 * x) -- warp_asin is the inverse about y = x. | |
fn warp_asin(x) = (2 / pi) * arcsin(x) | |
-- unipolar to unipolar warps, double reflection (i.e., rotated 180 about (.5, .5)) | |
fn warp_pow_r(x, p) = 1 - pow(1 - x, p) -- reciprocal of p gives a curve inverted around y = x. | |
fn warp_sin_r(x) = 1 - sinpi(.5 * (1 - x)) -- warp_asinR is the inverse about y = x. | |
fn warp_asin_r(x) = 1 - (2 / pi) * arcsin(1 - x) | |
-- unipolar to unipolar S warps | |
fn swarp_pow(x, p) = sel(x < .5, .5 * pow(2 * x, p), 1 - .5 * pow(2 - 2 * x, p)) | |
fn swarp_sin(x) = sinpi(x - 1) uni | |
fn swarp_asin(x) = x bi asin / pi + .5 | |
-- unipolar to unipolar S warps, double reflection | |
fn swarp_pow_r(x, p) = .5 * sel(x < .5, (1 - pow(1 - 2 * x, p)), (1 + pow(2 * x - 1, p))) | |
fn swarp_sin_r(x) = sel(x < .5, .5 * sinpi(x), 1 + .5 * sinpi(x + 1)) | |
fn swarp_asin_r(x) = sel(x < .5, asin(2 * x) / pi, 1 + asin(2 * x - 2) / pi) | |
-- general purpose warp | |
fn bwarp(x, w) { -- bipolar to bipolar warping | |
let u = .5 * x - .5 | |
(w + u) / (w * x - u) | |
} | |
fn bswarp(x, w) { -- bipolar to bipolar S warping | |
sel(x == 0, 0, do { | |
let wx = w * x | |
let sx = x sgn | |
sx * (wx - x) / (2 * wx - sx * w - x) | |
}) | |
} | |
-- unipolar to unipolar warping | |
fn warp(x, w) = (w * x) / (w * bi(x) - x + 1) | |
-- unipolar to unipolar S warping | |
fn swarp(x, w) = uni(bswarp(bi(x), w)) | |
-- invert a signal about y=a. | |
fn invert(x, a) = 2 * a - x | |
-- invert a signal within a range. (or equivalently, invert about y = (a+b)/2 ) | |
fn invert(x, a, b) = a + b - x | |
-- variable order chebyshev | |
fn chebyv(x, n) = cos(x acos * n) | |
-- musical units conversion | |
let kSecsToMin = 1/60 | |
let kMinToSecs = 60 | |
let kDegToRad = pi/180 | |
let kRadToDeg = 180/pi | |
fn octnn(x) = x * 12 -- octaves to note number | |
fn nnoct(x) = x / 12 -- note number to octaves | |
fn nncents(x) = x * 100 -- note number to cents | |
fn centsnn(x) = x / 100 -- cents to note number | |
fn octcents(x) = x * 1200 -- octaves to cents | |
fn centsoct(x) = x / 1200 -- cents to octaves | |
fn nnhz(x) = 440 * exp2((x - 69) / 12) -- note number to Hertz | |
fn hznn(x) = 69 + 12 * log2(x / 440) -- Hertz to note number | |
fn octhz(x) = 440 * exp2(x - 5.75) -- octaves to Hertz | |
fn hzoct(x) = 5.75 + log2(x / 440) -- Hertz to octaves | |
fn centshz(x) = 440 * exp2((x - 6900) / 1200) -- cents to Hert | |
fn hzcents(x) = 6900 + log2(x / 440) -- Hertz to cents | |
fn centsratio(x) = exp2(x / 1200) -- cents to frequency ratio | |
fn ratiocents(x) = log2(x) * 1200 -- frequency ratio to cents | |
fn stratio(x) = exp2(x / 12) -- semitones to frequency ratio | |
fn ratiost(x) = log2(x) * 12 -- frequency ratio to semitones | |
fn octratio(x) = exp2(x) -- octaves to frequency ratio | |
fn ratiooct(x) = log2(x) -- frequency ratio to octaves | |
fn dbamp(x) = pow(10, .05 * x) -- decibels to linear amplitude | |
fn ampdb(x) = 20 * log10(x) -- linear amplitude to decibels | |
fn bpmhz(x) = x * kSecsToMin -- beats per minute to Hertz | |
fn hzbpm(x) = x * kMinToSecs -- Hertz to beats per minute | |
fn bpmsec(x) = 60 / x -- beats per minute to seconds | |
fn secbpm(x) = 60 / x -- seconds to beats per minute | |
fn degrad(x) = x * kDegToRad -- degrees to radians | |
fn raddeg(x) = x * kRadToDeg -- radians to degrees | |
fn hzsec(x) = 1 / x -- Hertz to seconds | |
fn sechz(x) = 1 / x -- seconds to Hertz | |
fn cycrad(x) = 2 * pi * x -- cycles to radians | |
fn radcyc(x) = x / (2 * pi) -- radians to cycles | |
fn cycdeg(x) = x * 360 -- cycles to degrees | |
fn degcyc(x) = x / 360 -- degrees to cycles | |
-- indirect conversions | |
fn secnn(x) = x sechz hznn -- period to note number | |
fn secoct(x) = x sechz hzoct -- period to octaves | |
fn seccents(x) = x sechz hzcents -- period to cents | |
fn nnsec(x) = x nnhz hzsec -- note number to period | |
fn octsec(x) = x octhz hzsec -- octaves to period | |
fn centssec(x) = x centshz hzsec -- cents to period | |
fn bpmnn(x) = x bpmhz hznn -- BPM to note number | |
fn bpmoct(x) = x bpmhz hzoct -- BPM to octaves | |
fn bpmcents(x) = x bpmhz hzcents -- BPM to cents | |
fn nnbpm(x) = x nnhz hzbpm -- BPM to note number | |
fn octbpm(x) = x octhz hzbpm -- BPM to octaves | |
fn centsbpm(x) = x centshz hzbpm -- BPM to cents | |
-- variants of ring modulation | |
fn ring1(a, b) = a * b + a | |
fn ring2(a, b) = a * b + a + b | |
fn ring3(a, b) = a * a * b | |
fn ring4(a, b) = a * b * (a - b) | |
fn sumsq(a, b) = a sq + b sq | |
fn sqsum(a, b) = sq(a + b) | |
fn difsq(a, b) = a sq - b sq | |
fn sqdif(a, b) = sq(a - b) | |
fn absdif(a, b) = abs(a - b) | |
fn vca(x, a) = x * max(0, a) | |
fn scaleneg(x, a) = sel(x < 0, x * a, x) | |
fn scalepos(x, a) = sel(x > 0, x * a, x) | |
fn scalenegpos(x, a, b) = x * sel(x < 0, a, b) | |
fn above(x, a) = sel(x > a, x, 0) | |
fn below(x, a) = sel(x < a, x, 0) | |
fn absabove(x, a) = sel(x abs > a, x, 0) | |
fn absbelow(x, a) = sel(x abs < a, x, 0) | |
fn zapgremlins(x) { | |
let ax = x abs | |
sel(1e-15 < ax && ax < 1e15, x, 0) | |
} | |
fn decayCoeff(n, amp) = amp ^ (1/n) -- calculate coefficient to decay to amp in n cycles. | |
fn decay40dB(n) = decayCoeff(n, .01) -- calculate coefficient to decay by 40 dB in n cycles. | |
fn decay60dB(n) = decayCoeff(n, .001) -- calculate coefficient to decay by 60 dB in n cycles. | |
--------- | |
fn bfold(x) = 1 - abs(x - 1 - 4 * floor(.25*x + .25)) | |
-- Bipolar triangular wave folding can be cheaper if the | |
-- input can be assumed to be bounded in [-3, 5] | |
fn bfold_cheap(x) = abs(abs(x - 1) - 2) - 1 | |
fn panfun(x) { | |
let a = 0.337403011047526069 | |
let b = -1.334338069017510398 | |
let c = -a - b - 1 | |
1 + x * (c + x * (b + x * a)) | |
} | |
fn panfuns(x) = [x, 1 - x] panfun | |
fn pan(x, pos) = x * pos uni panfuns | |
-- simple filters | |
fn diff(x) = x - x z1 | |
fn slope(x) = fs() * x diff | |
fn accel(x) = x slope slope | |
fn jerk(x) = x slope accel | |
fn white(shape=[], seed=0) = birand(shape, seed) | |
fn violet(shape=[], seed=0) = .5 * diff(white(shape, seed)) | |
fn blue(shape=[], seed=0) = .5 * diff(pink(shape, seed)) | |
fn pink(shape=[], seed=0) = .25 * pink_filter(white(shape, seed)) | |
fn pink_vec(shape=[], seed=0) = .25 * pink_filter_vec(white(shape, seed)) | |
fn pinke(shape=[], seed=0) = .25 * pink_eco_filter(white(shape, seed)) | |
fn red(shape=[], seed=0, a=.125) { | |
let y = ts() | |
y wr(bfold_cheap(a*birand(shape, seed) + y(1))) | |
} | |
fn coin(prob, shape=[], seed=0) = urand(shape, seed) < prob | |
fn velvet(freq, shape=[]) = coin(freq * T(), shape) | |
fn dust(freq, shape=[]) = urand(shape, default_seed(0)) * velvet(freq, shape) | |
fn xrand(a, b, shape=[]) = uniexp(urand(shape, default_seed(0)), a, b) | |
fn pink_filter(x) { | |
-- from Paul Kellett | |
let b0s = [.0555179, .0750759, .1538520, .3104856, .5329522, -.0168980] | |
let a1s = [.99886, .99332, .96900, .86650, .55000, -.7616] | |
let d1 = ts() | |
let d2 = ts() | |
.5362 * x + d1 wr(a1s * d1(1) + b0s * x) sum + d2 wr(.115926 * d2(1)) | |
} | |
fn lag(x, t) { | |
let a = decay40dB(t * fs()) | |
let y = ts() | |
y wr(x + a * (y(1) - x)) | |
} | |
fn leaky(x, a) { | |
let y = ts() | |
y wr(y(1) * a + x) | |
} | |
fn onepole(x, a) { | |
let y = ts() | |
y w(x + a*(y(1) - x)) | |
} | |
fn onezero(x, a) = x + a*(z1(x) - x) | |
fn leakdc(x, k) { | |
let y = ts() | |
y w(x - z1(x) + k * y(1)) | |
} | |
fn decay(x, t) = leaky(x, decay40dB(t * fs())) | |
fn decay2(x, atk, dcy) = decay(x, dcy) - decay(x, atk) | |
-- sample and hold | |
fn sah(t, x) { | |
let y = ts() | |
y wr(sel(t > 0, x, y(1))) | |
} | |
-- flip flops | |
-- toggle flip flop | |
fn toggle_ff(x) { | |
let y = ts() | |
y w(sel(x>0, 1-y(1), y(1))) | |
} | |
-- set, reset flip flop | |
fn setreset_ff(s, r) { | |
let y = ts() | |
y w(sel(r>0, 0, sel(s>0, 1, y(1)))) | |
} | |
-- set, reset, toggle flip flop | |
fn srt_ff (s, r, t) { | |
let y = ts() | |
y w(sel(r>0, 0, sel(s>0, 1, sel(t>0, 1-y(1), y(1))))) | |
} | |
-- phasor is the core of many oscillators | |
fn phasor(fm, pm=0) { | |
let phase = ts() | |
phase w(frac(phase(1) + fm * T())) | |
frac(phase() + pm) | |
} | |
fn z1(x) { | |
-- A one sample delay of x. | |
let y = ts() | |
y w(x) | |
y(1) | |
} | |
fn z2(x) { | |
-- A one sample delay of x. | |
let y = ts() | |
y w(x) | |
y(2) | |
} | |
fn zn(x, n=3) { | |
-- Returns a tuple of feed forward delays of x, starting with a zero delay. | |
let y = ts() | |
y w(x) | |
tuple(y(i) for i in range(n)) --------<<<<< FIX ME | |
} | |
-- End of cycle. Emit a trigger when phasor wraps. | |
fn eoc(x) = abs(x - x z1) > .5 | |
fn rising(x) = x > x z1 | |
fn falling(x) = x < x z1 | |
fn changing(x) = x != x z1 | |
fn nochange(x) = x == x z1 | |
fn peak(x) = x < x z1 && x z1 > x z2 | |
fn trough(x) = x > x z1 && x z1 < x z2 | |
fn tremolo(x, freq, amount=.5, pm=0) = x * fsinosc(freq, pm) bilin(1 - amount, 1) | |
fn fadein(x, t) { | |
let dt = 1/(t*fs()) | |
let y = ts() | |
y w(dt + min(1, y(1))) | |
x * y() cb | |
} | |
-- unipolar waveshapers | |
fn sawshift(x, shift) = frac(x + shift) -- phase shift a unipolar sawtooth. | |
fn quadr(x) = frac(x + .25) -- shift a phasor by one quarter cycle | |
-- triangle waves | |
-- Unipolar ramp to bipolar triangle wave. | |
fn btri(x) = abs(4 * x - 2) - 1 | |
fn btri0(x) = 1 - abs(4 * x quadr - 2) -- 0 degrees initial phase | |
fn btri1(x) = abs(4 * x - 2) - 1 -- 90 degrees initial phase | |
fn btri2(x) = abs(4 * x quadr - 2) - 1 -- 180 degrees initial phase | |
fn btri3(x) = 1 - abs(4 * x - 2) -- 270 degrees initial phase | |
fn utri0(x) = 1 - abs(1 - 2 * x quadr) -- 0 degrees. unipolar output. '\, trisin | |
fn utri1(x) = abs(1 - 2 * x) -- 90 degrees. unipolar output. \/ tricos | |
fn utri2(x) = abs(1 - 2 * x quadr) -- 180 degrees. unipolar output. ,/' -trisin | |
fn utri3(x) = 1 - abs(1 - 2 * x) -- 270 degrees. unipolar output. /\ -tricos | |
-- trapezoid waves | |
fn trapez0(x) = bclip(2 - abs(4 - 8 * x quadr)) -- 0 degrees. bipolar output. | |
fn trapez1(x) = bclip(abs(4 - 8 * x) - 2) -- 90 degrees. bipolar output. | |
fn trapez2(x) = bclip(abs(4 - 8 * x quadr) - 2) -- 180 degrees. bipolar output. | |
fn trapez3(x) = bclip(2 - abs(4 - 8 * x)) -- 270 degrees. bipolar output. | |
-- pulse waves | |
fn upulse(x, pwm) = x < pwm -- unipolar pulse wave | |
fn bpulse(x, pwm) = upulse(x,pwm) bi -- bipolar pulse wave | |
fn zpulse(x, pwm) = frac(x - pwm) - x -- zero DC pulse wave | |
-- pulse waves. As in SuperCollider, these always output one value of the opposite polarity each cycle. | |
fn upulse1(x, pwm) = x eoc sel(pwm < .5, x < pwm) -- unipolar | |
fn bpulse1(x, pwm) = x upulse1(pwm) bi -- bipolar | |
fn zpulse1(x, pwm) = x eoc sel(pwm < .5, x zpulse(pwm)) -- zero DC | |
-- inspired by the Intellijel Rubicon waveform. | |
fn izigzag(x) = x utri1 - (x > .5) -- moving inwards | |
fn ozigzag(x) = x utri1 - (x < .5) -- moving outwards | |
-- Bipolar ramp to bipolar triangle wave. | |
fn bbtri(x) = abs(2 * x - 4 * x uni floor) - 1 | |
-- variable triangle and saw | |
-- an amplitude scaled difference of parabolas | |
fn par(x) = x bi sq -- unipolar ramp to parabola | |
fn vartri(x, pwm) = (.25 / (pwm - sq(pwm))) * (par(x) - par(frac(x - pwm))) | |
fn varsaw(x, pwm) = bi(vartri(x, pwm)) | |
fn usquare(x) = x < .5 | |
fn bsquare(x) = sel(x < .5, -1, 1) | |
fn lfsaw(fm, pm=0) = phasor(fm, pm) bi | |
fn lfimp(fm, pm=0) = phasor(fm, pm) eoc | |
fn lftri(fm, pm=0) = phasor(fm, pm) btri | |
fn lfpar(fm, pm=0) = phasor(fm, pm) par | |
fn lftrap(fm, pm=0) = phasor(fm, pm) trapez0 | |
fn lfusqr(fm, pm=0) = phasor(fm, pm) usquare | |
fn lfsqr(fm, pm=0) = phasor(fm, pm) bsquare | |
fn lfzig(fm, pm=0) = phasor(fm, pm) izigzag | |
fn lfzag(fm, pm=0) = phasor(fm, pm) ozigzag | |
fn lfpar(fm, pm=0) = phasor(fm, pm) par bi | |
fn lfvsaw(fm, pwm, pm=0) = phasor(fm, pm) varsaw(pwm) | |
fn lfupulse(fm, pwm, pm=0) = phasor(fm, pm) upulse1(pwm) | |
fn lfbpulse(fm, pwm, pm=0) = phasor(fm, pm) bpulse1(pwm) | |
fn lfzpulse(fm, pwm, pm=0) = phasor(fm, pm) zpulse(pwm) | |
fn combn(x, delay_time, decay_time) { | |
let a = decay60dB(decay_time / delay_time) | |
let delay_samples = delay_time * fs() | |
let y = ts(delay_samples) | |
y wr(x + a * y(delay_samples)) | |
} | |
fn sinosc(fm, pm=0) = phasor(fm, pm) sin2pi | |
fn sinosc(fm, pm=0) = phasor(fm, pm) sin2pi | |
fn fsinosc(fm, pm=0) = phasor(fm, pm) fsin | |
fn fsinxosc(fm, pm=0) = phasor(fm, pm) fsinx | |
------------------------------ | |
fn bubbles() = .4 lfsaw * 2 + [8, 7.23] lfsaw * .25 + 9.667 |> exp2 sinosc * 4c |> combn(.2,4) | |
fn bubbles2() = .4 lfsaw * 2 + #f32[8, 7.23] lfsaw * .25 + 9.667 |> exp2 sinosc * 4c |> combn(.2,4) | |
"==========================================" println | |
">makeRewriteRules" println | |
makeRewriteRules() | |
"<makeRewriteRules" println | |
SynthDef new with \csd { | |
fs() | |
fs() | |
let b = bubbles() jackout(0) | |
csd analyzeGraph(b) | |
"==========================================" println | |
{ signals: csd.signals len, | |
ugens: csd.ugens len, | |
scalars: csd.scalars len, | |
arrays: csd.arrays len, | |
tsvars: csd.tsvars len, | |
inputs: csd.inputs len, | |
outputs: csd.outputs len, | |
ugenTable: csd.ugenTable len, | |
serialNos: Signal.serialNos | |
} println | |
fn ugenClassName(x UGen) { x class name } | |
--fn signalInfo(o Signal) = "%1 %2" fmt(o class name, o.serialNo) | |
--fn signalInfo(o ConstSignal) = "%1 %2 %3" fmt(o class name, o.serialNo, o.value) | |
--fn printUgenInfo(o UGen) = "%1 : %2 -> %3" fmt(o signalInfo, o.ins signalInfo, o.consumers signalInfo) println | |
fn signalInfo(o Signal) = "%1 %2 %3 %4 %5 %6" fmt(o class name, o.serialNo, o.rate, o.elemType, o.shape, o.graphCut) | |
fn signalInfo(o ConstSignal) = "%1 %2 %3 %4 %5" fmt(o class name, o.serialNo, o.value, o.elemType, o.shape) | |
proc printUGenInfo(o UGen) { | |
o signalInfo println | |
println(" ", o.ins signalInfo) | |
println(" ", o.consumers signalInfo) | |
} | |
println("ugenInfo", csd.ugens len) | |
csd.ugens vec printUGenInfo | |
"==========================================" println | |
let synthName = "bubbles" | |
"CREATE CCodeGen" println | |
let ccodegen = CCodeGen(synthName, csd) | |
">genClass --------------" println | |
let ccode = ccodegen genClass | |
ccode println | |
"<genClass --------------" println | |
var buildDir = "SAPF_BUILD" getenv | |
if (!buildDir) { | |
let homeDir = "HOME" getenv | |
if (homeDir) { | |
buildDir = homeDir $ "/sapf-build-5/" | |
} else { | |
buildDir = "/tmp/" | |
} | |
} | |
let filepath = buildDir $ synthName $ "_synth" | |
let filepath_c = filepath $ ".cpp" | |
let filepath_o = filepath $ ".o" | |
let filepath_dylib = filepath $ ".dylib" | |
do { -- compile | |
ccode writeToFile(filepath_c) | |
let options = "-x c++ -arch x86_64 -std=c++1z -stdlib=libc++ -O3 -ffast-math" | |
let cmd = "clang %^ -o \"%^\" -c \"%^\"" fmt(options, filepath_o, filepath_c) | |
cmd println | |
let compileResult = cmd syscmd | |
println("status:", compileResult.status) | |
println("stdout:", compileResult.stdout) | |
println("stderr:", compileResult.stderr) | |
} | |
do { -- link | |
let options = "-arch x86_64 -dynamiclib -undefined dynamic_lookup -compatibility_version 1" | |
let cmd = "clang %^ -o \"%^\" \"%^\"" fmt(options, filepath_dylib, filepath_o) | |
cmd println | |
let compileResult = cmd syscmd | |
println("status:", compileResult.status) | |
println("stdout:", compileResult.stdout) | |
println("stderr:", compileResult.stderr) | |
} | |
do { -- run audio engine | |
let cmd = "/usr/local/bin/sapf_audioengine5 %^ %^" fmt(synthName, filepath_dylib) | |
cmd println | |
let result = cmd syscmd | |
println("status:", result.status) | |
println("stdout:", result.stdout) | |
println("stderr:", result.stderr) | |
} | |
} | |
"==========================================" println | |
let result = "ls -l" syscmd | |
println("status:", result.status) | |
println("stdout:", result.stdout) | |
println("stderr:", result.stderr) | |
"DONE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment