Call an object method: Difference between revisions

→‎{{header|TXR}}: New section.
m (Automated syntax highlighting fixup (second round - minor fixes))
(→‎{{header|TXR}}: New section.)
Line 1,896:
# Instance
$myInstance mthd someParameter</syntaxhighlight>
=={{header|TXR}}==
 
TXR Lisp method invocation syntax is <code>obj.(method args...)</code>.
 
Static methods are just functions that don't take an object as an argument. The above notation, therefore, isn't used, rather the functional square brackets: <code>[obj.function args...]</code>.
 
<syntaxhighlight lang="txrlisp">(defvarl thing-count 0)
 
(defstruct thing ()
(call-count 0)
 
(:init (me)
(inc thing-count))
(:function get-thing-count () thing-count)
(:method get-call-count (me) (inc me.call-count)))
 
(let ((t1 (new thing))
(t2 (new thing)))
(prinl t1.(get-call-count)) ;; prints 1
(prinl t1.(get-call-count)) ;; prints 2
(prinl t1.(get-call-count)) ;; prints 3
(prinl t2.(get-call-count)) ;; prints 1
(prinl t2.(get-call-count)) ;; prints 2
(prinl t2.(get-call-count)) ;; prints 3
(prinl [t1.get-thing-count]) ;; prints 2
(prinl [t2.get-thing-count])) ;; prints 2</syntaxhighlight>
 
{{out}}
<pre>1
2
3
1
2
3
2
2</pre>
 
=={{header|Ursa}}==
<syntaxhighlight lang="ursa"># create an instance of the built-in file class
Line 1,902 ⟶ 1,940:
# call the file.open method
f.open "filename.txt"</syntaxhighlight>
 
=={{header|VBA}}==
First we have to create a class module named "myObject" :
543

edits