Hacker News new | ask | show | jobs
by dreamcompiler 928 days ago
> But why not just make the indentation (or whatever that you really rely upon) the actual syntax, so there CANNOT be hidden bugs of that sort?

That's Python. When whitespace matters, any aesthetic reformatting mistake can change the program's meaning. With s-expressions this cannot happen. A lisp code parser is completely deterministic regardless of where the newlines, spaces, and tabs occur. You can remove all the newlines from a 10,000-line Lisp program and the compiler will parse it exactly the same as if it were formatted aesthetically.* You can also write a simple program that takes that godawful one-line program and reformats it aesthetically however you like--the meaning won't change.

IOW in Lisp the aesthetics of the source code do not determine its meaning; aesthetics and meaning are orthogonal properties and you are free to adjust the two independently. This is also somewhat true in languages like C, but rather than several special-case punctuation characters, in Lisp there's only one: The parenthesis. Lisp is thus similar in spirit to HTML where semantics and layout are [mostly] independent.

* With a few obvious exceptions like EOL comments, and newlines that are part of quoted strings.

1 comments

> any aesthetic reformatting mistake can change the program's meaning.

Why would you just randomly change indentation? On the contrary, I don't want the indentation to say something else than the code actually does.

> You can remove all the newlines from a 10,000-line Lisp program and the compiler will parse it exactly the same as if it were formatted aesthetically.

But a human won’t. And that’s a problem.

> Why would you just randomly change indentation? On the contrary, I don't want the indentation to say something else than the code actually does.

Because the user may want the development environment to display snippets of code in various places: REPL, debugger, code browsers, inspectors, various editor types, ...

In a Lisp system the code can be data and text. Code formatters can reformat code depending on user preferences, device types (color, font, ...), view sizes, ...

In Lisp often code gets generated (for example via 'Macros') and this code will be automatically layouted in various view (different widths, different fonts, different detail). Code can be small or large, the system may abbreviate parts, which one can expand, if necessary.

Source Code is not necessary static text in a file system. Code can just be list-based data structures and layout is fluid.

In Common Lisp the formatted output of code is also user extensible/customizable, a 'pretty printer' is a part of the language spec:

https://www.lispworks.com/documentation/HyperSpec/Body/22_ba...

If we read a text in a book reading the device, one can also change for example font size and the thing will relayout the text accordingly.