Injecting_Modules - nus-cs4215/x-slang-t1-xz-jj GitHub Wiki
Injecting Predeclared Names
In Source, each chapter of the languages have specific predeclared names defined as helper functions. As an adaptation of Source, SICPy includes (a subset of) them as well (e.g., MISC, LISTS, MATH and etc).
The corresponding implementation can be found under src/sicp/modules/module_inject.ts.
How?
Right before handing over the user's code to Pyodide.js, we perform a call to the inject_modules function in src/sicp/modules/module_inject.ts. This function returns the corresponding implementations in Python, which will then be executed through a pyodide.runPython() call to inject these modules into the environment.
For instance, the pair function is implemented as follows:
def pair(head, tail):
return [head, tail]
More details can be found in src/sicp/modules/module_inject.ts.