Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -6,7 +6,9 @@ PROC main()
DEF pt:PTR TO point,
NEW pt
pt.x := 10.4
pt.y := 3.14
-> Floats are also stored as integer types making
-> the float conversion operator necessary.
pt.x := !10.4
pt.y := !3.14
END pt
ENDPROC

View file

@ -1 +1,18 @@
//using object literal syntax
var point = {x : 1, y : 2};
//using constructor
var Point = function (x, y) {
this.x = x;
this.y = y;
};
point = new Point(1, 2);
//using ES6 class syntax
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
}
point = new Point(1, 2);

View file

@ -0,0 +1,4 @@
type Point{T<:Real}
x::T
y::T
end

View file

@ -0,0 +1,4 @@
==(u::Point, v::Point) = (u.x == v.x) & (u.y == v.y)
-(u::Point) = Point(-u.x, -u.y)
+(u::Point, v::Point) = Point(u.x + v.x, u.y + v.y)
-(u::Point, v::Point) = Point(u.x - v.x, u.y - v.y)

View file

@ -0,0 +1,14 @@
a = Point(1, 2)
b = Point(3, 7)
c = Point(2, 4)
println("a = ", a)
println("b = ", b)
println("c = ", c)
println("a + b = ", a+b)
println("-a + b = ", -a+b)
println("a - b = ", a-b)
println("a + b + c = ", a+b+c)
println("a == c ", a == c)
println("a + a == c ", a + a == c)

View file

@ -0,0 +1,4 @@
my $s1 = set <a b c d>; # order is not preserved
my $s2 = set <c d e f>;
say $s1 (&) $s2; # OUTPUT«set(c, e)»
say $s1 $s2; # we also do Unicode

View file

@ -0,0 +1 @@
(defstruct point nil (x 0) (y 0))

View file

@ -0,0 +1 @@
(defstruct point nil x y)

View file

@ -0,0 +1,3 @@
(new point) ;; -> #S(point x 0 y 0)
(new point x 1) ;; -> #S(point x 1 y 0)
(new point x 1 y 1) ;; -> #S(point x 1 y 1)

View file

@ -0,0 +1 @@
(defstruct (point x y) nil (x 0) (y 0))

View file

@ -0,0 +1 @@
(new (point 3 4)) -> #S(point x 3 y 4)

View file

@ -0,0 +1,3 @@
(defun displace-point-destructively (p delta)
(inc p.x delta.x)
(inc p.y delta.y))