September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,12 @@
// Both of the following declarations can be seen as a tree,
// var -> <varname>
var/x
var y
// They can also be defined like this.
// This is once again a tree structure, but this time the "var" only appears once, and the x and y are children.
var
x
y
// And like this, still a tree structure.
var/x, y

View file

@ -0,0 +1,12 @@
// Here, "/obj" is the type, a /obj being a simple game object.
var/obj/x
// It can also be defined like this, because of the tree structure:
var
obj
x
// Or this
var/obj
x
// ...
// You get the idea

View file

@ -0,0 +1,4 @@
var/x = 0
x = 10
var/y
y = "hi!"

View file

@ -1,8 +1,8 @@
#symbol program =
program =
[
#var c. // declaring variable. default value is $nil
#var a := 3. // declaring and initializing variables
#var b := "my string" length.
var c := $nil. // declaring variable.
var a := 3. // declaring and initializing variables
var b := "my string" length.
c := b + a. // assigning variable
].

View file

@ -0,0 +1,26 @@
// version 1.0.6
fun main(args: Array<String>) {
/* read-only variables */
val i = 3 // type inferred to be Int
val d = 2.4 // type inferred to be double
val sh: Short = 2 // type specified as Short
val ch = 'A' // type inferred to be Char
val bt: Byte = 1 // type specified as Byte
/* mutable variables */
var s = "Hey" // type inferred to be String
var l = 4L // type inferred to be Long
var b: Boolean // type specified as Boolean, not initialized immediately
var f = 4.4f // type inferred to be Float
b = true // now initialized
println("$i, $d, $sh, $ch, $bt, $s, $l, $b, $f")
s = "Bye" // OK as mutable
l = 5L // OK as mutable
b = false // OK as mutable
f = 5.6f // OK as mutable
println("$i, $d, $sh, $ch, $bt, $s, $l, $b, $f")
}

View file

@ -0,0 +1,9 @@
a.=4711
Say 'before sub a.3='a.3
Call sub a.
Say ' after sub a.3='a.3
Exit
sub: Procedure
use Arg a.
a.3=3
Return

View file

@ -0,0 +1 @@
a += 1

View file

@ -0,0 +1 @@
a = a+1

View file

@ -0,0 +1,2 @@
a = 1
b,c,d = 0

View file

@ -0,0 +1,5 @@
r = ~a
a = 3
#.output(r)
r = 5
#.output(a)

View file

@ -0,0 +1,3 @@
x = 14
y = 0.4E3
z = 3-2i

View file

@ -0,0 +1 @@
t$ = "Name"

View file

@ -0,0 +1 @@
n$ = """This is a quoted text"""

View file

@ -0,0 +1,3 @@
n = 4
a$ = "6 feet"
PRINT n * a$

View file

@ -0,0 +1 @@
DIM name$(100)

View file

@ -0,0 +1,5 @@
DEF MyFunction(x)
MyF2 = x^2
MyF3 = x^3
MyFunction = MyF2 + MyF3
END DEF

View file

@ -0,0 +1,2 @@
x = MyFunction(3)
PRINT x; MyFunction.MyF2; MyFunction.MyF3

View file

@ -0,0 +1 @@
DEF num=123

View file

@ -0,0 +1,69 @@
// variable declaration
var table, chair;
// assignment
var table = 10, chair = -10;
// multiple assignment to the same value
table = chair = 0;
// multiple assignment to an array
(
var table, chair;
#table, chair = [10, -10];
#table ... chair = [10, -10, 2, 3]; // with ellipsis: now chair is [-10, 2, 3]
)
// the letters a-z are predeclared in the interpreter for interactive programming
a = 10; x = a - 8;
// variables are type-neutral and mutable: reassign to different objects
a = 10; a = [1, 2, 3]; a = nil;
// immutable variables (only in class definitions)
const z = 42;
// lexical scope
// the closures g and h refer to different values of their c
(
f = {
var c = 0;
{ c = c + 1 }
};
g = f.value;
h = f.value;
c = 100; // this doesn't change it.
)
// dynamic scope: environments
f = { ~table = ~table + 1 };
Environment.use { ~table = 100; f.value }; // 101.
Environment.use { ~table = -1; f.value }; // 0.
// there is a default environment
~table = 7;
f.value;
// lexical scope in environments:
(
Environment.use {
~table = 100;
f = { ~table = ~table + 1 }.inEnvir;
};
)
f.value; // 101.
// because objects keep reference to other objects, references are not needed:
// objects can take the role of variables. But there is a Ref object, that just holds a value
a = Ref([1, 2, 3]); // a reference to an array, can also be written as a quote `[1, 2, 3];
f = { |x| x.value = x.value.squared }; // a function that operates on a ref
f.(a); // `[ 1, 4, 9 ]
// proxy objects serve as delegators in environments. This can be called line by line:
ProxySpace.push;
~z // returns a NodeProxy
~z.play; // play a silent sound
~z = ~x + ~y; // make it the sum of two silent sounds
~x = { PinkNoise.ar(0.1) }; // … which now are noise,
~y = { SinOsc.ar(440, 0, 0.1) }; // and a sine tone

View file

@ -0,0 +1,14 @@
var v; // global to the class that encloses this file
class C{ var v } // global to class C, each instance gets a new v
class C{fcn f{var v=123;}} // v can only be seen by f, initialized when C is
class C{fcn init{var [const] v=5;}} // init is part of the constructor,
so vars are promoted yo class scope. This allows const vars to be created at
construction time
var v=123; v="hoho"; //not typed
class C{var v} // C.v OK, but just v is not found
class C{var[const]v=4} // C.v=3 illegal (compile or run time, depending)
class C{var[mixin]v=4} // the compiler treats v as an int for type checking
class C{var[proxy]v=f; fcn f{println("my name is ",self.fcn.name)} }
v acts like a property to run f so C.v is the same as C.f()
class C{reg r} // C.r is compile time error
r:=5; // := syntax is same as "reg r=5", convenience