Re:Delimiter-first code
by pmontra on Friday December 09, 2022 @06:05AM
(#33920035)
Or no delimiter at all in case there are no ambiguities to solve. Make a language that knows that different lines are for different stuff
and separate with commas when you want to write something on the same line
[ Parent
| on HN ]
sections: [
"one"
"two"
"three"
]
and sections: [
"one"
["two" "three"]
]
exists already and is named rebol (and their derivatives)In your first example you’re just using newlines as delimiters, the second is allowing either newline or comma.
Or taking a Lisp perspective, atoms separated by white space.
That's how I do it in Civet (the CoffeeScript of TypeScript). It's a very small amount of complexity to add to the parser for a ton of convenience when using the language. https://github.com/DanielXMoore/Civet
Re:Delimiter-first code
by allknowingfrog on Friday December 09, 2022 @11:51AM
(#33923492)
Ruby has an interesting syntax for defining arrays of literal values.
irb(main):001:0> sections = %w(one two three)
=> ["one", "two", "three"]I know and it works on multiple lines too. However I never use it. Requirements change, refactoring happens, one of those literals becomes an interpolated string and all of a sudden I have to rewrite all the array. Furthermore %w() is just not nice to look at IMHO.