6 ms·
Alt opinion: syntax is the least important part of a programming language. I can't wait for the day someone invents one where it's defined entirely as an AST (w
by dmit 7mo ago
Alt opinion: syntax is the least important part of a programming language. I can't wait for the day someone invents one where it's defined entirely as an AST (with the S standing for Semantic). Just bring your own weird syntax.
I guess Unison is the closest to this platonic ideal right now? https://github.com/unisonweb/unison/issues/499 https://github.com/unisonweb/unison/issues/499
- geocar 7mo agoI completely agree: If it is ugly-as-sin-but-useful I will learn it. The aesthetic of mathematics as it appears in journals is I think questionable, but undeniably convenient for communication, so it is every language making the case that you (dear reader) can say something very complicated and useful in the ideal amount of space. "Hello world" isn't that: That's the one program everyone should be able to write correctly, 100% of the time. That's how we can talk about brainfuck as exercise, but APL is serious. Or put another way, even if seeing a new kind of "hello world" excites dear reader, it's probably not going to excite me, unless it's objectively disgusting. What Om does here is exactly right for me: It tells me what it is, and makes it easy for me to drill down to each of those things to figure out what the author means by that, and decide if I am convinced. I mean, that's the point right? I'm here trying to learn something new and that requires I allow myself to be convinced, and since "hello world" is table-stakes, seeing it can only slow my ability to be convinced.
- pjmlp 7mo agoI have an idea, maybe we could represent that AST as parenthesis.
- ocimbote 7mo agoHonestly, we can do better than LISPs. Just use curly brackets and boom. LISP 3k. You're welcome.
- pjmlp 7mo agoIt can even be used to represent serialized objects...
- itishappy 7mo agoThat's cool, but I might prefer semantic whitespace. Sure would be neat if we could both work with the same code in our preferred forms.
- itishappy 7mo agoLove this take! Unison is exactly this, and it's awesome! Here's a quote from one of the creators: > But here's the super cool thing about our language! Since we don't store your code in a text/source code representation, and instead as a typechecked AST, we have the freedom to change the surface syntax of the language very easily, which is something we've done several times in the past. We have this unique possibility that other languages don't have, in that we could have more than one "surface syntax" for the language. We could have our current syntax, but also a javascript-like syntax, or a python-like syntax. https://news.ycombinator.com/item?id=46053304 https://news.ycombinator.com/item?id=46053304
- fuzztester 7mo agoCan Raku do something like this? I was lightly exploring it recently, and I thought I saw that something like this may be possible with it.
- itishappy 7mo agoI'm not super familiar with Raku, but if RakuAST is what you had in mind it looks a bit different: use experimental :rakuast; my $ast = RakuAST::Call::Name.new( name => RakuAST::Name.from-identifier("say"), args => RakuAST::ArgList.new( RakuAST::StrLiteral.new("Hello world") ) ); Looks more like "low-level programming an AST" (which I believe other languages offer as well), rather than using a bidirectional transform. I don't know how you'd get Raku code back out, for example. Edit: I should have looked deeper, `DEPARSE` does exactly this: https://docs.raku.org/type/RakuAST https://docs.raku.org/type/RakuAST Neat!
- lizmat 7mo agoIt also goes from source code to AST: $ raku -e 'say Q|say "Hello World!"|.AST' RakuAST::StatementList.new( RakuAST::Statement::Expression.new( expression => RakuAST::Call::Name::WithoutParentheses.new( name => RakuAST::Name.from-identifier("say"), args => RakuAST::ArgList.new( RakuAST::QuotedString.new( segments => ( RakuAST::StrLiteral.new("Hello World!"), ) ) ) ) ) )
- phailhaus 7mo agoThis is a Very Bad Idea. Two people working with the same language will be unable to reason about each other's code, because it requires understanding their bespoke syntax and its nuances.
- dmit 7mo agoNo it won't? That's exactly the point -- each of those people will be viewing the code in their own preferred syntax. If there is semantic nuance in the writer's syntax, the reader will see it presented in the best way their preferred syntax's representation can provide. Imagine all the hours saved that are currently spent on tired tabs vs spaces debates, or manicuring .prettierrc, etc etc. The color of the bike shed might matter (sometimes a lot) to some people, I know, but it's storing bikes away from the elements and thieves that is the goal, not obsessing over optimizing something that is demonstrably a subjective matter of taste.
- deleted 7mo ago[deleted]
- phailhaus 7mo agoThose are both formatting examples though? You're suggesting totally different syntaxes, which means you can't even point to the same line in a codebase when talking about a PR. This throws up massive hurdles around communication when you could just agree on one standard and move on.
- dmit 7mo agoclass Bean { private boolean sprouted; public void sprout() { this.sprouted = true; // ... } } or data Bean = Dormant | Sprouted sprout :: Bean -> Bean sprout Dormant = Sprouted sprout Sprouted = -- aw, beans, we could have modeled -- this state as impossible to construct, -- but you chose runtime checks, so -- here we are. As for pointing to the source line, I think JavaScript people solved that one for us with source maps. Just because we download and execute a single 4Mb line of minified code, doesn't mean we can't tell which line of the original source caused the error. :)