Skip to content

Separate program values from their representations #1651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 65 commits into from
Apr 12, 2024

Conversation

s-kybound
Copy link
Member

@s-kybound s-kybound commented Apr 8, 2024

This PR extends the Result type with an optional Representation field, as long as a Result Value is present. This is done to allow alternate languages (aside from JS) to provide their own data representations for values whilst preserving the actual data passed.

For example, arrays in JavaScript are represented as [1, 2, 3, 4]. The corresponding vector (array equivalent in scheme) should be represented as #(1 2 3 4). This PR allows the new representation to be stored separately from the value returned (which is still a JS array).

After a program is run, the result will be mapped by the mapResult() function, which checks the language used in the context to run the appropriate result mapper. Ideally, languages will add their own logic into the mapResult() function (located in src/alt-langs/mapper.ts).

This PR is also non-invasive. If an alternate representation is not needed (the case for Source/JS/TS) or not implemented, js-slang defaults to using the original representation for the value.

(as a side note, this PR also tags all scheme pairs so that they are distinguishable from scheme vectors (despite both being represented using arrays) - a possible enhancement that can be brought to js-slang too?)

s-kybound and others added 30 commits March 7, 2024 06:27
Copy link
Member

@RichDom2185 RichDom2185 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Copy link
Member

@martin-henz martin-henz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat integration of scm-slang into js-slang.

@martin-henz martin-henz merged commit ea7aee9 into source-academy:master Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants