Hacker News new | ask | show | jobs
by _Y_ 5317 days ago
What does cons operator mean? Concatenation? Constructor? Other than hello world I haven't done much Scala.
1 comments

Cons is short for construct and comes from Lisp which has weird names for things; things like car and cdr.

It means construct a new list.

A cons A (or A :: B) means create a new list with A before B, where B can be a list item or a list itself and A is a list item.

The :: operator is right associative so "Jim" :: "Bob" :: Nil actually works like ("Jim" :: ("Bob" :: Nil) ) (Actually all operators that end in : are right associative in Scala.)

For more see: http://en.wikipedia.org/wiki/Cons