Call an object method: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 162:
Output from object1: Example of calling an instance method from an alias</pre>
 
=={{header|ChucK}}==
<lang>
MyClass myClassObject;
myClassObject.myFunction(some parameter);
</lang>
=={{header|C}}==
C has structures and it also has function pointers, which allows C structures to be associated with any function with the same signature as the pointer. Thus, C structures can also have object methods.
Line 204 ⟶ 199:
Factorial of 10 is 3628800
</pre>
 
=={{header|C++}}==
<lang cpp>// Static
Line 221 ⟶ 217:
// Instance
myInstance.Method(someParameter);</lang>
 
=={{header|ChucK}}==
<lang>
MyClass myClassObject;
myClassObject.myFunction(some parameter);
</lang>
 
=={{header|Clojure}}==
Line 1,246 ⟶ 1,248:
Checkit
</lang>
 
 
 
=={{header|Maple}}==
Line 1,440:
MyClass::classMethod('MyClass', $someParameter);
MyClass::method($myInstance, $someParameter);</lang>
 
=={{header|Perl 6}}==
{{works with|Rakudo|2015.12}}
=== Basic method calls ===
<lang perl6>class Thing {
method regular-example() { say 'I haz a method' }
 
multi method multi-example() { say 'No arguments given' }
multi method multi-example(Str $foo) { say 'String given' }
multi method multi-example(Int $foo) { say 'Integer given' }
};
 
# 'new' is actually a method, not a special keyword:
my $thing = Thing.new;
 
# No arguments: parentheses are optional
$thing.regular-example;
$thing.regular-example();
$thing.multi-example;
$thing.multi-example();
 
# Arguments: parentheses or colon required
$thing.multi-example("This is a string");
$thing.multi-example: "This is a string";
$thing.multi-example(42);
$thing.multi-example: 42;
 
# Indirect (reverse order) method call syntax: colon required
my $foo = new Thing: ;
multi-example $thing: 42;
</lang>
 
=== Meta-operators ===
 
The <code>.</code> operator can be decorated with meta-operators.
 
<lang perl6>
my @array = <a z c d y>;
@array .= sort; # short for @array = @array.sort;
 
say @array».uc; # uppercase all the strings: A C D Y Z
</lang>
 
=== Classless methods ===
 
A method that is not in a class can be called by using the <code>&</code> sigil explicitly.
 
<lang perl6>
my $object = "a string"; # Everything is an object.
my method example-method {
return "This is { self }.";
}
 
say $object.&example-method; # Outputs "This is a string."
</lang>
 
=={{header|Phix}}==
Line 1,527 ⟶ 1,472:
<lang PicoLisp>(foo> MyClass)
(foo> MyObject)</lang>
 
=={{header|Pike}}==
Pike does not have static methods. (the <code>static</code> modifier in Pike is similar to <code>protected</code> in C++).
Line 1,636 ⟶ 1,582:
(define timer (new timer%))
(send timer start 100)</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2015.12}}
=== Basic method calls ===
<lang perl6>class Thing {
method regular-example() { say 'I haz a method' }
 
multi method multi-example() { say 'No arguments given' }
multi method multi-example(Str $foo) { say 'String given' }
multi method multi-example(Int $foo) { say 'Integer given' }
};
 
# 'new' is actually a method, not a special keyword:
my $thing = Thing.new;
 
# No arguments: parentheses are optional
$thing.regular-example;
$thing.regular-example();
$thing.multi-example;
$thing.multi-example();
 
# Arguments: parentheses or colon required
$thing.multi-example("This is a string");
$thing.multi-example: "This is a string";
$thing.multi-example(42);
$thing.multi-example: 42;
 
# Indirect (reverse order) method call syntax: colon required
my $foo = new Thing: ;
multi-example $thing: 42;
</lang>
 
=== Meta-operators ===
 
The <code>.</code> operator can be decorated with meta-operators.
 
<lang perl6>
my @array = <a z c d y>;
@array .= sort; # short for @array = @array.sort;
 
say @array».uc; # uppercase all the strings: A C D Y Z
</lang>
 
=== Classless methods ===
 
A method that is not in a class can be called by using the <code>&</code> sigil explicitly.
 
<lang perl6>
my $object = "a string"; # Everything is an object.
my method example-method {
return "This is { self }.";
}
 
say $object.&example-method; # Outputs "This is a string."
</lang>
 
=={{header|Ring}}==
Line 1,880 ⟶ 1,882:
 
What is your name ?</pre>
 
 
=={{header|XLISP}}==
10,333

edits