March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
|
|
@ -0,0 +1,13 @@
|
|||
( ( myClass
|
||||
= (name=aClass)
|
||||
( Method
|
||||
= .out$(str$("Output from " !(its.name) ": " !arg))
|
||||
)
|
||||
(new=.!arg:?(its.name))
|
||||
)
|
||||
& (myClass.Method)$"Example of calling a 'class' method"
|
||||
& new$(myClass,object1):?MyObject
|
||||
& (MyObject..Method)$"Example of calling an instance method"
|
||||
& !MyObject:?Alias
|
||||
& (Alias..Method)$"Example of calling an instance method from an alias"
|
||||
);
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
*> INVOKE
|
||||
INVOKE FooClass "someMethod" RETURNING bar *> Factory object
|
||||
INVOKE foo-instance "anotherMethod" RETURNING bar *> Instance object
|
||||
|
||||
*> Inline method invocation
|
||||
MOVE FooClass::"someMethod" TO bar *> Factory object
|
||||
MOVE foo-instance::"anotherMethod" TO bar *> Instance object
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
INVOKE foo-instance "FactoryObject" RETURNING foo-factory
|
||||
*> foo-factory can be treated like a normal object reference.
|
||||
INVOKE foo-factory "someMethod"
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
// Static (known in Pascal as class method)
|
||||
MyClass.method(someParameter);
|
||||
|
||||
// Instance
|
||||
myInstance.method(someParameter);
|
||||
|
|
@ -24,5 +24,4 @@ BEGIN
|
|||
myInstance := myClass(null);
|
||||
DBMS_OUTPUT.put_line( myClass.static_method() );
|
||||
DBMS_OUTPUT.put_line( myInstance.instance_method() );
|
||||
END;
|
||||
/
|
||||
END;/
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
/** This class implicitly includes a constructor which accepts an Int and
|
||||
/* This class implicitly includes a constructor which accepts an Int and
|
||||
* creates "val variable1: Int" with that value.
|
||||
*/
|
||||
class MyClass(val variable1: Int) {
|
||||
var variable2 = "asdf" // Another instance variable; a public var this time
|
||||
class MyClass(val memberVal: Int) { // Acts like a getter, getter automatically generated.
|
||||
var variable2 = "asdf" // Another instance variable; a public mutable this time
|
||||
def this() = this(0) // An auxilliary constructor that instantiates with a default value
|
||||
def myMethod = variable1 // A getter for variable1, getter of variable1 is auto-created
|
||||
}
|
||||
|
||||
object HelloObject {
|
||||
|
|
@ -13,13 +12,13 @@ object HelloObject {
|
|||
|
||||
/** Demonstrate use of our example class.
|
||||
*/
|
||||
object Call_an_object_method extends Application {
|
||||
object Call_an_object_method extends App {
|
||||
val s = "Hello"
|
||||
val m = new MyClass()
|
||||
val m = new MyClass
|
||||
val n = new MyClass(3)
|
||||
|
||||
println(HelloObject.s) // prints "Hello" by object getterHelloObject
|
||||
|
||||
println(m.myMethod) // prints 0
|
||||
println(n.myMethod) // prints 3
|
||||
assert(HelloObject.s == "Hello") // "Hello" by object getterHelloObject
|
||||
assert(m.memberVal == 0)
|
||||
assert(n.memberVal == 3)
|
||||
println("Successfully completed without error.")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue