A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
1
Task/Compound-data-type/Factor/compound-data-type.factor
Normal file
1
Task/Compound-data-type/Factor/compound-data-type.factor
Normal file
|
|
@ -0,0 +1 @@
|
|||
TUPLE: point x y ;
|
||||
20
Task/Compound-data-type/Fantom/compound-data-type.fantom
Normal file
20
Task/Compound-data-type/Fantom/compound-data-type.fantom
Normal 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 + ")")
|
||||
}
|
||||
}
|
||||
|
|
@ -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}}" }
|
||||
}
|
||||
17
Task/Compound-data-type/Groovy/compound-data-type-2.groovy
Normal file
17
Task/Compound-data-type/Groovy/compound-data-type-2.groovy
Normal 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
|
||||
19
Task/Compound-data-type/Groovy/compound-data-type-3.groovy
Normal file
19
Task/Compound-data-type/Groovy/compound-data-type-3.groovy
Normal 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
|
||||
31
Task/Compound-data-type/Groovy/compound-data-type-4.groovy
Normal file
31
Task/Compound-data-type/Groovy/compound-data-type-4.groovy
Normal 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
|
||||
4
Task/Compound-data-type/IDL/compound-data-type.idl
Normal file
4
Task/Compound-data-type/IDL/compound-data-type.idl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
point = {x: 6 , y: 0 }
|
||||
point.y = 7
|
||||
print, point
|
||||
;=> { 6 7}
|
||||
1
Task/Compound-data-type/Icon/compound-data-type.icon
Normal file
1
Task/Compound-data-type/Icon/compound-data-type.icon
Normal file
|
|
@ -0,0 +1 @@
|
|||
record Point(x,y)
|
||||
17
Task/Compound-data-type/J/compound-data-type.j
Normal file
17
Task/Compound-data-type/J/compound-data-type.j
Normal 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
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
Var:Create(
|
||||
Point,
|
||||
Number x,
|
||||
Number y
|
||||
)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
function main() {
|
||||
Var:Point point;
|
||||
}
|
||||
2
Task/Compound-data-type/Logo/compound-data-type-1.logo
Normal file
2
Task/Compound-data-type/Logo/compound-data-type-1.logo
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
setpos [100 100] setpos [100 0] setpos [0 0]
|
||||
show pos ; [0 0]
|
||||
1
Task/Compound-data-type/Logo/compound-data-type-2.logo
Normal file
1
Task/Compound-data-type/Logo/compound-data-type-2.logo
Normal file
|
|
@ -0,0 +1 @@
|
|||
until [(first mousepos) < 0] [ifelse button? [pendown] [penup] setpos mousepos]
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
struct myPoint (x, y)
|
||||
newPoint = myPoint x:3 y:4
|
||||
|
|
@ -0,0 +1 @@
|
|||
newPoint = Point2 3 4
|
||||
|
|
@ -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]
|
||||
|
|
@ -0,0 +1 @@
|
|||
p[x] = 2; p[y] = 3;
|
||||
7
Task/Compound-data-type/Maxima/compound-data-type.maxima
Normal file
7
Task/Compound-data-type/Maxima/compound-data-type.maxima
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
defstruct(point(x, y))$
|
||||
|
||||
p: new(point)$
|
||||
|
||||
q: point(1, 2)$
|
||||
|
||||
p@x: 5$
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
TYPE Point = RECORD
|
||||
x, y : INTEGER
|
||||
END;
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
VAR point : Point;
|
||||
...
|
||||
point.x := 12;
|
||||
point.y := 7;
|
||||
3
Task/Compound-data-type/Modula-3/compound-data-type.mod3
Normal file
3
Task/Compound-data-type/Modula-3/compound-data-type.mod3
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
TYPE Point = RECORD
|
||||
x, y: INTEGER;
|
||||
END;
|
||||
Loading…
Add table
Add a link
Reference in a new issue