ExternalFunction
ExternalFunction[sys,"f"]
represents an external function named "f" defined in the external evaluator sys.
ExternalFunction[session,"f"]
represents an external function "f" in the specified external session.
ExternalFunction[sys,"code"]
represents an external function defined by the code fragment "code".
Details

- In ExternalFunction[sys,"code"], "code" is typically a pure or lambda function in the external system.
- In ExternalFunction[sys, …], possible choices for sys include:
-
"Python" Python "NodeJS" JavaScript running through Node.js "Julia" Julia "Ruby" Ruby "R" R "Jupyter" Jupyter kernel - ExternalFunction[session,"f"] returns a Failure object if "f" does not exist in session.
Examples
open allclose allBasic Examples (2)
Scope (5)
Define a lambda function in Python:
Use this Python function in the Wolfram Language:
Use a Python built-in function:
Use the external function to convert a string to a list:
Define a function using complex numbers:
Compute the argument of a complex number via the Python phase function:
In NodeJS, it is not enough to just define a function—you have to explicitly return the function for ExternalFunction to recognize it as a callable function:
Applications (3)
Define a function in the session:
Create an ExternalFunction from this Python function:
Use the function within normal Wolfram Language code:
Import the Python NumPy package to load additional functionality:
It partitioned the list into a 3×4 matrix:
The equivalent Wolfram Language command:
Define a Python function that imports an image from a URL and rotates it:
The result is a ByteArray:
Import the ByteArray to display the rotated image:
Text
Wolfram Research (2019), ExternalFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/ExternalFunction.html.
CMS
Wolfram Language. 2019. "ExternalFunction." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ExternalFunction.html.
APA
Wolfram Language. (2019). ExternalFunction. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ExternalFunction.html