Running Racket from command line

54 views
Skip to first unread message

Vignesh Krishnaraja

unread,
Nov 21, 2019, 2:57:26 PM11/21/19
to Racket Developers
I am trying to run a racket file from the command line.

First thing I have to say is that when I run the program from the IDE (Dr. Racket) it works perfectly fine. The program uses #lang racket.

I tried using the -f to load the file and -e to evaluate my expression which is "(mine-expr '((prompt1 prompt2)))"
Racket is seeing ((prompt1 prompt2)) but it doesn't consider it as a list. I don't know why it is not treating it as a list since I used the ' .

When I run the exact same expression on DrRacket I get " '(("C" prompt1 prompt2)) ".

Also I noticed I was able to get some weird result when I escaped the space between the two elements.

What is the best way to evaluate an expression from command line using the definitions of a file just like the way we can on DrRacket?

Is there any other way to evaluate an expression through command line. Please let me know! I almost have no clue with racket. I am trying to reuse the racket program in my project. Thanks!


Sam Tobin-Hochstadt

unread,
Nov 21, 2019, 3:05:37 PM11/21/19
to Vignesh Krishnaraja, Racket Developers
There are three things you could do here:

1. Start the racket REPL, use `enter!` to run the program, and then
type in your expression. This is very similar to how DrRacket works.

2. Make sure the relevant things are `provide`d by your module, then
`require` the module and execute an expression. Here's an example:

[samth@huor:~/sw/plt/extra-pkgs/racket-lang-org (master) plt] cat a.rkt
#lang racket
(define x 1)
(provide x)
[samth@huor:~/sw/plt/extra-pkgs/racket-lang-org (master) plt] racket
-e "(require \"a.rkt\")" -e "(displayln x)"
1


3. Write the program you want as a module which uses `require` to
depend on the code you've already written, and then just run that
program as `racket program.rkt`.

I strongly recommend option 3, but any of them should work for you.

Sam
> --
> You received this message because you are subscribed to the Google Groups "Racket Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/73dd4ef7-9bb4-47c9-9c10-d369b2a30b67%40googlegroups.com.

Vignesh Krishnaraja

unread,
Nov 21, 2019, 5:56:11 PM11/21/19
to Racket Developers
I got it to work! Thanks a lot!
> To unsubscribe from this group and stop receiving emails from it, send an email to racke...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages