Suggestion: Is it possible for Elixir to pick it's line-break character(s) from the host platform?

704 views
Skip to first unread message

Charles Okwuagwu

unread,
Nov 14, 2015, 1:27:44 PM11/14/15
to elixir-lang-core
Is it possible for Elixir to pick it's line-break character(s) from the host platform?

Alternatively,can we have flexibility in specifying the line-break character(s) for File module operations?

See this comment to a question I posted recently on Stack-overflow:

"Given that Elixir started on Macs and Linux the issue of the line break isn't terribly surprising. I think you should submit a PR to allow the line break to be picked up from the platform. No joke. – Onorio Catenacci"





José Valim

unread,
Nov 15, 2015, 5:14:14 AM11/15/15
to elixir-l...@googlegroups.com
Sorry, but I don't follow the issue.

Elixir already works with \n and \r\n transparently. I don't see why one would want to specify the line breaks in this case. Can you please paste exactly which output you are getting and let us know which output you were expecting?



José Valim
Skype: jv.ptec
Founder and Director of R&D

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/2bc77493-f29c-40ac-a708-35211eb27eb8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Charles Okwuagwu

unread,
Nov 15, 2015, 5:43:23 AM11/15/15
to elixir-lang-core, jose....@plataformatec.com.br
I have included an sample of the file i am trying to load in windows. the line end is \r\n.

when loaded with File.read!, i see :

iex(2)> File.read! "D:\\Projects\\sample.txt"  
"1039027537039357001\r\n1124138842463513719\r\n1137145765766942221\r\n1159807134726147157\r\n1162386423249503807\r\n1166092057686212149\r\n1192934946182607263\r\n1239437837009623463\r\n1242249431735251217\r\n1286092661601003031\r\n1300223652350017207\r\n1320700236992142661\r\n1322986082402655259\r\n1342729635050601557\r\n1342815051384338027\r\n1361578683715077199\r\n1381265403472415423\r\n1387654405700676857\r\n1414719090657425471\r\n1438176310698548801"
iex(4)> File.stream!("D:\\Projects\\sample.txt") |> Enum.to_list
["1039027537039357001\n", "1124138842463513719\n", "1137145765766942221\n",
 "1159807134726147157\n", "1162386423249503807\n", "1166092057686212149\n",
 "1192934946182607263\n", "1239437837009623463\n", "1242249431735251217\n",
 "1286092661601003031\n", "1300223652350017207\n", "1320700236992142661\n",
 "1322986082402655259\n", "1342729635050601557\n", "1342815051384338027\n",
 "1361578683715077199\n", "1381265403472415423\n", "1387654405700676857\n",
 "1414719090657425471\n", "1438176310698548801"]
iex(5)> 

The File.stream! default :line option should remove both \r\n, not just \r

You see my point?
sample.txt

Charles Okwuagwu

unread,
Nov 15, 2015, 5:44:56 AM11/15/15
to elixir-lang-core, jose....@plataformatec.com.br
**** a sample, (not an sample)**** sorry

José Valim

unread,
Nov 15, 2015, 5:47:22 AM11/15/15
to Charles Okwuagwu, elixir-lang-core
Thank you!

The current behaviour is correct, it is just a different in semantics. File.stream is not removing "\r", it is *normalizing* all line breaks into "\n" so the developer writing the code does not need to worry about both kinds of line breaks. This is also what happens when using the IO functions to read from IO devices. You can just remove the "\n" if you don't care about it.



José Valim
Skype: jv.ptec
Founder and Director of R&D

Charles Okwuagwu

unread,
Nov 15, 2015, 5:56:11 AM11/15/15
to José Valim, elixir-lang-core

Ah, I see.

You normalize, but you still keep \n as part of the separated strings.

I was expecting the behaviour to be similar to split, which removes the splitting character(s).

Thanks for the clarification.

Sent from TypeMail

Reply all
Reply to author
Forward
0 new messages