[racket] newlines in strings not the same in DrRacket and Racket

From: Dr. Nikolaus Klepp (office at klepp.biz)
Date: Sat Jun 21 05:19:53 EDT 2014

You are using Windows?


Am Samstag, 21. Juni 2014 schrieb Jos Koot:
> 
> I find the following:
> 
> (write (string->list #<<end
> a
> a
> end
> ))
> 
> In DrRacket (#\a #\newline #\a)
> In Racket: (#\a #return #\newline #\a #\return)
> 
> Jos
> 
> 
> > -----Original Message-----
> > From: Robby Findler [mailto:robby at eecs.northwestern.edu] 
> > Sent: sábado, 21 de junio de 2014 8:29
> > To: Jos Koot
> > Cc: Alexander D. Knauth; users
> > Subject: Re: [racket] newlines in strings not the same in 
> > DrRacket and Racket
> > 
> > I think that here strings are parsed in a way to make the
> > line-separator difference not matter too. Maybe that works best for
> > you?
> > 
> > http://docs.racket-lang.org/reference/reader.html#%28idx._%28g
> entag._54._%28lib._scribblings%2Freference%2Freference..scrbl%> 29%29%29
> > 
> > Robby
> > 
> > On Sat, Jun 21, 2014 at 1:25 AM, Jos Koot <jos.koot at gmail.com> wrote:
> > > Thanks Robby, that's clear.
> > > I often copy results from the interactions window to the 
> > definitions window
> > > of DrRacket.
> > > After reverting my preference file to defaults and 
> > reselecting my personal
> > > preferences, the problem has disappeared.
> > > Nevertheless I'll avoid the problem for the future. Four 
> > options I think:
> > > 1: stick to your string-append advice.
> > > 2: @ notation of scribble (which I have to try out yet, but 
> > may well be
> > > preferable)
> > > 3: replace all newlines in strings by \n (not nice for it 
> > makes the text
> > > less readable)
> > > 4: my trick to remove #\return from strings before comparing them.
> > > Thanks, Jos
> > >
> > >
> > >> -----Original Message-----
> > >> From: Robby Findler [mailto:robby at eecs.northwestern.edu]
> > >> Sent: sábado, 21 de junio de 2014 0:51
> > >> To: Alexander D. Knauth
> > >> Cc: Jos Koot; users
> > >> Subject: Re: [racket] newlines in strings not the same in
> > >> DrRacket and Racket
> > >>
> > >> The issue is probably that the file is being saved with 
> > CRLF. When the
> > >> file is opened in DrRacket, DrRacket always treats 
> > newlines like that
> > >> as if there were the "\n" character. But when racket reads 
> > the file it
> > >> just puts whatever bytes are in the saved file into the string.
> > >>
> > >> The best path forward: don't use actual newlines in literals (like
> > >> strings). Instead write things like:
> > >>
> > >> (string-append "first line\n" "second-line\n")
> > >>
> > >> Or use scribble's @ notation.
> > >>
> > >> Robby
> > >>
> > >>
> > >> On Fri, Jun 20, 2014 at 5:20 PM, Alexander D. Knauth
> > >> <alexander at knauth.org> wrote:
> > >> > Or are you using different editors?  Different editors
> > >> might use different
> > >> > conventions for representing newlines.
> > >> >
> > >> > When the 32 bit one has the problem, what does it say?
> > >> >
> > >> > For example when I made the text file with DrRacket or
> > >> TextEdit but ran it
> > >> > with racket (not DrRacket), it worked,
> > >> > but when I made the text file with Microsoft Word, it 
> > gave me this:
> > >> > $ racket newline-3.txt
> > >> > (format "~n") = "\n"
> > >> > "
> > >> > " = "\r"
> > >> > Ran 1 check.
> > >> > 0 checks passed.
> > >> > Actual value
> > >> > , the expected value.
> > >> >  In newline-3.txt at line 7 column 0
> > >> >
> > >> > On Jun 20, 2014, at 5:14 PM, Jos Koot <jos.koot at gmail.com> wrote:
> > >> >
> > >> > Very strange.
> > >> > I did the same on my other computer and there it has the
> > >> same problem as
> > >> > before.
> > >> > I use windows 7 on both systems one with 64 bit OS and one
> > >> with 32 bit OS.
> > >> > The 64 bit version does well, the 32 bit windows 7 system
> > >> has the problem.
> > >> > May be my preferences?
> > >> > Thanks, Jos
> > >> >
> > >> > -----Original Message-----
> > >> > From: Jos Koot [mailto:jos.koot at gmail.com]
> > >> > Sent: viernes, 20 de junio de 2014 23:03
> > >> > To: 'Alexander D. Knauth'
> > >> > Cc: 'users'; 'Jos Koot'
> > >> > Subject: RE: [racket] newlines in strings not the same in
> > >> > DrRacket and Racket
> > >> >
> > >> > Gives me
> > >> >
> > >> > (format "~n") = "\n"
> > >> > "
> > >> > " = "\n"
> > >> > The only test passed!
> > >> >
> > >> > both in DrRacket and Racket.
> > >> > Very surprising. Can you explain what happens here?
> > >> > I don't have a clue.
> > >> > Thanks,
> > >> > Jos
> > >> >
> > >> >
> > >> > ________________________________
> > >> >
> > >> > From: Alexander D. Knauth [mailto:alexander at knauth.org]
> > >> > Sent: viernes, 20 de junio de 2014 22:41
> > >> > To: Jos Koot
> > >> > Cc: users
> > >> > Subject: Re: [racket] newlines in strings not the same
> > >> > in DrRacket and Racket
> > >> >
> > >> >
> > >> > This doesn't exactly solve your problem, but what
> > >> > happens (for both cases) when you do this?:
> > >> > #lang racket
> > >> > (require test-engine/racket-tests)
> > >> > (display "(format \"~n\") = ") (format "~n")
> > >> > (display "\"") (newline)
> > >> > (display "\" = ") "
> > >> > "
> > >> > (check-expect (format "~n") "
> > >> > ")
> > >> > (test)
> > >> > (void (read-line)) ; wait until the user has read the results.
> > >> >
> > >> > On Jun 20, 2014, at 3:02 PM, Jos Koot
> > >> > <jos.koot at gmail.com> wrote:
> > >> >
> > >> >
> > >> > Running the following in DrRacket goes well.
> > >> >
> > >> > #lang racket
> > >> > (require test-engine/racket-tests)
> > >> > (check-expect (format "~n") "
> > >> > ")
> > >> > (test)
> > >> > (read-line) ; wait until the user has read the results.
> > >> >
> > >> > Displays: The only test passed!
> > >> >
> > >> > But running the same with Racket tells me the
> > >> > test fails.
> > >> > I have a solution for this by removing #\return
> > >> > from the strings to be
> > >> > compared.
> > >> >
> > >> > Question though: Can I solve this problem in a
> > >> > simpler way?
> > >> > May be I overlooked something in the docs?
> > >> >
> > >> > Best wishes, Jos
> > >> >
> > >> >
> > >> > ____________________
> > >> > Racket Users list:
> > >> > http://lists.racket-lang.org/users
> > >> >
> > >> >
> > >> >
> > >> >
> > >> >
> > >> >
> > >> >
> > >> > ____________________
> > >> >   Racket Users list:
> > >> >   http://lists.racket-lang.org/users
> > >> >
> > >
> 
> 
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
> 
> 



-- 
Please do not email me anything that you are not comfortable also sharing with the NSA.


Posted on the users mailing list.