source-academy / modules Goto Github PK
View Code? Open in Web Editor NEWModules that can be imported by programs in Source Academy, an online experiential environment for computational thinking
License: Apache License 2.0
Modules that can be imported by programs in Source Academy, an online experiential environment for computational thinking
License: Apache License 2.0
Please answer the following questions for yourself before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.
Importing of wrong names should give an error.
Wrong names are silently ignored. The name is get_wave, not fetch_wave:
Please provide detailed steps for reproducing the issue.
See above
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
Current sourceacademy.org, Chrome on macOS.
see above
import {draw_connected_full_view, unit_circle } from "curve";
draw_connected_full_view(500)(unit_circle);
0;
should draw the circle. Currently the drawers only draw when the result of the evaluation is a drawing. With the separate curve window, we can eliminate this hack.
Please answer the following questions for yourself before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.
Gallery entry in Developer documentation
https://github.com/source-academy/modules/wiki/%5Bcurve%5D-Developer-Documentation
should work
Bugs as follows.
then you get:
should be "curve" not "curves"
After correcting this, the import fails:
see above
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
see above
Some of the functions in the Rune library do not have properly typed function arguments.
For example, the current color()
function has signature color(rune: Rune, r: any, g: any, b: any): Rune
. However, it should instead be color(rune: Rune, r: number, g: number, b: number): Rune
.
This may cause confusion in the documentation.
See https://source-academy.github.io/modules/documentation/modules/runes.html#color for details.
The documentation currently uses the type CurveFunction. There is no such a type in the material. It should be just Curve.
Ever since the introduction of our module bundler RollupJS, I feel that documenting in the code alone is insufficient. We should include a page in the wiki to explain the choices and the build flow (eg. TypeScript -> ESNext -> ES2015
) and the intermediate steps within the bundler system (eg. CopyFilePlugin
and Polyfills
).
Please answer the following questions for yourself before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.
This should work:
import {} from "sound";
import { start } from "pix_n_flix";
start();
It crashes the frontend.
https://share.sourceacademy.nus.edu.sg/lc0d3
Just presss "Run".
ESLint provides JavaScript linting and analyzes the modules' code for errors. This linter will help to enforce rules that modules need to conform to. Furthermore, it will provide a better developer experience for the cadets.
Prettier is there to format code, especially line endings (just use LF) which can lead to commits that modify entire files (and therefore lose the git blame).
There is an issue where by upon running the yarn module
command in the modules' root folder on a MacOS to add a new bundle/tab, the new bundle/tab generates in a new directory modules\src\bundles
.
play()
and play_concurrently()
should both spawn sound tab if either of which is the last statement of the program, regardless of which to store as the downloadable audio file.
play()
returns AudioPlayed while play_concurrently()
is purely a consumer. Hence, no sound tab is spawned.
import {
play,
play_concurrently,
noise_sound
} from "sound";
play(noise_sound(0.5));
play_concurrently(noise_sound(0.5));
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
In the Rune module docs, rotate()
takes two params - rad
and rune
. It states that rad
should be a "fraction between 0 and 1", which is the same documented text as the stack/beside/overlay_frac functions' frac
params.
However, the method itself is said to "[rotate] a given Rune by a given angle, given in radians, in anti-clockwise direction". I have found that supplying 2 * math_PI
rads is a full rotation, and numbers higher than that also work.
Please answer the following questions for yourself before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.
2D Draw methods should throw an error when passed a 3D curve, and 3D draw methods should throw
an error when passed a 2D curve.
The 2D draw methods like draw_connected
accept 3D points created by make_3D_point
, and
3D draw methods like draw_3D_connected
accept 2D points created by make_2D_point
.
Please provide detailed steps for reproducing the issue.
import { draw_connected, draw_3D_connected, make_point, make_3D_point } from 'curve';
draw_connected(200)(t => make_3D_point(t, t, t)); // works with no error
draw_3D_connected(200)(t => make_point(t, t)); // works with no error
Currently
make_sound(x => 0, -1)
is possible, but it should lead to an error.
Please answer the following questions for yourself before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.
The documention (wiki and module documentation) should use the proper name: binary_tree
It is called binary_trees (with "s")
The current mission format allows us to select from a fixed set of libraries, such as TWO_DIM_RUNES, as in
<DEPLOYMENT interpreter="2">
<EXTERNAL name="TWO_DIM_RUNES">
<SYMBOL>beside</SYMBOL>
<SYMBOL>make_cross</SYMBOL>
...
These libraries are currently hard-wired into the Source Academy frontend. I suggest that we instead use JavaScript modules that we take from a folder lib in this assessments repository. More specifically, the IMPORT tag will include a relative path that is extended by the Source Academy to a full path to the master assessment repository of the Source Academy github organization.
Example:
<DEPLOYMENT interpreter="2">
<IMPORT module="cs1101s_1920/two_dim_runes">
<SYMBOL>beside</SYMBOL>
<SYMBOL>make_cross</SYMBOL>
This assessment would load the following module:
https://github.com/source-academy/assessments/tree/master/lib/cs1101s_1920/two_dim_runes.js
as if it was imported as follows:
import { beside, make_cross } from 'two_dim_runes';
assuming that the module two_dim_runes
is written like this:
export function beside(x, y) {
return ...;
}
export function make_cross(x) {
return ...;
}
Views?
Not sure if this issue is related to previous issue, but when I change the module I'm importing from, the spawn tab's tag does not change. For example. if I import something from repeat module, then import from another module, the spawn tab's tag remains as Repeat Test Tab.
Maybe this issue is related to the previous one and would be fixed simultaneously.
evaluationMode
settingAfter looking at the developer documentation for Source Module rpc
, I realised that it may be essential for Source Module developers to have some control over the mode of evaluation by the Source Interpreter js-slang
.
I'm proposing a field evaluationMode
in modules.json
that can be set to either all
, interpreter
or transpiler
which will be checked in the module loader of js-slang
which will either continue the module loading process or throw a corresponding error message.
ie.
{
"rpc": {
"evaluationMode": "all",
"tabs": [ "Rpc" ]
}
}
The updating of the evaluationMode
field can be added into the Source Module command- line application.
How can I use Source functions in the implementation of a module?
Maybe
import { array_length } from "sicp";
This is to communicate to students show(Rune) doesn't produce a rune, therefore the output does not go into things which require a Rune.
I propose something like the following:
class Rune {
constructor() {
this.drawMethod = '';
}
toReplString() {
return this.drawMethod === '' ? '<RUNE>' : '<RENDERING>'
}
}
import firebase from "firebase/app";
import "firebase/firestore";
Using the code snippet above inside a bundle or a tab should compile into the expected IIFE function by rollup with no function parameters.
However, the current compilation by rollup results in a function with many function parameters as shown in the picture below.
Please provide detailed steps for reproducing the issue.
firebase
and firebase/firestore
as shown in the code snippet above.yarn build
to see the output file in ./build/bundle/
.Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
N/A
The problem: We will prefix the SICP JS textbook programs with
import "sicp";
Those programs would work in Source Academy, if we have an empty module here.
Please answer the following questions for yourself before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.
Source Academy does not crash
What is the current behavior?
Source Academy crashes
Please provide detailed steps for reproducing the issue.
import {
red_of,
green_of,
blue_of,
alpha_of,
set_rgba,
copy_image,
install_filter,
reset_filter,
video_height,
video_width
} from "pix_n_flix";
I require "debounce" dependency for "three" and "three-react-fiber". The package supposedly exports "debounce" function as follows:
The project is unable to build.
yarn install
to install all additional dependencies requiredyarn build
"enable verbose";
import { repeat } from "repeat";
repeat(x => x + 1);
When running the above code snippet, a side content tab should appear as shown in the image below.
Nothing is rendered in the side content panel. The REPL shows the function output as expected.
cadet-frontend
with a local server serving the static modules' JavaScript files.N/A
With all the recent breaking changes to the modules repository, a detailed documentation of how to properly use it is needed. This is especially so for module development teams who are going to start to move their modules into our system.
(from @ZhengHanLee)
anaglyph(show(scale(0.5, overlay(scale(0.25, orange(circle)), circle)))); shows error message "Error: show expects a rune as argument." instead of "Error: anaglyph expects a rune as argument."
See #80.
Unit testing capabilities have been added to the modules repository in pull request #37. This new feature requires documentation on how to create tests and how the tests are involved in the deployment flow of our modules.
Add a guide to teach creators of modules on how to pass functions from the bundle to the front end.
This is for more complex modules that require interactions with the tab's content (eg. curves, pixNFlix) or user interaction (eg. buttons)
this feature is not in the documentation: https://source-academy.github.io/modules/documentation/modules/curve.html
The function get_image_rune should be renamed to from_url.
Is your feature request related to a problem? Please describe.
We need to load the module asynchronously and somehow indicate to the user that module loading is in progress. This should be analogous to Sling sending a program to the robot.
Describe the solution you'd like
When there is a module load, we should do the following upon Run:
(1) indicate that module loading is in progress
(2) load the module(s) asynchronously
(3) when (2) is successful, indicate that module loading is done
(3) run the program
While (2) is under way, the user should be able to interact with the system.
Attempting to run the following snippet multiple times will result in Maximum call stack size exceeded
(at least on Chrome 84), but repeated attempts will eventually result in successful execution (usually 5 times, but sometimes a bit more).
Note that this program will likely cause your JS engine to run out of memory too.. but that might be a separate issue entirely. You'll know that it's running once the tab hangs.
function hook(frac) {
return beside_frac(
1 - frac,
stack(square, blank),
square);
}
function spiral(thickness, depth) {
return depth === 0
? blank
: stack_frac(
thickness,
hook(thickness * 0.5),
quarter_turn_right(spiral(thickness, depth - 1)));
}
function fractal(pic, n) {
return n === 1
? pic
: beside(
pic,
fractal(stackn(2, pic), n - 1));
}
show(fractal(spiral(1/5, 1000), 15));
Interestingly enough, each failed attempt to run that snippet will result in the aforementioned error occurring at a different line number -- usually one of -1, 2, 3, 4, or 14.
function cone(n, rune) {
const scale_factor = (n-1)/n;
return n === 0
? blank
: overlay_frac(scale_factor, scale(scale_factor, cone(n-1, rune)), rune);
}
anaglyph(cone(4, nova));
// hollusion(cone(4, nova));
Latest deployed master
We should ask all contributors of content to agree to that license
Now that we have an IMPORT node, I think we can load symbols from external libraries so that we achieve the effect of prepending functions while hiding their implementation.
We can still keep the PREPEND node for prepend programs that do not need to be hidden.
Is your feature request related to a problem? Please describe.
I'm always frustrated when TypeDoc API generator requires functions/mock functions to be defined in functions.ts
in the root directory of the Source Module Bundles.
I would like to change the default export function in Source Module Bundle's index.ts
to regular export function ...
for every function provided by the Source Module. The __params
should be changed into a global variable (ie. __dirname
).
Source Academy playground should be running smoothly.
Currently, while using the copy_gc
and mark_sweep
modules, Source Academy randomly crashes.
Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.
Please provide detailed steps for reproducing the issue.
violin/modules/master
to a new branch.yarn build
and yarn serve
.Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
Running display(array_length(src))
should return the height of the video/image.
Correct values are only returned when HEIGHT is set between 300 and 500. For any values <300 or >500, display(array_length(src))
returns 300.
Run the code in Q3 of the mission: Expected result: 150, Actual result: 300
const WIDTH = 400;
const HEIGHT = 150;
function zoom(factor) {
return (src, dest) => display(array_length(src));
}
install_filter(zoom(2));
set_dimensions(WIDTH, HEIGHT);
start();
The repeat
module's repeat()
function is said to take (func: Function, n: number)
as params, but its documented example only supplies a function, similar to twice()
.
repeat(x => x + 2)
Unable to change modules without refreshing. For example, if I first import from repeat, it works fine. Without refreshing, if I import curve again, it doesn't work.
under src/bundles/curve/index.ts
I defined curve as this.
function curve() {
return 'curve';
}
If I call curve()
it says Line 2: Calling non-function value undefined.
Note:
Same issues arises if I import curve then import repeat.
Issue does not arise if I try to change the functions I want to import from within the same module.
"enable verbose";
import { sample_function } from "asdasd";
import { repeat } from "repeat";
repeat(sample_function);
The code snippet above should result in the following error message returned in the REPL of Source Academy.
Line 3: Module "asdasd" not found.
The current behaviour of Source Academy is to crash the site with the logs attatched in the Failure Logs section of this issue.
js-slang
commit bf53d72, modules
commit a58c40a, cadet-frontend
commit d66683c.Unhandled Rejection (Error): The error you provided does not contain a stack trace.
▼ 4 stack frames were expanded.
S
C:/.../cadet-frontend/node_modules/react-error-overlay/lib/index.js:1
V
C:/.../cadet-frontend/node_modules/react-error-overlay/lib/index.js:1
(anonymous function)
C:/.../cadet-frontend/node_modules/react-error-overlay/lib/index.js:1
Module.oe
C:/.../cadet-frontend/node_modules/react-error-overlay/lib/index.js:1
▲ 4 stack frames were expanded.
(anonymous function)
C:/.../cadet-frontend/src/commons/sagas/SafeEffects.ts:22
19 |
20 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment
21 | // @ts-ignore
22 | import('react-error-overlay').then(reo => reo.reportRuntimeError(error));
| ^ 23 | }
24 | Sentry.captureException(error);
25 | console.error(error);
View compiled
This screen is visible only in development. It will not appear if the app crashes in production.
Open your browser’s developer console to further inspect this error. Click the 'X' or hit ESC to dismiss this message.
(from @ZhengHanLee)
hollusion is now much more subtle than it used to be. I personally prefer it to be drastic. What do prof think?
See #80.
For example, the following program
cone(4, circle);
should produce the following depth map:
This is misleading. It should say "show" or "anaglyph".
the notion of a "depth map" is also not necessary. There are simply 3-dimensional runes.
function initCurveBuffer(gl: any, func: (t: number) => Point, num: number) { ... }
In the function above, if func
is used in the function, eslint should not be highlighting any errors.
Eslint saying that t
is defined but never used, although func
is used somewhere in the function.
Please provide detailed steps for reproducing the issue.
.ts
file under src
directory.function initCurveBuffer(gl: any, func: (t: number) => Point, num: number) {
const num = 0;
for (let i = 0; i <= num; i += 1) {
const point = func(i / num);
}
}
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
N/A
When hollusion()
is run repeatedly, the browser starts to freeze and cpu consumption goes up.
hollusion(heart);
Then click run several times
CPU consumption goes up and browser become slow
Browser should not become slow
Pressing the buttons on the spawned pix n flix tab for the height and width should modify the dimensions of the video.
Nothing happens, buttons remain greyed off
Please provide detailed steps for reproducing the issue.
import { start } from 'pix_n_flix'; start();
With the possibility of importing multiple modules comes the need to resolve name clashes. For that, JavaScript allows "import as". Suggested syntax:
import-directive ::= imports { imports } from string;
imports ::= epsilon | import (, imports)...
import ::= name | name as name
We used to have a display_waveform function, see
source-academy/frontend#935
Would be nice to revive this
Add to the developer guide the detailed outline of the following:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.