langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -0,0 +1,4 @@
class animal =
object (self)
(*functions go here...*)
end

View file

@ -0,0 +1,5 @@
class dog =
object (self)
inherit animal
(*functions go here...*)
end

View file

@ -0,0 +1,5 @@
class cat =
object (self)
inherit animal
(*functions go here...*)
end

View file

@ -0,0 +1,5 @@
class lab =
object (self)
inherit dog
(*functions go here...*)
end

View file

@ -0,0 +1,5 @@
class collie =
object (self)
inherit dog
(*functions go here...*)
end

View file

@ -0,0 +1,14 @@
class Animal
{ #~ ... ~# }
class Dog from Animal
{ #~ ... ~# }
class Lab from Dog
{ #~ ... ~# }
class Collie from Dog
{ #~ ... ~# }
class Cat from Animal
{ #~ ... ~# }

View file

@ -0,0 +1,34 @@
@interface Animal : NSObject
{
// ...
}
// ...
@end
@interface Dog : Animal
{
// ...
}
// ...
@end
@interface Lab : Dog
{
// ...
}
// ...
@end
@interface Collie : Dog
{
// ...
}
// ...
@end
@interface Cat : Animal
{
// ...
}
// ...
@end

View file

@ -0,0 +1,37 @@
class animal
method show() as string
return "Animal "
end method
end Class
class dog
from Animal Animal
method show() as string
return animal.show()+"dog "
end method
end Class
class cat
from animal animal
method show() as string
return animal.show()+"cat "
end method
end Class
class Lab
from dog dog
method show() as string
return dog.show()+"Lab "
end method
end Class
class Collie
from dog dog
method show() as string
return dog.show()+"Collie "
end method
end Class
Collie c
print c.show 'result: Animal Dog Collie

View file

@ -0,0 +1,19 @@
class Animal
%% ...
end
class Dog from Animal
%% ...
end
class Lab from Dog
%% ...
end
class Collie from Dog
%% ...
end
class Cat from Animal
%% ...
end

View file

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

View file

@ -0,0 +1,21 @@
Interface Animal
Eat()
Sleep()
EndInterface
Interface Cat Extends Animal
ChaseMouse()
EndInterface
Interface Dog Extends Animal
Bark()
WagTail()
EndInterface
Interface Lab Extends Dog
Swim()
EndInterface
Interface Collie Extends Dog
HeardSheep()
EndInterface

View file

@ -0,0 +1,27 @@
Class Animal
EndClass
Class Dog Extends Animal
Public Method Bark()
EndMethod
EndClass
Class Cat Extends Animal
Public Method Sleep()
EndMethod
EndClass
Class Lab Extends Dog
Public Method Swim()
EndMethod
EndClass
Class Collie Extends Dog
Public Method Fetch()
EndMethod
EndClass
;- test the code
*Lassie.Collie = NewObject.Collie
*Lassie\Bark()
*Lassie\Fetch()

View file

@ -0,0 +1,28 @@
REBOL [
Title: "Inheritance"
Author: oofoe
Date: 2009-12-08
URL: http://rosettacode.org/wiki/Inheritance
]
; REBOL provides subclassing through its prototype mechanism:
Animal: make object! [
legs: 4
]
Dog: make Animal [
says: "Woof!"
]
Cat: make Animal [
says: "Meow..."
]
Lab: make Dog []
Collie: make Dog []
; Demonstrate inherited properties:
print ["Cat has" Cat/legs "legs."]
print ["Lab says:" Lab/says]

View file

@ -0,0 +1,5 @@
define: #Animal &parents: {Cloneable}.
define: #Dog &parents: {Animal}.
define: #Cat &parents: {Animal}.
define: #Lab &parents: {Dog}.
define: #Collie &parents: {Dog}.

View file

@ -0,0 +1,3 @@
@(defex cat animal)
@(defex lab dog animal)
@(defex collie dog)

View file

@ -0,0 +1,4 @@
@(try)
@ (throw lab "x")
@(catch animal (arg))
@(end)

View file

@ -0,0 +1,23 @@
Class Animal
' ...
End Class
Class Dog
Inherits Animal
' ...
End Class
Class Lab
Inherits Dog
' ...
End Class
Class Collie
Inherits Dog
' ...
End Class
Class Cat
Inherits Animal
' ...
End Class

View file

@ -0,0 +1,5 @@
pet = new()
cat = new(pet)
dog = new(pet)
fido = new(dog)
felix = new(cat)