How to use Racket in terminal?
Asked Answered
K

2

7

I'm having no luck finding a way to have this work the way I'd like it to, so if anyone could help that would be so greatly appreciated.

What I'd like is to be able to do this on Terminal:

> racket

And then be able to enter Racket commands and have them compile. Like,

> (+ 1 2)
> 3

And hopefully some commands like

> racket myprog.rkt
> 3

Where myprog.rkt was just the file containing (+ 1 2).

I'm new to this so sorry if it's an obvious question but I just don't know how to make it work.

Thanks.

Keslie answered 16/4, 2013 at 17:33 Comment(0)
C
4

You're describing almost exactly what the racket executable is doing. The only difference is that your myprog.rkt would need to have a #lang racket at the top.

If you're using a Mac, you'll need to run the executable with a direct path, or add it to your environment's $PATH, or make a symlink to it. You will find the executable in the bin subdirectory.

If you're on Windows, you have to do the same -- either add the Racket directory to the PATH in the system settings, or run it directly. On windows, you should have a startup link to the Racket executable which will run in a cmd box. (And note that if you look at the Racket directory, there will not be a bin subdirectory.)

Centiliter answered 16/4, 2013 at 18:21 Comment(5)
@Keslie See also the documentation on xrepl: docs.racket-lang.org/xrepl/index.html?q=xreplNimbus
Right! What I want is to be able to, anywhere is terminal, just say racket and have that executable run, just like how python works. How do I add it to my path?Keslie
sounds like you have a question about how to add something to your path. What operating system are you using?Rondo
Create an alias in ~/.bash_profile: alias racket='/Applications/Racket\ v6.1.1.1/bin/racket'Pewee
Don't do an alias -- that would work only in bash, not in other shells, and not from scripts.Centiliter
C
0

It would a great idea to first download Racket, you can find the download file or also do it with Snap or Flathub, check it out. To complement @EliBarzilay, if you are on GNU/Linux, on a debian based system you need to install racket, running:

sudo apt install racket 

Or in RHEL/Fedora:

sudo dnf install racket

for then:

racket myprog.rkt
Canotas answered 3/2 at 3:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.