Skip to content

Overview

Bryan Loh edited this page Apr 18, 2021 · 4 revisions

This page contains information regarding the overview of the Source Modules system.

Aims

  1. Decouple Source modules from the frontend and backend of Source Academy, as well as the implementation of Source language, enhancing the flexibility of Source modules.
  2. Optionally render interactive user interfaces for students to use with Source Academy to enhance their learning experience.
  3. Allow ease of collaboration and promotes contribution to the modules ecosystem without a steep learning curve.

Motivation

The project was suggested by Prof Martin Henz who first proposed to include import statements in the Source Language in the js-slang issue here. This move aims to achieve 3 main things:

  1. To demystify module loading for students. Source would be in line with other programming languages where imported functionality is explicitly named in programs.
  2. To simplify the Source Academy user interface. There will no longer be a need for a “library” menu.
  3. To simplify Source implementation tools. Imported names will all be explicitly mentioned in the Source program.

I'm proposing to allow the following syntax in Source:

program         ::= importdirective... statement...
importdirective ::= import { importnames } from string;
importnames     ::= importname (, importname)...
importname      ::= name | name as name

This means that we will explicitly import modules (libraries) from now on, in order to use them:

import { heart as lung, show as view, stack, sail } from 'lib/runes';

view(stack(lung, sail));

For Source 2021, the path will be resolved to: https://github.com/source-academy/modules/tree/master/ This means that from 'lib/runes' refers to https://github.com/source-academy/modules/tree/master/lib/runes.js (the default file extension will be .js)

The Source Academy frontend will fetch the module from the backend, which of course will cache it. Our modules can still be written in JavaScript and loaded in the frontend in whatever way works (e.g. eval).

In the future, we can allow for a more flexible scheme where users can import Source programs using the same syntax.

Clone this wiki locally