txt: ## foreigncode.md
  class ForeignCode
  
  Rakudo-specific class that wraps around code in other languages (generally NQP)
  
  ```raku
  class ForeignCode does Callable {}
  ```
  
  [[1]](#fn1)
  
  `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`](/type/Callable) contexts easily. For instance, subs have some anonymous functions that are actually `ForeignCode`.
  
  ```raku
  sub does-nothing(){};
  say $_.name ~ ' → ' ~ $_.^name for &does-nothing.^methods;
  # OUTPUT: «<anon> → ForeignCode␤<anon> → ForeignCode␤soft → Method␤…»
  
  ```
  
  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 [`Method`](/type/Method)s.
  
  # [Methods](#class_ForeignCode "go to top of document")[§](#Methods "direct link")
  
  ## [method arity](#class_ForeignCode "go to top of document")[§](#method_arity "direct link")
  
  ```raku
  method arity()
  ```
  
  Returns the arity of the enclosed code.
  
  ## [method count](#class_ForeignCode "go to top of document")[§](#method_count "direct link")
  
  ```raku
  method count()
  ```
  
  Returns the number of arguments the enclosed code needs.
  
  ## [method signature](#class_ForeignCode "go to top of document")[§](#method_signature "direct link")
  
  ```raku
  method signature( ForeignCode:D: )
  ```
  
  Returns the signature of the enclosed code.
  
  ## [method name](#class_ForeignCode "go to top of document")[§](#method_name "direct link")
  
  ```raku
  method name()
  ```
  
  Returns the name of the enclosed code, or `<anon>` if it has not received any.
  
  ## [method gist](#class_ForeignCode "go to top of document")[§](#method_gist "direct link")
  
  ```raku
  method gist( ForeignCode:D: )
  ```
  
  Returns the name of the code by calling `name`.
  
  ## [method Str](#class_ForeignCode "go to top of document")[§](#method_Str "direct link")
  
  ```raku
  method Str( ForeignCode:D: )
  ```
  
  Returns the name of the code by calling `name`.
  
  # [Typegraph](# "go to top of document")[§](#typegraphrelations "direct link")
  
  Type relations for `ForeignCode`
  
  
  
  raku-type-graph
  
  
  
  ForeignCode
  ForeignCode
  
  
  Any
  Any
  
  
  ForeignCode->Any
  
  
  
  Callable
  Callable
  
  
  ForeignCode->Callable
  
  
  
  Mu
  Mu
  
  
  Any->Mu
  
  [Expand chart above](/assets/typegraphs/ForeignCode.svg)
  
  1 [[↑]](#fnret1) 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
  