i all the A langs
This commit is contained in:
parent
86c034bb8b
commit
9246b988c7
245 changed files with 3941 additions and 0 deletions
82
Task/Classes/ALGOL-68/classes.alg
Normal file
82
Task/Classes/ALGOL-68/classes.alg
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
MODE MYDATA = STRUCT(
|
||||
INT name1
|
||||
);
|
||||
STRUCT(
|
||||
INT name2,
|
||||
PROC (REF MYDATA)REF MYDATA new,
|
||||
PROC (REF MYDATA)VOID init,
|
||||
PROC (REF MYDATA)VOID some method
|
||||
) class my data;
|
||||
class my data := (
|
||||
# name2 := # 2, # Class attribute #
|
||||
|
||||
# PROC new := # (REF MYDATA new)REF MYDATA:(
|
||||
(init OF class my data)(new);
|
||||
new
|
||||
),
|
||||
|
||||
# PROC init := # (REF MYDATA self)VOID:(
|
||||
""" Constructor (Technically an initializer rather than a true 'constructor') """;
|
||||
name1 OF self := 0 # Instance attribute #
|
||||
),
|
||||
|
||||
# PROC some method := # (REF MYDATA self)VOID:(
|
||||
""" Method """;
|
||||
name1 OF self := 1;
|
||||
name2 OF class my data := 3
|
||||
)
|
||||
);
|
||||
|
||||
# class name, invoked as a function is the constructor syntax #
|
||||
REF MYDATA my data = (new OF class my data)(LOC MYDATA);
|
||||
|
||||
MODE GENDEROPT = UNION(STRING, VOID);
|
||||
MODE AGEOPT = UNION(INT, VOID);
|
||||
|
||||
MODE MYOTHERDATA = STRUCT(
|
||||
STRING name,
|
||||
GENDEROPT gender,
|
||||
AGEOPT age
|
||||
);
|
||||
STRUCT (
|
||||
INT count,
|
||||
PROC (REF MYOTHERDATA, STRING, GENDEROPT, AGEOPT)REF MYOTHERDATA new,
|
||||
PROC (REF MYOTHERDATA, STRING, GENDEROPT, AGEOPT)VOID init,
|
||||
PROC (REF MYOTHERDATA)VOID del
|
||||
) class my other data;
|
||||
class my other data := (
|
||||
# count := # 0, # Population of "(init OF class my other data)" objects #
|
||||
# PROC new := # (REF MYOTHERDATA new, STRING name, GENDEROPT gender, AGEOPT age)REF MYOTHERDATA:(
|
||||
(init OF class my other data)(new, name, gender, age);
|
||||
new
|
||||
),
|
||||
|
||||
# PROC init := # (REF MYOTHERDATA self, STRING name, GENDEROPT gender, AGEOPT age)VOID:(
|
||||
""" One initializer required, others are optional (with different defaults) """;
|
||||
count OF class my other data +:= 1;
|
||||
name OF self := name;
|
||||
gender OF self := gender;
|
||||
CASE gender OF self IN
|
||||
(VOID):gender OF self := "Male"
|
||||
ESAC;
|
||||
age OF self := age
|
||||
),
|
||||
|
||||
# PROC del := # (REF MYOTHERDATA self)VOID:(
|
||||
count OF class my other data -:= 1
|
||||
)
|
||||
);
|
||||
|
||||
PROC attribute error := STRING: error char; # mend the error with the "error char" #
|
||||
|
||||
# Allocate the instance from HEAP #
|
||||
REF MYOTHERDATA person1 = (new OF class my other data)(HEAP MYOTHERDATA, "John", EMPTY, EMPTY);
|
||||
print (((name OF person1), ": ",
|
||||
(gender OF person1|(STRING gender):gender|attribute error), " ")); # "John Male" #
|
||||
print (((age OF person1|(INT age):age|attribute error), new line)); # Raises AttributeError exception! #
|
||||
|
||||
# Allocate the instance from LOC (stack) #
|
||||
REF MYOTHERDATA person2 = (new OF class my other data)(LOC MYOTHERDATA, "Jane", "Female", 23);
|
||||
print (((name OF person2), ": ",
|
||||
(gender OF person2|(STRING gender):gender|attribute error), " "));
|
||||
print (((age OF person2|(INT age):age|attribute error), new line)) # "Jane Female 23" #
|
||||
7
Task/Classes/Aikido/classes.aikido
Normal file
7
Task/Classes/Aikido/classes.aikido
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
class Circle (radius, x, y) extends Shape (x, y) implements Drawable {
|
||||
var myvec = new Vector (x, y)
|
||||
|
||||
public function draw() {
|
||||
// draw the circle
|
||||
}
|
||||
}
|
||||
27
Task/Classes/AmigaE/classes.amiga
Normal file
27
Task/Classes/AmigaE/classes.amiga
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
OBJECT a_class
|
||||
varA, varP
|
||||
ENDOBJECT
|
||||
|
||||
-> this could be used like a constructor
|
||||
PROC init() OF a_class
|
||||
self.varP := 10
|
||||
self.varA := 2
|
||||
ENDPROC
|
||||
|
||||
-> the special proc end() is for destructor
|
||||
PROC end() OF a_class
|
||||
-> nothing to do here...
|
||||
ENDPROC
|
||||
|
||||
-> a not so useful getter
|
||||
PROC getP() OF a_class IS self.varP
|
||||
|
||||
PROC main()
|
||||
DEF obj : PTR TO a_class
|
||||
NEW obj.init()
|
||||
WriteF('\d\n', obj.varA) -> this can be done, while
|
||||
-> varP can't be accessed directly
|
||||
WriteF('\d\n', obj.varP) -> or
|
||||
WriteF('\d\n', obj.getP())
|
||||
END obj
|
||||
ENDPROC
|
||||
19
Task/Classes/AutoHotkey/classes.ahk
Normal file
19
Task/Classes/AutoHotkey/classes.ahk
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
obj := new MyClass
|
||||
obj.WhenCreated()
|
||||
|
||||
class MyClass {
|
||||
; Instance Variable #1
|
||||
time := A_Hour ":" A_Min ":" A_Sec
|
||||
|
||||
; Constructor
|
||||
__New() {
|
||||
MsgBox, % "Constructing new object of type: " this.__Class
|
||||
FormatTime, date, , MM/dd/yyyy
|
||||
; Instance Variable #2
|
||||
this.date := date
|
||||
}
|
||||
; Method
|
||||
WhenCreated() {
|
||||
MsgBox, % "Object created at " this.time " on " this.date
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue