Call an object method: Difference between revisions

Content added Content deleted
Line 1,400: Line 1,400:
# Instance
# Instance
$myInstance mthd someParameter</lang>
$myInstance mthd someParameter</lang>

=={{header|XLISP}}==
Class methods and instance methods are defined using <tt>DEFINE-CLASS-METHOD</tt> and <tt>DEFINE-METHOD</tt> respectively. They are called by sending a message to the class or to an instance of it: the message consists of (<i>a</i>) the name of the object that will receive it, which may be a class; (<i>b</i>) the name of the method, as a quoted symbol; and (<i>c</i>) the parameters if any.
<lang xlisp>(DEFINE-CLASS MY-CLASS)

(DEFINE-CLASS-METHOD (MY-CLASS 'DO-SOMETHING-WITH SOME-PARAMETER)
(DISPLAY "I am the class -- ")
(DISPLAY SELF)
(NEWLINE)
(DISPLAY "You sent me the parameter ")
(DISPLAY SOME-PARAMETER)
(NEWLINE))

(DEFINE-METHOD (MY-CLASS 'DO-SOMETHING-WITH SOME-PARAMETER)
(DISPLAY "I am an instance of the class -- ")
(DISPLAY SELF)
(NEWLINE)
(DISPLAY "You sent me the parameter ")
(DISPLAY SOME-PARAMETER)
(NEWLINE))

(MY-CLASS 'DO-SOMETHING-WITH 'FOO)

(DEFINE MY-INSTANCE (MY-CLASS 'NEW))

(MY-INSTANCE 'DO-SOMETHING-WITH 'BAR)</lang>
{{out}}
<pre>I am the class -- #<Class:MY-CLASS #x38994c8>
You sent me the parameter FOO
I am an instance of the class -- #<Object:MY-CLASS #x39979d0>
You sent me the parameter BAR</pre>


=={{header|zkl}}==
=={{header|zkl}}==