-
Notifications
You must be signed in to change notification settings - Fork 108
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This reverts commit 42e184e.
7 tasks
RichDom2185
approved these changes
Apr 11, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
martin-henz
approved these changes
Apr 11, 2024
There was a problem hiding this 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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?)