By now you might have heard the good news that #rstats is getting a new shorthand function syntax. Soon you'll be able to write the following in R!
add <- \\(x, y) x + y
But why does this new syntax use the backslash?
(A thread. 1/n)
add <- \\(x, y) x + y
But why does this new syntax use the backslash?
(A thread. 1/n)
The \\(x,y) x + y syntax might look odd, but is borrowed (as far as I know) from perhaps the most functional of all programming languages - Haskell - where a similar syntax is used (with the addition of an -> arrow).
But why the backslash?
(2/n)
But why the backslash?
(2/n)
Modern Javascript doesn't use a backslash for shorthand function definitions and neither does python. But python gives us a clue! Why does python use the lambda keyword?
(3/n)
(3/n)
Because of the lambda calculus! "[A] formal system in mathematical logic for expressing computation based on function abstraction" ( https://en.wikipedia.org/wiki/Lambda_calculus) where function definitions use the greek lambda:
λxy. x + y
But why the backslash in R and Haskell?
(4/n)
λxy. x + y
But why the backslash in R and Haskell?
(4/n)
Well, the λ is hard to write on US keyboards and is not part of the characters in the ASCII encoding. And if you squint a \\ kinda looks like half a λ.
(5/n)
(5/n)
So, the new function shorthand in R uses the backslash because Haskell wanted lambda functions, but didn't want to write "lambda" out as python, but couldn't use a real λ, and instead had to use a \\ 
Btw, I really look forward to having this new syntax in R!
(6/n)

Btw, I really look forward to having this new syntax in R!

(6/n)
Oh, and why did Alonzo Church use the λ when he created the lambda calculus? "For ease of printing"
( https://en.wikipedia.org/wiki/Lambda_calculus)
It's turtles all the way!
(7/n)

( https://en.wikipedia.org/wiki/Lambda_calculus)
It's turtles all the way!
(7/n)