exportFunction

exportFunction (inputsSchema output options callable name --)

Inputs

Outputs

exportFunction constructs a function signature, compiles the supplied Block, records the resulting function declaration, and creates the exported function name in the current module.

The stack contract follows the declared signature. When the exported function starts at runtime, its declared inputs are on the data stack. Named access inside the body still requires explicit binding. Names written inside inputsSchema therefore belong only to the signature, not to the surrounding scope.

Behavior

Example

exportExample.mpl

{} 0 {} [
  "-- zero-input body compiled --" printCompilerMessage
  7
] "seven" exportFunction

{ value: 0; } 0 {} [
  value:;
  "-- one-input body compiled --" printCompilerMessage
  value 1 +
] "addOne" exportFunction

"-- exported name immediately usable here --" printCompilerMessage
@addOne printStack _:;
@addOne known? printStack _:;

test.mpl is the primary runnable example file.

test.mpl

"String" use
"exportExample.seven" use
"exportExample.addOne" use

{} 0 {} [
  ("-- zero-input function -- " seven "\n") printList
  ("-- one-input function -- " 5 addOne "\n") printList
  @addOne known? printStack _:;
  0
] "main" exportFunction

Module-loading wrapper lines are omitted below.

Expected Output During Compilation

-- zero-input body compiled --
-- one-input body compiled --
-- exported name immediately usable here --
{value: Int32;} Int32 {} codeRef
FALSE
FALSE

Expected Output

-- zero-input function -- 7
-- one-input function -- 6

See also