val list = a +: l :+ b
And I knew I had to put in a comment because that stuff always makes my eyes cross over when I come back to it. val list = a +: l :+ b
And I knew I had to put in a comment because that stuff always makes my eyes cross over when I come back to it.But they're just method calls, both defined on the class of l. It is a little weird.
l.prepend(a).append(b)
Horrible. Ghastly. Can't see anybody tolerating a language that looked like that.. /s l prepend a append ba.append(l).append(b)
?
もっと練習 ⍝ Practice more NB. ⍝ is a symbol for comment.
/* NB. is for comment, too. */
// Anything inside /* */ is comment, too.
# // starts a comment, too. a ? b : c
construct which maybe was equally puzzling when it was introduced by CPL in 1963."a +: l" calls the +: method on l with a as its argument and returns a list with a added to the start, "l :+ b" calls the :+ method on l with b as its argument and returns a list with b added to the end. "a +: l :+ b" (parsed as "(a +: l) :+ b") therefore returns a copy of l with a added to the start and b added to the end.
This is user definable, you can make operators whichever way you like (and start them with : if you want them to be right associative).
It's very flexible and you do sort of get used to libraries using it, but I'm not entirely sure that getting used to something always means it's good.
(TBH though, I use the ternary operator constantly and think nothing of it.)