A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
8
Task/Classes/Factor/classes.factor
Normal file
8
Task/Classes/Factor/classes.factor
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
TUPLE: my-class foo bar baz ;
|
||||
M: my-class quux foo>> 20 + ;
|
||||
C: <my-class> my-class
|
||||
10 20 30 <my-class> quux ! result: 30
|
||||
TUPLE: my-child-class < my-class quxx ;
|
||||
C: <my-child-class> my-child-class
|
||||
M: my-child-class foobar 20 >>quux ;
|
||||
20 20 30 <my-child-class> foobar quux ! result: 30
|
||||
6
Task/Classes/Falcon/classes-1.falcon
Normal file
6
Task/Classes/Falcon/classes-1.falcon
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
class class_name[ ( param_list ) ] [ from inh1[, inh2, ..., inhN] ]
|
||||
[ static block ]
|
||||
[ properties declaration ]
|
||||
[init block]
|
||||
[method list]
|
||||
end
|
||||
15
Task/Classes/Falcon/classes-2.falcon
Normal file
15
Task/Classes/Falcon/classes-2.falcon
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
class mailbox( max_msg )
|
||||
|
||||
capacity = max_msg * 10
|
||||
name = nil
|
||||
messages = []
|
||||
|
||||
init
|
||||
printl( "Box now ready for ", self.capacity, " messages." )
|
||||
end
|
||||
|
||||
function slot_left()
|
||||
return self.capacity - len( self.messages )
|
||||
end
|
||||
|
||||
end
|
||||
2
Task/Classes/Falcon/classes-3.falcon
Normal file
2
Task/Classes/Falcon/classes-3.falcon
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
m = mailbox( 10 )
|
||||
// Ouputs: Box now ready for 100 messages.
|
||||
26
Task/Classes/Fancy/classes.fancy
Normal file
26
Task/Classes/Fancy/classes.fancy
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
class MyClass {
|
||||
read_slot: 'instance_var # creates getter method for @instance_var
|
||||
@@class_var = []
|
||||
|
||||
def initialize {
|
||||
# 'initialize' is the constructor method invoked during 'MyClass.new' by convention
|
||||
@instance_var = 0
|
||||
}
|
||||
|
||||
def some_method {
|
||||
@instance_var = 1
|
||||
@another_instance_var = "foo"
|
||||
}
|
||||
|
||||
# define class methods: define a singleton method on the class object
|
||||
def self class_method {
|
||||
# ...
|
||||
}
|
||||
|
||||
# you can also name the class object itself
|
||||
def MyClass class_method {
|
||||
# ...
|
||||
}
|
||||
}
|
||||
|
||||
myclass = MyClass new
|
||||
27
Task/Classes/Fantom/classes.fantom
Normal file
27
Task/Classes/Fantom/classes.fantom
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
class MyClass
|
||||
{
|
||||
// an instance variable
|
||||
Int x
|
||||
|
||||
// a constructor, providing default value for instance variable
|
||||
new make (Int x := 1)
|
||||
{
|
||||
this.x = x
|
||||
}
|
||||
|
||||
// a method, return double the number x
|
||||
public Int double ()
|
||||
{
|
||||
return 2 * x
|
||||
}
|
||||
}
|
||||
|
||||
class Main
|
||||
{
|
||||
public static Void main ()
|
||||
{
|
||||
a := MyClass (2) // instantiates the class, with x = 2
|
||||
b := MyClass() // instantiates the class, x defaults to 1
|
||||
c := MyClass { x = 3 } // instantiates the class, sets x to 3
|
||||
}
|
||||
}
|
||||
15
Task/Classes/Groovy/classes-1.groovy
Normal file
15
Task/Classes/Groovy/classes-1.groovy
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
/** Ye olde classe declaration */
|
||||
class Stuff {
|
||||
/** Heare bee anne instance variable declared */
|
||||
def guts
|
||||
|
||||
/** This constuctor converts bits into Stuff */
|
||||
Stuff(injectedGuts) {
|
||||
guts = injectedGuts
|
||||
}
|
||||
|
||||
/** Brethren and sistren, let us flangulate with this fine flangulating method */
|
||||
def flangulate() {
|
||||
println "This stuff is flangulating its guts: ${guts}"
|
||||
}
|
||||
}
|
||||
16
Task/Classes/Groovy/classes-2.groovy
Normal file
16
Task/Classes/Groovy/classes-2.groovy
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
def stuff = new Stuff('''
|
||||
I have made mistakes in the past.
|
||||
I have made mistakes in the future.
|
||||
-- Vice President Dan Quayle
|
||||
''')
|
||||
|
||||
stuff.flangulate()
|
||||
|
||||
stuff.guts = '''
|
||||
Our enemies are innovative and resourceful, and so are we.
|
||||
They never stop thinking about new ways to harm our country and our people,
|
||||
and neither do we.
|
||||
-- President George W. Bush
|
||||
'''
|
||||
|
||||
stuff.flangulate()
|
||||
11
Task/Classes/J/classes-1.j
Normal file
11
Task/Classes/J/classes-1.j
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
coclass 'exampleClass'
|
||||
|
||||
exampleMethod=: monad define
|
||||
1+exampleInstanceVariable
|
||||
)
|
||||
|
||||
create=: monad define
|
||||
'this is the constructor'
|
||||
)
|
||||
|
||||
exampleInstanceVariable=: 0
|
||||
1
Task/Classes/J/classes-2.j
Normal file
1
Task/Classes/J/classes-2.j
Normal file
|
|
@ -0,0 +1 @@
|
|||
exampleObject=: conew 'exampleClass'
|
||||
24
Task/Classes/Lisaac/classes.lisaac
Normal file
24
Task/Classes/Lisaac/classes.lisaac
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
Section Header
|
||||
|
||||
+ name := SAMPLE;
|
||||
|
||||
Section Inherit
|
||||
|
||||
- parent : OBJECT := OBJECT;
|
||||
|
||||
Section Private
|
||||
|
||||
+ variable : INTEGER <- 0;
|
||||
|
||||
Section Public
|
||||
|
||||
- some_method <- (
|
||||
variable := 1;
|
||||
);
|
||||
|
||||
- main <- (
|
||||
+ sample : SAMPLE;
|
||||
|
||||
sample := SAMPLE.clone;
|
||||
sample.some_method;
|
||||
);
|
||||
20
Task/Classes/Logtalk/classes-1.logtalk
Normal file
20
Task/Classes/Logtalk/classes-1.logtalk
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
:- object(metaclass,
|
||||
instantiates(metaclass)).
|
||||
|
||||
:- public(new/2).
|
||||
new(Instance, Value) :-
|
||||
self(Class),
|
||||
create_object(Instance, [instantiates(Class)], [], [state(Value)]).
|
||||
|
||||
:- end_object.
|
||||
|
||||
:- object(class,
|
||||
instantiates(metaclass)).
|
||||
|
||||
:- public(method/1).
|
||||
method(Value) :-
|
||||
::state(Value).
|
||||
|
||||
:- private(state/1).
|
||||
|
||||
:- end_object.
|
||||
7
Task/Classes/Logtalk/classes-2.logtalk
Normal file
7
Task/Classes/Logtalk/classes-2.logtalk
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
| ?- class::new(Instance, 1).
|
||||
Instance = o1
|
||||
yes
|
||||
|
||||
| ?- o1::method(Value).
|
||||
Value = 1
|
||||
yes
|
||||
Loading…
Add table
Add a link
Reference in a new issue