js-slang icon indicating copy to clipboard operation
js-slang copied to clipboard

String representation is not language dependent

Open RichDom2185 opened this issue 1 year ago • 3 comments

When running Python, string representations are still following Source/JS notation:

image

Ideally, the REPL should show

lambda x: func(repeat(func, n - 1)(x))

as the program output instead.

Perhaps related to how stringify in src/utils/stringify.ts is implemented?

RichDom2185 avatar May 17 '23 08:05 RichDom2185

For the most part, JS and Python have overlapping representations where the complex stuff lies (arrays, dictionaries/objects and other nested data structures). So it would be good to reuse most of the existing code.

The main difference are the language constructs. For Python S1, the following need different representation:

  1. functions (as you pointed out)
  2. if-else
  3. ternary
  4. "blocks"

We need a rather big refactor of the stringify function to make it language aware. CS2030S tells me that we shouldn't be adding if-else cases and instead should make a new subclass that contains these methods :).

Fidget-Spinner avatar Jul 20 '23 12:07 Fidget-Spinner

Haha, fair enough. Need to see what's the canonical Python representation of estrees. I think we can work something out if we are willing to be a bit generous.

martin-henz avatar Jul 20 '23 12:07 martin-henz

@martin-henz perhaps we could take a look at this issue together with the plans you mentioned to apply the visitor pattern to js-slang?

RichDom2185 avatar Jul 20 '23 13:07 RichDom2185