September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -0,0 +1,17 @@
|
|||
(defclass my-class ()
|
||||
((x
|
||||
:accessor get-x ;; getter function
|
||||
:initarg :x ;; arg name
|
||||
:initform 0))) ;; initial value
|
||||
|
||||
;; declaring a public class method
|
||||
(defmethod square-x ((class-instance my-class))
|
||||
(* (get-x class-instance) (get-x class-instance)))
|
||||
|
||||
;; create an instance of my-class
|
||||
(defvar *instance*
|
||||
(make-instance 'my-class :x 10))
|
||||
|
||||
(format t "Value of x: ~a~%" (get-x *instance*))
|
||||
|
||||
(format t "Value of x^2: ~a~%" (square-x *instance*))
|
||||
|
|
@ -1 +1 @@
|
|||
instance message:param1:param2.
|
||||
console printLine("Hello"," ","World!").
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
instance message &subj1:param1 &subj2:param2.
|
||||
console write literal:(console readLiteral).
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
console write literal(console readLiteral).
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
procedure main()
|
||||
|
||||
foo_m1() # equivalent of class method, not normally used
|
||||
bar := foo() # create instance
|
||||
bar.m2() # call method m2 with self=bar
|
||||
end
|
||||
bar.m2() # call method m2 with self=bar, an implicit first parameter
|
||||
|
||||
foo_m1( , "param1", "param2") # equivalent of static class method, first (self) parameter is null
|
||||
end
|
||||
|
||||
class foo(cp1,cp2)
|
||||
method m1(m1p1,m1p2)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
class MyClass {
|
||||
fun instanceMethod(s: String) = println(s)
|
||||
|
||||
companion object {
|
||||
fun staticMethod(s: String) = println(s)
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val mc = MyClass()
|
||||
mc.instanceMethod("Hello instance world!")
|
||||
MyClass.staticMethod("Hello static world!")
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
+&GO
|
||||
30
Task/Call-an-object-method/OoRexx/call-an-object-method.rexx
Normal file
30
Task/Call-an-object-method/OoRexx/call-an-object-method.rexx
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
say "pi:" .circle~pi
|
||||
c=.circle~new(1)
|
||||
say "c~area:" c~area
|
||||
Do r=2 To 10
|
||||
c.r=.circle~new(r)
|
||||
End
|
||||
say .circle~instances('') 'circles were created'
|
||||
|
||||
::class circle
|
||||
::method pi class -- a class method
|
||||
return 3.14159265358979323
|
||||
|
||||
::method instances class -- another class method
|
||||
expose in
|
||||
use arg a
|
||||
If datatype(in)<>'NUM' Then in=0
|
||||
If a<>'' Then
|
||||
in+=1
|
||||
Return in
|
||||
|
||||
::method init
|
||||
expose radius
|
||||
use arg radius
|
||||
self~class~instances('x')
|
||||
|
||||
::method area -- an instance method
|
||||
expose radius
|
||||
Say self~class
|
||||
Say self
|
||||
return self~class~pi * radius * radius
|
||||
11
Task/Call-an-object-method/Zkl/call-an-object-method.zkl
Normal file
11
Task/Call-an-object-method/Zkl/call-an-object-method.zkl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
class C{var v; fcn f{v}}
|
||||
C.f() // call function f in class C
|
||||
C.v=5; c2:=C(); // create new instance of C
|
||||
println(C.f()," ",c2.f()) //-->5 Void
|
||||
C.f.isStatic //--> False
|
||||
|
||||
class [static] D{var v=123; fcn f{v}}
|
||||
D.f(); D().f(); // both return 123
|
||||
D.f.isStatic //-->False
|
||||
|
||||
class E{var v; fcn f{}} E.f.isStatic //-->True
|
||||
Loading…
Add table
Add a link
Reference in a new issue