peculiar assignment schemes and repl responses

15 views
Skip to first unread message

archsky

unread,
Nov 20, 2015, 12:31:15 AM11/20/15
to scala-user
hi

consider following test cases, with particular attention to whitespaces

scala> def test1 = {"this is sit"}
test: String

scala> test1
res21: String = this is sit



scala> def test2 = { "this is sit" }
test2: String

scala> test2
res22: String = this is sit



scala> def test3 = { " this is sit " }
test3: String

scala> test3
res23: String = " this is sit "



scala> def test4 = {" this is sit "}
test4: String

scala> test4
res24: String = " this is sit "



basically,
in test1 and test2, there is no whitespace between the quotation marks and the enclosed strings
in test3 and test4, there is 01 whitespace between the quotation marks and the enclosed strings

in former two, repl responds without quotes, and in latter two repl responds with quotes.
is there a logic behind (a syntactic convention perhaps) by the virtue of which the repl response changes in the former two and latter two cases, and should we (as developers) be wary of such a thing??

Haoyi Li

unread,
Nov 20, 2015, 12:36:24 AM11/20/15
to archsky, scala-user
I'd guess it's intended behavior to make the spaces at the start and end more obvious.

FWIW the Ammonite REPL appears to do the more consistent thing all the time

@ def test1 = {"this is sit"}
defined function test1
@ test1
res10: String = "this is sit"
@ def test2 = { "this is sit" }
defined function test2
@ test2
res12: String = "this is sit"
@ def test3 = { " this is sit " }
defined function test3
@ test3
res14: String = " this is sit "
@ def test4 = {" this is sit "}
defined function test4
@ test4
res16: String = " this is sit "



--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jasper-M

unread,
Nov 20, 2015, 4:27:29 AM11/20/15
to scala-user
What is the thing with the curly braces supposed to show?

Op vrijdag 20 november 2015 06:31:15 UTC+1 schreef archsky:
Reply all
Reply to author
Forward
0 new messages