0

I am working with a .rkt file in VSCodium, using the Magic Racket extension.

File Contents:

#lang racket

(define (square x) (* x x))
(define myNums (list 1 2 3 4 5))
(define hisNums '(2 4 6 8 10 9 7 5 3 1))

(square (car(cdr(cdr hisNums))))
(car(cdr(cdr hisNums)))
(cons(square(car(cdr(cdr hisNums)))) (car(cdr(cdr hisNums))))
(cons(square(car(cdr(cdr hisNums)))) (cdr(cdr hisNums)))

(square (car(cdr(cdr myNums))))
(car(cdr(cdr myNums)))
(cons(square(car(cdr(cdr myNums)))) (car(cdr(cdr myNums))))
(cons(square(car(cdr(cdr myNums)))) (cdr(cdr myNums)))

When I choose the Racket: Load file in REPL command, VSCodium opens Racket with racket --repl --eval '(enter! (file "filename.rkt"))'

and the output in the terminal is,

Welcome to Racket v8.8 [cs].
string::9: read: expected a `)` to close `(`
>

and the file is not loaded into the REPL.

What is the line

string::9: read: expected a `)` to close `(`

trying to tell me?

How do I solve this issue and get the file loaded into the REPL without that error message?

Edit

I need to clarify that do understand that it is complaining about a missing closing parens somewhere, but more important is that I need help interpreting/translating the following portion into English:

string::9: read: 

I don't know how to read that.

halfer
  • 19,824
  • 17
  • 99
  • 186
nutbunny
  • 79
  • 1
  • 7
  • 1
    Have you saved your program properly before running "Racket: Load file in REPL"? The error message tells you that your code has a mismatched paren, but your code doesn't have that. This usually happens when you forgot to save your work. – Sorawee Porncharoenwase Mar 25 '23 at 23:43
  • You might be interested in [`caddr`](https://docs.racket-lang.org/reference/pairs.html#%28def._%28%28quote._~23~25kernel%29._caddr%29%29) or [`third`](https://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Flist..rkt%29._third%29%29), btw. – Shawn Mar 26 '23 at 01:38
  • And see [the style guide](https://docs.racket-lang.org/style/Textual_Matters.html), especially section 6.8, for some formatting tips. – Shawn Mar 26 '23 at 01:44
  • @SoraweePorncharoenwase Yes, the file was saved. It works fine in the DrRacket GUI but in both a normal terminal and the terminal inside VSCodium it has that same error. – nutbunny Mar 26 '23 at 11:04
  • @Shawn thanks for the style tips, much appreciated. My code posted above is just me learning how to interact with the language and how different types of input relate to output, so it's basically me probing the language. – nutbunny Mar 26 '23 at 11:10
  • "_in both a normal terminal and the terminal inside VSCodium it has that same error._" -- Can't reproduce: I don't use VSCodium, but I copied and pasted your posted code into a file and ran `racket --repl --eval '(enter! (file "filename.rkt"))'` with no errors. You might double-check the actual file you have saved and be sure that 1) you have no syntax mistakes and 2) you are invoking `racket` on the right file. You might also consider creating a simpler program for testing. If this then works in a terminal window but still not in VSCodium then it might be a problem specific to VSCodium. – ad absurdum Mar 26 '23 at 16:20
  • @adabsurdum I created a "simple.rkt" file with function `(define (square x) (* x x))` followed by `(square 2)` `(square 6)` & `(square 23)`. Running the file in both the terminal & VSCodium terminal, with `racket simple.rkt` works fine, printing out the values 4, 36, and 529. Loading it into the REPL, whether the terminal or the VSCodium terminal, with `--repl --eval '(enter! (file "filename.rkt"))'` will not work. I figured out that the `string::9: read: expected a ')' to close '('` probably refers to placing a ")" after the `'(enter!` . Can a space in the file path cause this? – nutbunny Mar 27 '23 at 19:09
  • @nutbunny do you mean `--repl --eval '(enter! (file "simple.rkt"))'`? That is, you invoked `racket --repl --eval` on your "simple.rkt" file instead of on your original file for the new test, correct? "_Can a space in the file path cause this?_" -- I don't see spaces in any of your file names. What kind of terminal are you using? Are you on Linux, Windows, MacOS? – ad absurdum Mar 27 '23 at 19:28
  • @adabsurdum EDIT: I need to correct my previous reply, I meant to say `--repl --eval '(enter! (file "C:\users\.....\Racket Sources\simple.rkt"))'` will not work – nutbunny Mar 27 '23 at 19:28
  • @nutbunny -- Ah: Windows, with the space in a directory name. It would surprise me if the space was causing the problem, but you could try putting the source in a different directory, or just invoking `racket` from the source directory. I have rarely used Racket in Windows, but I do have an old machine set up with an older version of Racket; I'll try to test there to see if I can recreate the issue. – ad absurdum Mar 27 '23 at 19:34

1 Answers1

1

The problem is that the string parameter for --eval is not being passed correctly to Racket.

I was able to reproduce the issue on a Windows system with Racket 7.5 installed. I used this simple program saved in simple.rkt:

#lang racket

(define (square x)
  (* x x))

(square 2)

From the cmd.exe command prompt:

>racket --repl --eval '(enter! (file "simple.rkt"))'

yielded the error message:

string::2: read-syntax: expected a `(` to close `)`

I don't think that the Windows command prompt recognizes single-quotes, but rather that it expects double quotes for arguments containing spaces. The internal quotes needed by Racket surrounding the file name string can be escaped with backslashes:

>racket --repl --eval "(enter! (file \"simple.rkt\"))"

This worked without problems, starting a repl and showing the expected result of 4.

A similar problem is occurring when you try to start a repl from VSCodium. It seems that Magic Racket has had similar issues in the past generating shell commands that aren't quite correct; I suspect that you are either experiencing a bug in Magic Racket or that you need to configure VSCodium to use the correct terminal program. If this is a bug the best thing to do would be to raise an issue with magic-racket to see if someone can fix this.

Terminal Programs in Windows

The Windows cmd.exe program seems to be kind of a mess when it comes to passing these types of string arguments to programs.

If you are going to spend much time using the terminal in Windows, you might consider using one of the Linux shells; these can run under WSL which was added in Windows 10. Note that if you try to use Magic Racket under WSL, you may have to troubleshoot some issues.

You could also install something like MYSYS2 which uses MinGW to provide a Linux-like shell. I have these tools installed on the old windows box that I tested with above; your original posted racket invocation worked just fine in the MYSYS shell on Windows.

ad absurdum
  • 19,498
  • 5
  • 37
  • 60
  • nutbunny -- did you figure this out? You never answered my earlier question about which terminal program you are using. PowerShell, cmd.exe, bash under WSL, or something else? That matters. Magic Racket is certainly not sending the correct string argument to the racket executable, and this is sent via a shell. After looking over the magic-racket source code it seems that in your case it has determined that you are using neither PowerShell nor cmd.exe. This could be a bug in magic-racket, or it could mean that you need to configure VSCodium or magic-racket to use the correct shell. – ad absurdum Mar 29 '23 at 01:07
  • @ad_absurdum Sorry, no, i did not manage to fix it, but I decided to just stick with the DrRacket REPL in the meantime until i understand more about the intricacies of programming and terminal usage. I do think that your suggestion - that the Windows terminal clashes with certain types of string arguments - has merit, as that seems to be the only possible explanation. – nutbunny Apr 05 '23 at 20:42