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

Examples

open allclose all

Basic Examples  (2)

Create an external function using the absolute value function in Python:

Compute the absolute value of with the external Python function:

Start a new session:

Define a new function:

Use the function:

Close the session:

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:

Start a session:

Define a function using complex numbers:

Compute the argument of a complex number via the Python phase function:

Close the session:

Start a NodeJS session:

In NodeJS, it is not enough to just define a functionyou have to explicitly return the function for ExternalFunction to recognize it as a callable function:

Call the function:

Close the session:

Start a Julia session:

Define a function in Julia:

Call the function:

Close the session:

Applications  (3)

Start a new session:

Define a function in the session:

Create an ExternalFunction from this Python function:

Use the function within normal Wolfram Language code:

Start a new session:

Import the Python NumPy package to load additional functionality:

Call the external function:

It partitioned the list into a 3×4 matrix:

The equivalent Wolfram Language command:

Start a new session:

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:

Wolfram Research (2019), ExternalFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/ExternalFunction.html.

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

BibTeX

@misc{reference.wolfram_2023_externalfunction, author="Wolfram Research", title="{ExternalFunction}", year="2019", howpublished="\url{https://reference.wolfram.com/language/ref/ExternalFunction.html}", note=[Accessed: 18-April-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_externalfunction, organization={Wolfram Research}, title={ExternalFunction}, year={2019}, url={https://reference.wolfram.com/language/ref/ExternalFunction.html}, note=[Accessed: 18-April-2024 ]}