ngs-lang / ngs

Next Generation Shell (NGS)
https://ngs-lang.org/
GNU General Public License v3.0
1.49k stars 41 forks source link

Consider quoting non-top-level strings in echo() #622

Open MinmoTech opened 1 year ago

MinmoTech commented 1 year ago

From discussion on discord:

NGS does not print quotes around strings in arrays, while python does:

ngs -e 'echo(["1"])'
[1]
ngs -e 'echo([1])'
[1]
ngs -e 'echo("1")'
1
ngs -e 'echo(1)'
1
python -c 'print([9])'
[9]
python -c 'print(["9"])'
['9']
python -c 'print(9)'
9
python -c 'print("9")'
9

This can be surprising behavior (it was for me).

NGS also has echo(code(EXPR)) as an alternative:

ngs -e 'echo(code(["9"]))'
['9']
ngs -e 'echo(code([9]))'
[9]
ngs -e 'echo(code(9))'
9
ngs -e 'echo(code("9"))'
'9'
ilyash-b commented 1 year ago

Thinking and gathering information.

$ node -e 'console.log([1,"2"])'
[ 1, '2' ]

$ ruby -e 'puts [1,"2"]'
1
2

$ python3 -c 'print([1, "2"])'
[1, '2']

# Raku, online
print [1, "a"]
1 a