Not_Quite_JS.txt 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. The language supported in this workspace is not quite JavaScript; it is rather a (large) subset of JavaScript, extended with some
  2. new syntax.
  3. One such extension allows string literals to be written as
  4. '`' <identifier> or '#' <identifier>
  5. For example, instead of writing
  6. "foo"
  7. you can write
  8. `foo
  9. And of course,
  10. "foo" == `foo && `foo == #foo
  11. I did this because I think parse trees, like
  12. ["plus", ["lit", 2], ["lit", 5]]
  13. look better when you write them like this
  14. [`plus, [`lit, 2], [`lit, 5]]
  15. Another extension is that string literals, as in Smalltalk, can span multiple lines, e.g.,
  16. " this whole thing
  17. is a string
  18. yay!
  19. "
  20. This is useful because it lets you put an entire program into a string (I do this in the Prolog, Logo, and MetaToo projects). Keep in mind that, as in Python, you can put escape sequences inside multi-line strings. So if you want a '\' character inside one of these guys, you need to type '\\'.
  21. And because it's usually annoying to have to escape double quotes inside these big strings, you can also write multi-line string literals in Python-like syntax, e.g.,
  22. """
  23. 1+2
  24. alert("hello world")
  25. """
  26. -Alex
  27. ------------------------------------------------------------------------------------------------------------------------------------
  28. Hey, Alex -- How about using a symbol that is less in one's face than "#"? What about tilde ~ or ` or underline, etc.? -- Alan
  29. Hi Alan - this is funny, because the # was inspired by ST-80, heh heh... anyway, I like the idea of using ` instead. Try it now, it works. --- Alex
  30. Hi Alex -- I have always hated that convention in ST-80 (I was not around to protest when that went in). ST-80 had the interesting problem of moving from an environment at PARC in which any glyphs desired could be authored, displayed and printed, to the "outside world" in the early 80s in which none of those things could be done. So they had to go back to ASCII conventions and this was painful. Thanks for the change. --- Alan