Skip to content

Instantly share code, notes, and snippets.

@0xYUANTI
Created July 7, 2014 13:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xYUANTI/69c50ace9a5d888c9a48 to your computer and use it in GitHub Desktop.
Save 0xYUANTI/69c50ace9a5d888c9a48 to your computer and use it in GitHub Desktop.
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.10.4 (OpenJDK 64-Bit Server VM, Java 1.6.0_32).
Type in expressions to have them evaluated.
Type :help for more information.
scala> def f = 1
def f = 1
f: Int
scala> f
f
res0: Int = 1
scala> f()
f()
<console>:9: error: Int does not take parameters
f()
^
scala> (f _)
(f _)
res2: () => Int = <function0>
scala> (f _)()
(f _)()
res3: Int = 1
scala> def g() = 2
def g() = 2
g: ()Int
scala> g
g
res4: Int = 2
scala> g()
g()
res5: Int = 2
scala> (g _)
(g _)
res6: () => Int = <function0>
scala> (g _)()
(g _)()
res7: Int = 2
scala> val h = () => 3
val h = () => 3
h: () => Int = <function0>
scala> h
h
res8: () => Int = <function0>
scala> h()
h()
res9: Int = 3
scala> (h _)
(h _)
res10: () => () => Int = <function0>
scala> (h _)()
(h _)()
<console>:9: error: _ must follow method; cannot follow h.type
(h _)()
^
scala>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment