Rules / Types, classes & roles / basic

ForeignCode Reference

Rakudo-specific class that wraps around code in other languages (generally NQP)

What it is #

Routines #

Signatures are reproduced from the documentation, including their declared return types. A routine listed here is part of the type's published interface; whether Raku++ implements it is a separate question, answered by the examples below.

method arity #

method arity()

Returns the arity of the enclosed code.

method count #

method count()

Returns the number of arguments the enclosed code needs.

method signature #

method signature( ForeignCode:D: )

Returns the signature of the enclosed code.

method name #

method name()

Returns the name of the enclosed code, or <anon> if it has not received any.

method gist #

method gist( ForeignCode:D: )

Returns the name of the code by calling name.

method Str #

method Str( ForeignCode:D: )

Returns the name of the code by calling name.

Examples, run three ways #

Every example below comes from the official documentation, together with the output that documentation asserts. Each was then executed by Rakudo and by Raku++ when this page was built. Where the three agree, one result is shown; where they do not, all three are — because which of them is wrong is exactly the information worth having.

1 all-differ · 1 no-output

class ForeignCode does Callable {}

Not executed: the documentation states no expected output for this example.

sub does-nothing(){};
say $_.name ~ ' → ' ~ $_.^name for &does-nothing.^methods;
# OUTPUT: «<anon> → ForeignCode␤<anon> → ForeignCode␤soft → Method␤…»
Documentation
<anon> → ForeignCode
<anon> → ForeignCode
soft → Method
…
Rakudo
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
candidates → Method
cando → Method
multi → Method
soft → Method
is-wrapped → Method
wrap → Method
unwrap → Method
package → Method
leave → Method
iterator → Method
IS-SETTING-ONLY → Method+{is-implementation-detail}
prec → Method
op_props → Method+{is-implementation-detail}
precedence → Method
associative → Method
thunky → Method
iffy → Method
reducer → Method
equiv → Method
tighter → Method
looser → Method
assoc → Method
set_op_props → Method+{is-implementation-detail}
apply-operator-trait → Method+{is-implementation-detail}
gist → Method
raku → Method
POPULATE → Submethod
POPULATE → Submethod
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
of → Method
returns → Method
unshift-phaser → Method+{is-implementation-detail}
push-phaser → Method+{is-implementation-detail}
add_phaser → Method
callable_for_phaser → Method
fire_if_phasers → Method
fire_phasers → Method
has-phasers → Method
has-loop-phasers → Method
has-phaser → Method
phasers → Method
WHY → Method
set_why → Method
raku → Method
POSITIONS → Method
POPULATE → Submethod
POPULATE → Submethod
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
<anon> → ForeignCode
is-implementation-detail → Method
precedence → Method
associative → Method
thunky → Method
iffy → Method
reducer → Method
bytecode-size → Method
POSITIONS → Method+{is-implementation-detail}
arity → Method
count → Method
signature → Method
cando → Method
prec → Method
outer → Method
static_id → Method
file → Method
line → Method
of → Method
returns → Method
Capture → Method
ACCEPTS → Method
Str → Method
new → Method
POPULATE → Submethod
assuming → Method
POPULATE → Submethod
Raku++

All three differ. Needs a human.

Not yet examined. Which of these is correct has not been established — do not treat either engine as settled here.