3 ms·
Great write up! One small picky thing: > Scala: def test = {"hello world"} Can be actually def test = "hello world" :) p.s. you can play with Scala
by eranation 13y ago
Great write up!
One small picky thing:
> Scala: def test = {"hello world"}
Can be actually
def test = "hello world"
:)
p.s. you can play with Scala code live in the browser here:
http://scalatutorials.com/tour/ http://scalatutorials.com/tour/ (work in progress)
- dxbydt 13y agoTo get parity with his PHP & Java snippets, you probably want one of several variants below - scala> def test1 = println ("hello world") scala> def test2(f: =>Unit) = println ("hello world") scala> def test3(f:Unit) = println ("hello world") scala> test1 hello world scala> test2() hello world scala> test3() hello world scala> val t = test2 _ scala> t apply Unit hello world scala> t() hello world scala> t(()) hello world I will leave it as an exercise to the reader to distinguish between these thunks :)
- eranation 13y ago:) See also this question: http://stackoverflow.com/questions/8303817/nine-ways-to-define-a-method-in-scala http://stackoverflow.com/questions/8303817/nine-ways-to-defi... It can go quite crazy on function definition styles: val add:(Int,Int)=>Int = _ + _ (from http://scalatutorials.com/tour/12_tour_of_scala_anonymous_functions_2.html http://scalatutorials.com/tour/12_tour_of_scala_anonymous_fu...)
- neya 13y agoOh noes, I purposely avoided this variation because I didn't want readers to think functions don't have braces AT ALL. :)Thanks for your input!