aboutsummaryrefslogtreecommitdiff
path: root/stdlib/test
diff options
context:
space:
mode:
authorEduardo Julian2017-06-17 21:48:38 -0400
committerEduardo Julian2017-06-17 21:48:38 -0400
commitf418f51ef28b7d357140b477af2db8b3b6854eb1 (patch)
treeef74fcf24fc537f07daba4b7443e48373e4a0750 /stdlib/test
parente65917e3fe1b5794a2643058f15c7aeb5ca1a0fa (diff)
- Implemented functional object-oriented programming.
Diffstat (limited to 'stdlib/test')
-rw-r--r--stdlib/test/test/lux/paradigm/object.lux48
-rw-r--r--stdlib/test/tests.lux1
2 files changed, 49 insertions, 0 deletions
diff --git a/stdlib/test/test/lux/paradigm/object.lux b/stdlib/test/test/lux/paradigm/object.lux
new file mode 100644
index 000000000..0171ab41f
--- /dev/null
+++ b/stdlib/test/test/lux/paradigm/object.lux
@@ -0,0 +1,48 @@
+(;module:
+ lux
+ (lux (data (coll [list]))
+ (paradigm object)))
+
+(interface: (Queue a)
+ (push [a] @)
+ (peek [] (Maybe a))
+ (pop [] @)
+ (size [] Nat))
+
+(class: (List-Queue a) (Queue a)
+ (List a)
+
+ (def: (push a)
+ (update! (|>. (#;Cons a))))
+
+ (def: peek
+ (|>. get! list;head))
+
+ (def: pop
+ (update! (function [state] (|> state list;tail (default state)))))
+
+ (def: size
+ (|>. get! list;size)))
+
+(type: Coord [Real Real])
+(type: Angle Real)
+
+(interface: Geometry
+ (translate [Coord] @)
+ (rotate [Coord Angle] @)
+ (scale [Real Real] @))
+
+(class: Point Geometry
+ {#label Text
+ #coord Coord}
+ (def: (translate coord self) self)
+ (def: (rotate coord angle self) self)
+ (def: (scale width height self) self))
+
+(def: queue0 (|> (new-List-Queue (list))
+ (: (Queue Nat))
+ (push +123)
+ (push +456)
+ (push +789)
+ pop))
+(def: point0 (new-Point ["YOLO" [123.4 567.8]]))
diff --git a/stdlib/test/tests.lux b/stdlib/test/tests.lux
index b55373330..0a609ce13 100644
--- a/stdlib/test/tests.lux
+++ b/stdlib/test/tests.lux
@@ -67,6 +67,7 @@
["_;" type]
(type ["_;" check]
["_;" auto])
+ (paradigm ["_;" object])
))
(lux (control [contract])
(data [env]