source-academy / js-slang

Implementations of sublanguages of JavaScript, TypeScript, Scheme and Python
https://source-academy.github.io/source/
Apache License 2.0
64 stars 102 forks source link

print: display string in REPL without quotation marks #1664

Open martin-henz opened 2 months ago

martin-henz commented 2 months ago

Currently

display(1.5, "abc")

prints:

abc 1.5

and

display("cde", abc")

prints:

abc: "cde"

This works quite well, with the exception that sometimes, I want to display a (possibly multi-line) string without quotation marks, and without a value coming after it. I propose that we introduce print(string):

print("**********************************************\n*** the program entered the main algorithm ***"\n*********************************************")

should just display

**********************************************
*** the program entered the main algorithm ***
**********************************************

without quotation marks.

RichDom2185 commented 2 months ago

obsolete:

What happens if we want to display the actual value undefined?

martin-henz commented 2 months ago

obsolete:

What happens if we want to display the actual value undefined?

A small hack would be needed:

display(value, "the value is:" + (is_undefined(value) ? " undefined" : ""))