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,10 @@
begin
% create the compound data type %
record Point( real x, y );
% declare a Point variable %
reference(Point) p;
% assign a value to p %
p := Point( 1, 0.5 );
% access the fields of p - note Algol W uses x(p) where many languages would use p.x %
write( x(p), y(p) )
end.

View file

@ -0,0 +1,27 @@
--Compound Data type can hold multiple independent values
--In Elm data can be compounded using List, Tuple, Record
--In a List
point = [2,5]
--This creates a list having x and y which are independent and can be accessed by List functions
--Note that x and y must be of same data type
--Tuple is another useful data type that stores different independent values
point = (3,4)
--Here we can have multiple data types
point1 = ("x","y")
point2 = (3,4.5)
--The order of addressing matters
--Using a Record is the best option
point = {x=3,y=4}
--To access
point.x
point.y
--Or Use it as a function
.x point
.y point
--Also to alter the value
{point | x=7}
{point | y=2}
{point | x=3,y=4}
--Each time a new record is generated
--END

View file

@ -0,0 +1,9 @@
data class Point(var x: Int, var y: Int)
fun main(args: Array<String>) {
val p = Point(1, 2)
println(p)
p.x = 3
p.y = 4
println(p)
}

View file

@ -0,0 +1,20 @@
MODULE Point;
TYPE
Object* = POINTER TO ObjectDesc;
ObjectDesc* = RECORD
x-,y-: INTEGER;
END;
PROCEDURE (p: Object) Init(x,y: INTEGER);
BEGIN
p.x := x; p.y := y
END Init;
PROCEDURE New*(x,y: INTEGER): Object;
VAR
p: Object;
BEGIN
NEW(p);p.Init(x,y);RETURN p;
END New;
END Point.

View file

@ -0,0 +1,11 @@
p = .point~new(3,4)
say "x =" p~x
say "y =" p~y
::class point
::method init
expose x y
use strict arg x = 0, y = 0 -- defaults to 0 for any non-specified coordinates
::attribute x
::attribute y

View file

@ -1 +1,3 @@
my @point = 3, 8;
my Int @point = 3, 8; # or constrain to integer elements

View file

@ -1 +1,3 @@
my %point = x => 3, y => 8;
my Int %point = x => 3, y => 8; # or constrain the hash to have integer values

View file

@ -1,4 +0,0 @@
Structure MyPoint
X.i
Y.i
EndStructure

View file

@ -1,7 +0,0 @@
Structure MyFileDate
name.s
StructureUnion
Date_as_txt.s
Date_in_Ticks.l
EndStructureUnion
EndStructure

View file

@ -0,0 +1,16 @@
mata
struct Point {
real scalar x, y
}
// dumb example
function test() {
struct Point scalar a
a.x = 10
a.y = 20
printf("%f\n",a.x+a.y)
}
test()
30
end

View file

@ -0,0 +1,7 @@
class Point{ var x,y;
fcn init(x,y){self.x=x.toFloat(); self.y=y.toFloat(); }
fcn toString{ "P(%f,%f)".fmt(x,y) }
fcn __opADD(P){} //+: add Point, constant or whatever
//... __opEQ == etc
}
Point(1,2).println() //-->P(1.000000,2.000000)

View file

@ -0,0 +1 @@
point:=T(1,2); points:=T( T(1,2), L(3,4) )