This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1 @@
TUPLE: point x y ;

View file

@ -0,0 +1,20 @@
// define a class to contain the two fields
// accessors to get/set the field values are automatically generated
class Point
{
Int x
Int y
}
class Main
{
public static Void main ()
{
// empty constructor, so x,y set to 0
point1 := Point()
// constructor uses with-block, to initialise values
point2 := Point { x = 1; y = 2}
echo ("Point 1 = (" + point1.x + ", " + point1.y + ")")
echo ("Point 2 = (" + point2.x + ", " + point2.y + ")")
}
}

View file

@ -0,0 +1,8 @@
class Point {
int x
int y
// Default values make this a 0-, 1-, and 2-argument constructor
Point(int x = 0, int y = 0) { this.x = x; this.y = y }
String toString() { "{x:${x}, y:${y}}" }
}

View file

@ -0,0 +1,17 @@
// Default Construction with explicit property setting:
def p0 = new Point()
assert 0 == p0.x
assert 0 == p0.y
p0.x = 36
p0.y = -2
assert 36 == p0.x
assert -2 == p0.y
// Direct Construction:
def p1 = new Point(36, -2)
assert 36 == p1.x
assert -2 == p1.y
def p2 = new Point(36)
assert 36 == p2.x
assert 0 == p2.y

View file

@ -0,0 +1,19 @@
// Explicit coersion from list with "as" keyword
def p4 = [36, -2] as Point
assert 36 == p4.x
assert -2 == p4.y
// Explicit coersion from list with Java/C-style casting
p4 = (Point) [36, -2]
println p4
assert 36 == p4.x
assert -2 == p4.y
// Implicit coercion from list (by type of variable)
Point p6 = [36, -2]
assert 36 == p6.x
assert -2 == p6.y
Point p8 = [36]
assert 36 == p8.x
assert 0 == p8.y

View file

@ -0,0 +1,31 @@
// Direct map-based construction
def p3 = new Point([x: 36, y: -2])
assert 36 == p3.x
assert -2 == p3.y
// Direct map-entry-based construction
p3 = new Point(x: 36, y: -2)
assert 36 == p3.x
assert -2 == p3.y
p3 = new Point(x: 36)
assert 36 == p3.x
assert 0 == p3.y
p3 = new Point(y: -2)
assert 0 == p3.x
assert -2 == p3.y
// Explicit coercion from map with "as" keyword
def p5 = [x: 36, y: -2] as Point
assert 36 == p5.x
assert -2 == p5.y
// Implicit coercion from map (by type of variable)
Point p7 = [x: 36, y: -2]
assert 36 == p7.x
assert -2 == p7.y
Point p9 = [y:-2]
assert 0 == p9.x
assert -2 == p9.y

View file

@ -0,0 +1,4 @@
point = {x: 6 , y: 0 }
point.y = 7
print, point
;=> { 6 7}

View file

@ -0,0 +1 @@
record Point(x,y)

View file

@ -0,0 +1,17 @@
NB. Create a "Point" class
coclass'Point'
NB. Define its constuctor
create =: 3 : 0
'X Y' =: y
)
NB. Instantiate an instance (i.e. an object)
cocurrent 'base'
P =: 10 20 conew 'Point'
NB. Interrogate its members
X__P
10
Y__P
20

View file

@ -0,0 +1,5 @@
Var:Create(
Point,
Number x,
Number y
)

View file

@ -0,0 +1,3 @@
function main() {
Var:Point point;
}

View file

@ -0,0 +1,2 @@
setpos [100 100] setpos [100 0] setpos [0 0]
show pos ; [0 0]

View file

@ -0,0 +1 @@
until [(first mousepos) < 0] [ifelse button? [pendown] [penup] setpos mousepos]

View file

@ -0,0 +1,2 @@
struct myPoint (x, y)
newPoint = myPoint x:3 y:4

View file

@ -0,0 +1 @@
newPoint = Point2 3 4

View file

@ -0,0 +1,11 @@
In[1]:= a = point[2, 3]
Out[1]= point[2, 3]
In[2]:= a[[2]]
Out[2]= 3
In[3]:= a[[2]] = 4; a
Out[3]= point[2, 4]

View file

@ -0,0 +1 @@
p[x] = 2; p[y] = 3;

View file

@ -0,0 +1,7 @@
defstruct(point(x, y))$
p: new(point)$
q: point(1, 2)$
p@x: 5$

View file

@ -0,0 +1,3 @@
TYPE Point = RECORD
x, y : INTEGER
END;

View file

@ -0,0 +1,4 @@
VAR point : Point;
...
point.x := 12;
point.y := 7;

View file

@ -0,0 +1,3 @@
TYPE Point = RECORD
x, y: INTEGER;
END;