Skip to content

Modules: Proposal: import syntax for Source §1-§4 #399

@martin-henz

Description

@martin-henz

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));

This will:

  • demystify module loading for students: Source would be in line with other programming languages where imported functionality is explicitly named in programs
  • simplify the Source Academy user interface: no more need for a "Library" menu
  • simplify js-slang tools: imported names are all explicitly mentioned in the program

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ProposalProposing a feature, please discussimportantFixing this is important, but not mission-critical

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions