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,72 @@
/* NetRexx */
options replace format comments java crossref savelog symbols binary
-- -----------------------------------------------------------------------------
class RCAbstractType public final
method main(args = String[]) public constant
say ' Testing' RCAbstractType.class.getSimpleName
say ' Creating an object of type:' Concrete.class.getSimpleName
conk = Concrete()
say 'getClassName:'.right(20) conk.getClassName
say 'getIfaceName:'.right(20) conk.getIfaceName
say 'mustImplement:'.right(20) conk.mustImplement
say 'canOverride1:'.right(20) conk.canOverride1
say 'canOverride2:'.right(20) conk.canOverride2
say 'callOverridden2:'.right(20) conk.callOverridden2
return
-- -----------------------------------------------------------------------------
class RCAbstractType.Iface interface
ifaceName = RCAbstractType.Iface.class.getSimpleName
method getIfaceName() public returns String
method canOverride1() public returns String
method canOverride2() public returns String
-- -----------------------------------------------------------------------------
class RCAbstractType.Abstraction abstract implements RCAbstractType.Iface
properties inheritable
className = String
method Abstraction() public
setClassName(this.getClass.getSimpleName)
return
method mustImplement() public abstract returns String
method getClassName() public returns String
return className
method setClassName(nm = String) public
className = nm
return
method getIfaceName() public returns String
return RCAbstractType.Iface.ifaceName
method canOverride1() public returns String
return 'In' RCAbstractType.Abstraction.class.getSimpleName'.canOverride1'
method canOverride2() public returns String
return 'In' RCAbstractType.Abstraction.class.getSimpleName'.canOverride2'
-- -----------------------------------------------------------------------------
class RCAbstractType.Concrete extends RCAbstractType.Abstraction
method Concrete() public
super()
return
method mustImplement() public returns String
return 'In' RCAbstractType.Concrete.class.getSimpleName'.mustImplement'
method canOverride2() public returns String
return 'In' RCAbstractType.Concrete.class.getSimpleName'.canOverride2'
method callOverridden2() public returns String
return super.canOverride2

View file

@ -0,0 +1,46 @@
; file: abstract.lsp
; url: http://rosettacode.org/wiki/Abstract_type
; author: oofoe 2012-01-28
; Abstract Shape Class
(new Class 'Shape) ; Derive new class.
(define (Shape:Shape ; Shape constructor.
(pen "X")) ; Default value.
(list (context) ; Assemble data packet.
(list 'pen pen)
(list 'size (args))))
(define (Shape:line x) ; Print out row with 'pen' character.
(dotimes (i x)
(print (lookup 'pen (self))))
(println))
(define (Shape:draw)) ; Placeholder, does nothing.
; Derived Objects
(new Shape 'Box)
(define (Box:draw) ; Override base draw method.
(let ((s (lookup 'size (self))))
(dotimes (i (s 0)) (:line (self) (s 0)))))
(new Shape 'Rectangle)
(define (Rectangle:draw)
(let ((size (lookup 'size (self))))
(dotimes (i (size 1)) (:line (self) (size 0)))))
; Demonstration
(:draw (Shape)) ; Nothing happens.
(println "A box:")
(:draw (Box "O" 5)) ; Create Box object and call draw method.
(println "\nA rectangle:")
(:draw (Rectangle "R" 32 4))
(exit)

View file

@ -0,0 +1,4 @@
class virtual foo =
object
method virtual bar : int
end

View file

@ -0,0 +1 @@
type t

View file

@ -0,0 +1,5 @@
module Foo : sig
type t
end = struct
type t = int * int
end

View file

@ -0,0 +1,5 @@
type u
type v
type 'a t
type ut = u t
type vt = v t

View file

@ -0,0 +1,7 @@
class ClassA {
method : virtual : public : MethodA() ~ Int;
method : public : MethodA() ~ Int {
return 0;
}
}

View file

@ -0,0 +1,23 @@
declare
class BaseQueue
attr
contents:nil
meth init
raise notImplemented(self init) end
end
meth enqueue(Item)
raise notImplemented(self enqueue) end
end
meth dequeue(?Item)
raise notImplemented(self dequeue) end
end
meth printContents
{ForAll @contents Show}
end
end
Queue = {New BaseQueue init} %% throws

View file

@ -0,0 +1,23 @@
use v6;
role A {
# must be filled in by the class it is composed into
method abstract() { ... };
# can be overridden in the class, but that's not mandatory
method concrete() { say '# 42' };
}
class SomeClass does A {
method abstract() {
say "# made concrete in class"
}
}
my $obj = SomeClass.new;
$obj.abstract();
$obj.concrete();
# output:
# made concrete in class
# 42

View file

@ -0,0 +1,46 @@
REBOL [
Title: "Abstract Type"
Author: oofoe
Date: 2009-12-05
URL: http://rosettacode.org/wiki/Abstract_type
]
; The "shape" class is an abstract class -- it defines the "pen"
; property and "line" method, but "size" and "draw" are undefined and
; unimplemented.
shape: make object! [
pen: "X"
size: none
line: func [count][loop count [prin self/pen] prin crlf]
draw: does [none]
]
; The "box" class inherits from "shape" and provides the missing
; information for drawing boxes.
box: make shape [
size: 10
draw: does [loop self/size [line self/size]]
]
; "rectangle" also inherits from "shape", but handles the
; implementation very differently.
rectangle: make shape [
size: 20x10
draw: does [loop self/size/y [line self/size/x]]
]
; Unlike some languages discussed, REBOL has absolutely no qualms
; about instantiating an "abstract" class -- that's how I created the
; derived classes of "rectangle" and "box", after all.
s: make shape [] s/draw ; Nothing happens.
print "A box:"
b: make box [pen: "O" size: 5] b/draw
print [crlf "A rectangle:"]
r: make rectangle [size: 32x5] r/draw

View file

@ -0,0 +1,17 @@
MustInherit Class Base
Protected Sub New()
End Sub
Public Sub StandardMethod()
'code
End Sub
Public Overridable Sub Method_Can_Be_Replaced()
'code
End Sub
Public MustOverride Sub Method_Must_Be_Replaced()
End Class

View file

@ -0,0 +1,3 @@
Interface IBase
Sub Method_Must_Be_Implemented()
End Interface