From f418f51ef28b7d357140b477af2db8b3b6854eb1 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 17 Jun 2017 21:48:38 -0400 Subject: - Implemented functional object-oriented programming. --- stdlib/test/test/lux/paradigm/object.lux | 48 ++++++++++++++++++++++++++++++++ stdlib/test/tests.lux | 1 + 2 files changed, 49 insertions(+) create mode 100644 stdlib/test/test/lux/paradigm/object.lux (limited to 'stdlib/test') 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] -- cgit v1.2.3