Call an object method: Difference between revisions

Content added Content deleted
Line 521: Line 521:


==Icon and {{header|Unicon}}==
==Icon and {{header|Unicon}}==
Icon does not have objects or methods; they can be implemented on top of other types such as records.
In Unicon all procedures and methods are dynamically invoked at run-time. The normal method of invoking a method is with instances of its class. While it is technically possible to call a method without having an instance it requires knowledge of the underlying translation of methods and classes to procedures and is somewhat unusual.

Unicon has no concept of static methods; all methods are normally invoked using an instance of a class. While it is technically possible to call a method without an instance, it requires knowledge of the underlying implementation, such as the name-mangling conventions, and is non-standard.
<lang unicon>procedure main()
<lang unicon>procedure main()


foo_m1() # equivalent of class method, not normally used
bar := foo() # create instance
bar := foo() # create instance
bar.m2() # call method m2 with self=bar
bar.m2() # call method m2 with self=bar, an implicit first parameter
end


foo_m1( , "param1", "param2") # equivalent of static class method, first (self) parameter is null
end


class foo(cp1,cp2)
class foo(cp1,cp2)
Line 545: Line 547:
L := [cp1]
L := [cp1]
end</lang>
end</lang>
Note: Icon cannot translate code with objects. It may be possible for Icon to translate code preprocessed by Unicon if no other Unicon extensions are used.


=={{header|J}}==
=={{header|J}}==