source-academy / modules

Modules that can be imported by programs in Source Academy, an online experiential environment for computational thinking
Apache License 2.0
8 stars 28 forks source link

[WIKI]: Document using Source functions in modules #76

Open martin-henz opened 3 years ago

martin-henz commented 3 years ago

Feature

How can I use Source functions in the implementation of a module?

Maybe

import { array_length } from "sicp";

Checklist

houruomu commented 3 years ago

Is 'sicp' a module here? If yes then we can write something like import {xxx} from '../sicp/index.ts';

leeyi45 commented 1 year ago

Has this been adequately addressed by #192?

martin-henz commented 1 year ago

Has this been adequately addressed by #192?

I think yes. But is this documented anywhere?

Cloud7050 commented 1 year ago

I am unsure if this has since been documented somewhere, but developers should now be able to see how to use real js-slang types and functions by referring to existing modules which have since adopted the new technology.

import {
  head,
  list,
  tail,
  type List,
  is_list,
} from 'js-slang/dist/stdlib/list';

It is worth noting that if a file uses js-slang functions (excluding types - types appear to be ok), then that file must not be imported by any tab, or building will fail. This may or may not get addressed down the line, removed as a limitation via updates to the build system. Longer explanation:

https://github.com/Cloud7050/modules/blob/fd66e351a89332ebb1008b513e9233106bf8881f/src/bundles/csg/functions.ts#L97-L108