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
    "Python-NumPy"Python with NumPy loaded
    "Python-PIL"Python with the Python Image Library (PIL) loaded
    "NodeJS"JavaScript running through Node.js
  • ExternalFunction[session,"f"] returns a Failure object if "f" does not exist in session.

Examples

open all close all

Basic Examples  (2)

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

In[1]:=
Click for copyable input
Out[1]=

Compute the absolute value of with the external Python function:

In[2]:=
Click for copyable input
Out[2]=

Start a new session:

In[1]:=
Click for copyable input
Out[1]=

Define a new function:

In[2]:=
Click for copyable input
Out[2]=

Use the function:

In[3]:=
Click for copyable input
Out[3]=

Close the session:

In[4]:=
Click for copyable input

Scope  (3)

Applications  (3)

Introduced in 2019
(12.0)