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

@ -0,0 +1,14 @@
OBJECT animal
ENDOBJECT
OBJECT dog OF animal
ENDOBJECT
OBJECT cat OF animal
ENDOBJECT
OBJECT lab OF dog
ENDOBJECT
OBJECT collie OF dog
ENDOBJECT

View file

@ -0,0 +1,7 @@
include FMS-SI.f
:class Animal ;class
:class Dog <super Animal ;class
:class Cat <super Animal ;class
:class Lab <super Dog ;class
:class Collie <super Dog ;class

View file

@ -0,0 +1,13 @@
var Animal = $new(null);
var Dog = $new(null);
$objsetproto(Dog, Animal);
var Cat = $new(null);
$objsetproto(Cat, Animal);
var Lab = $new(null);
$objsetproto(Lab, Dog);
var Collie = $new(null);
$objsetproto(Collie, Dog);

View file

@ -4,5 +4,5 @@ class Cat is Animal {}
class Lab is Dog {}
class Collie is Dog {}
say ~Collie.^parents; # undefined type object
say ~Collie.new.^parents; # instantiated object
say Collie.^parents; # undefined type object
say Collie.new.^parents; # instantiated object

View file

@ -0,0 +1 @@
animal = ()

View file

@ -0,0 +1 @@
dog = (| parent* = animal |)

View file

@ -0,0 +1 @@
cat = (| parent* = animal |)

View file

@ -0,0 +1 @@
lab = (| parent* = dog |)

View file

@ -0,0 +1 @@
collie = (| parent* = dog |)

View file

@ -0,0 +1,23 @@
(defstruct animal nil
name
(:method get-name (me)
(if me.name me.name (error `get-name: animal @me has no name`)))
(:method speak (me stream)
(error "abstract animal cannot speak")))
(defstruct dog animal
(:method speak (me : (stream *stdout*))
(put-line `@{me.(get-name)}: bark!` stream)))
(defstruct cat animal
(:method speak (me : (stream *stdout*))
(put-line `@{me.(get-name)}: meow!` stream)))
(defstruct lab dog)
(defstruct collie dog)
(let ((pet1 (new collie name "Lassie"))
(pet2 (new cat name "Max")))
pet1.(speak)
pet2.(speak))