Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected result of scala.io.Source.fromFile(...).mkString(",") evaluation #6592

Closed
scabug opened this Issue Oct 30, 2012 · 5 comments

Comments

Projects
None yet
2 participants
@scabug
Copy link

scabug commented Oct 30, 2012

I've 2 files that have only one difference - "\r\n" sequence in the test.txt
[vladimir@vladimir tmp]$ cat test.txt
line1
line2
line3
[vladimir@vladimir tmp]$ cat test2.txt
line1
line2
line3[vladimir@vladimir tmp]$

I try to execute in the REPL:

scala> scala.io.Source.fromFile("/tmp/test.txt").mkString(",")
res17: String =
,l,i,n,e,1,
,l,i,n,e,2,
,l,i,n,e,3,
"

scala> scala.io.Source.fromFile("/tmp/test2.txt").mkString(",")
res18: String =
,,i,n,e,1,
,l,i,n,e,2,
,l,i,n,e,3

scala>

As you can see, for test2.txt file the first "l" character ommited. I think, that it isn't expected behaviour.

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Oct 30, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6592?orig=1
Reporter: Vladimir Kuptsov (vkuptcov)
Attachments:

  • test.txt (created on Oct 30, 2012 1:32:25 PM UTC, 21 bytes)
  • test2.txt (created on Oct 30, 2012 1:32:25 PM UTC, 19 bytes)
@scabug

This comment has been minimized.

Copy link
Author

scabug commented Oct 30, 2012

Alexei Tereschenko (aytereschenko) said (edited on Oct 30, 2012 1:47:35 PM UTC):
If I run the following code from an IDE, not from REPL:

object Test {
  def main(args: Array[String]) = {
    println(scala.io.Source.fromFile("/tmp/test.txt").mkString(","))
    println(scala.io.Source.fromFile("/tmp/test2.txt").mkString(","))
  }
}

then I receive the following output:

,
,
,l,i,n,e,3
,
,
,
@scabug

This comment has been minimized.

Copy link
Author

scabug commented May 20, 2013

@JamesIry said:
2.10.2 is about to be cut. Kicking down the road and un-assigning to foster work stealing.

1 similar comment
@scabug

This comment has been minimized.

Copy link
Author

scabug commented May 20, 2013

@JamesIry said:
2.10.2 is about to be cut. Kicking down the road and un-assigning to foster work stealing.

@scabug

This comment has been minimized.

Copy link
Author

scabug commented May 19, 2014

@som-snytt said:
This is as expected, or to be expected, or, as the doctors say, as well as could be expected.

The "\r," sequence places a comma in the first column of the terminal.

The difference between the two strings is that one ends in whitespace, so REPL displays it in quotes; the open quote is overstruck instead of the first char of text.

scala> scala.io.Source.fromFile("test2.txt").mkString(",") map { case '\r' => '*' case c => c }
res0: String =
l,i,n,e,1,*,
,l,i,n,e,2,*,
,l,i,n,e,3

scala> "a b c"
res1: String = a b c

scala> "a b c "
res2: String = "a b c "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.