BrowserREPL-button-tip-on BrowserREPL-button-tip-off

EditButtonTip 2024-05-18

class ForeignCode

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

class ForeignCode does Callable {}
Code

[ 1 ]

ForeignCode is a Raku wrapper around code that is not written originally in that language; its intention is to use these blocks of code in Callable contexts easily. For instance, subs have some anonymous functions that are actually ForeignCode.

sub does-nothing(){};
say $_.name ~ ' → ' ~ $_.^name for &does-nothing.^methods;
# OUTPUT: «<anon> → ForeignCode␤<anon> → ForeignCode␤soft → Method␤…»
Code

This script will map method names to their class, and it shows that routines, in particular, have several methods that are actually ForeignCode instead of Methods.

Methods§

method arity§

method arity()
Code

Returns the arity of the enclosed code.

method count§

method count()
Code

Returns the number of arguments the enclosed code needs.

method signature§

method signature( ForeignCode:D: )
Code

Returns the signature of the enclosed code.

method name§

method name()
Code

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

method gist§

method gist( ForeignCode:D: )
Code

Returns the name of the code by calling name.

method Str§

method Str( ForeignCode:D: )
Code

Returns the name of the code by calling name.

Class relation diagram§

Rakudo Type Relation for ForeignCode ForeignCode ForeignCode Any Any ForeignCode->Any is Callable Callable ForeignCode->Callable does

Footnotes

1 |^| This is a Rakudo specific class, and as such it is advisable not to use it in your own code, since its interface might change or even disappear in the future. This is provided here only as a reference