3 ms·
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 sections = [ "o
by pmontra 4y ago
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
sections = [
"one"
"two"
"three"
]
and separate with commas when you want to write something on the same line
sections = [
"one"
"two", "three"
]
- bstpierre 4y agoIn your first example you’re just using newlines as delimiters, the second is allowing either newline or comma.
- DougBTX 4y agoOr taking a Lisp perspective, atoms separated by white space.
- xcombelle 4y agosections: [ "one" "two" "three" ] and sections: [ "one" ["two" "three"] ] exists already and is named rebol (and their derivatives)
- Yahivin 4y agoThat'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 https://github.com/DanielXMoore/Civet
- allknowingfrog 4y agoRuby has an interesting syntax for defining arrays of literal values. irb(main):001:0> sections = %w(one two three) => ["one", "two", "three"]
- pmontra 4y agoI 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.