[racket] Error when pasting code

From: George Neuner (gneuner2 at comcast.net)
Date: Wed Mar 18 01:15:14 EDT 2015

Hi Steve,

On Tue, 17 Mar 2015 22:27:38 +0000 (UTC), Steve Graham 
<jsgrahamus at yahoo.com> wrote:

>   Your unicode comment made me wonder.  So I wrote out some code to
>the repl and it "compiled" and ran fine.  Next I copied that code to
>Notepad and then copied and pasted it back to the repl and it "compiled"
>and ran fine.  Finally I google "scheme factorial" and copied what I
>found to the repl and there I had problems.

I have seen a few editions of DrRacket [including 6.1.1 release] hang
or crash loading a source file that has an embedded UTF BOM header.
CLI racket or raco will complain about the module language being
unknown or not found [can't remember the exact message], so if the
file otherwise looks correct, that is a quick test for the header
being present.

If DrRacket does manage to load the file, you'll see a couple of weird
glyphs (that can't be removed!) at the beginning.

Only solution is to use another editor to remove the header.  May be
just my luck, but I haven't yet found an editor that will remove an
existing BOM header just by saving to a different format.  I use the
hex/bin function of my code editor to manually remove the header

The compiler - at least in conjunction with DrRacket - also doesn't
much like multi-byte characters.  As you have discovered, sometimes
things which visually appear to be correct just won't compile.

My solution, if that happens, is to load the file in a different
editor, resave it as Western (ISO-8859-1) to quickly clean up as much
as possible and then retype in DrRacket any lines that still produce
syntax errors.

I have never investigated whether the compile problem is only in
conjunction with the Dr editor or is pervasive.  I generally do a lot
of testing/tweaking in the debug environment before moving to CLI
racket.  By that time I no longer have the compile problem.  

Unfortunately, I don't encounter either unicode problem very often,
and when I do it tends to be when I'm really busy, so I just deal with
it and forget about bug reports.  Yeah, I know. Selfish  8-(

>  :   First saw this in the arc programming language, which is based
>on Racket.
>   The funny thing is that a number of other Scheme implementations do
>not act thusly.  I wonder what can be done to remove this from Racket.

If you have an example that fails reliably, you should file a bug



>;; Typed into repl
>> (define (fact n)
>     (if (< n 2)
>         1
>         (* n (fact (- n 1)))))
>> (fact 5)
>;; Copied from Notepad into repl> (define (fact n)
>   (if (< n 2)
>       1
>       (* n (fact (- n 1)))))
>> (fact 5)
>;; Copied from browser into repl> (define (factorial n)
>  (if (= n 0)
>      1
>      (* n (factorial (- n 1)))))
>stdin::355: if: bad syntax;
> has 4 parts after keyword
>  in: (if (= n 0) 1 R (* n (factorial (- n 1))))
>  context...:
>   C:\Program Files\Racket\collects\racket\private\misc.rkt:87:7
>From: George Neuner <gneuner2 at comcast.net>
> To: users at racket-lang.org 
> Sent: Tuesday, March 17, 2015 2:21 PM
> Subject: Re: [racket] Error when pasting code
>On Tue, 17 Mar 2015 19:06:50 +0000 (UTC), Steve Graham
><jsgrahamus at yahoo.com> wrote:
>>When running the following code, when manually typed in, there is no
>>error.  However, when the same is pasted from the keyboard buffer,
>>the error indicated appears.
>>Thanks, Steve
>Likely there are hidden control characters being carried when you cut
>and paste.
>I've had troubles going back and forth between DrRacket and various
>unicode aware code editors - everything from syntax errors compiling
>to DrRacket hanging or even crashing trying to load source files.
>Inevitably it is because some hidden character(s) snuck in.
>I haven't actually experienced it with cut-n-paste, but it would not
>surprise me.
>  Racket Users list:
>  http://lists.racket-lang.org/users

Posted on the users mailing list.