[racket] Help: Running racket programs from command line

1,872 views
Skip to first unread message

A Z

unread,
Sep 23, 2010, 2:51:56 PM9/23/10
to us...@racket-lang.org
I want to make a script that tests a bunch of racket programs in different .rkt files. I went through the documentation but I do not get any information about how to run racket programs from command line. Please help me.

Thanks,
Colum

Robby Findler

unread,
Sep 23, 2010, 2:55:06 PM9/23/10
to A Z, us...@racket-lang.org
Say "racket file.rkt".

You can find the docs here:

http://docs.racket-lang.org/reference/running-sa.html#%28part._mz-cmdline%29

Robby

> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
>
_________________________________________________
For list-related administrative tasks:
http://lists.racket-lang.org/listinfo/users

A Z

unread,
Sep 27, 2010, 3:36:33 PM9/27/10
to Robby Findler, us...@racket-lang.org
Hello Robby,

Thanks for your reply. I can get racket file.rkt working. I want to test some or a particular definition in the racket file with a particular input.

Say, the racket file is file.rkt

***********
(define (twice x)
        (* 2 x))

and so on....

**********

I want to test if (twice 2) is 4 from the command line.

Thanks for the help.
Colum

Horace Dynamite

unread,
Sep 27, 2010, 4:39:20 PM9/27/10
to A Z, racket
> Say, the racket file is file.rkt
>
> ***********
> (define (twice x)
>         (* 2 x))
>
> and so on....
>
> **********
>
> I want to test if (twice 2) is 4 from the command line.

You need to know what "folder" or "directory" you saved the file in.
Lets say it's in C:\racket\

Click Start -> Run and type "cmd" (without the quotes)
Then type (again, without quotes)
"cd C:\racket\"

(or you could pass the full path to enter! (see below) instead)

If the racket executable is in your path, you should be able to type
"racket.exe" and have the racket program waiting for your input. If
this is not the case, you need to find out where your racket
executable is. Try "C:\program files\Racket\racket.exe".

If that doesn't work, hunt through you're program files folder to see
where you installed Racket.

Once the racket program is waiting on your input, type "(enter!
"file.rkt")" and you should be all set, then you may type "(twice 2)"
and see the result.

This will only work if you "cd"'d into the correct folder above.

More experienced users have made running racket from the "command
line" like this more convenient by setting up their favourite editor
to automatically launch the racket program, and to make sure it's in
the folder their racket files are located.

If this all sounds too complicated (it does to me), I'd strongly
suggest you use DrRacket.

Hope that helps,

Horace.

A Z

unread,
Sep 27, 2010, 6:35:01 PM9/27/10
to Horace Dynamite, racket
Hello Horace,

I thank you for patiently explaining me how to run racket from command line.

Actually, this is not exactly what I am looking for.

What I want is a script file. Such that I can test the modules of the program from command prompt.

Something like

*******
#!/bin/bash
racket -f "file.rkt"

racket (twice 2)
*******

Thanks in advance,
Colum

John Clements

unread,
Sep 28, 2010, 12:32:12 AM9/28/10
to A Z, racket, Horace Dynamite

On Sep 27, 2010, at 3:35 PM, A Z wrote:

> Hello Horace,
>
> I thank you for patiently explaining me how to run racket from command line.
>
> Actually, this is not exactly what I am looking for.
>
> What I want is a script file. Such that I can test the modules of the program from command prompt.
>
> Something like
>
> *******
> #!/bin/bash
> racket -f "file.rkt"
>
> racket (twice 2)
> *******

Ah! Caught.

Okay, you want a file that tests another file. The easy way to do this is not to dip into shell programming at all, but to write your script as another racket program. For the example you provide:

****
#lang racket

(require "file.rkt")
(require rackunit)

(check-equal? (twice 2) 4)
*****


Then just run this file from the command-line. If it were called 'tests.rkt', you could run it as

racket tests.rkt

John Clements

A Z

unread,
Sep 28, 2010, 12:35:52 PM9/28/10
to John Clements, racket, Horace Dynamite
That is exactly what I was looking for.

Thanks
Shad Kirmani

A Z

unread,
Sep 28, 2010, 5:07:29 PM9/28/10
to John Clements, racket, Horace Dynamite
Hello,

There is a problem. 'require' does not go inside the definition of a function. DrRacket complains that it needs to go in a module.

I need (require path) inside a function because I want to run functions from each .rkt file in a directory. I can write (require "file.rkt") for each of the file at the top, but that does not look good.

Thanks everyone.
Shad Kirmani


On Tue, Sep 28, 2010 at 12:32 AM, John Clements <clem...@brinckerhoff.org> wrote:

Deren Dohoda

unread,
Sep 28, 2010, 5:13:37 PM9/28/10
to A Z, racket
Shad, what you're looking for, I believe, is local-require.

A Z

unread,
Sep 28, 2010, 8:27:25 PM9/28/10
to Deren Dohoda, racket
Hello,

Can anyone please tell me how to process all the files in a directory.

This is what I am doing:

(check-progs (directory-list "/home/racket/progs"))

(define (check-progs flist)
  (if(list? flist)
     (if(null? (cdr flist))
        '()
        (check-progs (cdr flist)))
     (process (simple-form-path (car flist)))))


(define (process path)
  (local-require path)
  (local-require rackunit)
  (check-equal? (twice 2) 4)

Thanks in advance.
Colum

On Tue, Sep 28, 2010 at 5:13 PM, Deren Dohoda <deren....@gmail.com> wrote:
Colum, what you're looking for, I believe, is local-require.

On Tue, Sep 28, 2010 at 5:07 PM, A Z <ukb...@gmail.com> wrote:
> Hello,
>
> There is a problem. 'require' does not go inside the definition of a
> function. DrRacket complains that it needs to go in a module.
>
> I need (require path) inside a function because I want to run functions from
> each .rkt file in a directory. I can write (require "file.rkt") for each of
> the file at the top, but that does not look good.
>
> Thanks everyone.
> Colum

A Z

unread,
Sep 28, 2010, 10:30:50 PM9/28/10
to John Clements, racket
Hello John,

I have the same test for all the files.

Thanks
Colum

On Tue, Sep 28, 2010 at 9:48 PM, John Clements <clem...@brinckerhoff.org> wrote:

On Sep 28, 2010, at 5:27 PM, A Z wrote:

> Hello,
>
> Can anyone please tell me how to process all the files in a directory.
>
> This is what I am doing:
>
> (check-progs (directory-list "/home/racket/progs"))
>
> (define (check-progs flist)
>   (if(list? flist)
>      (if(null? (cdr flist))
>         '()
>         (check-progs (cdr flist)))
>      (process (simple-form-path (car flist)))))
>
>
> (define (process path)
>   (local-require path)
>   (local-require rackunit)
>   (check-equal? (twice 2) 4)
>

Hmm... perhaps the first question is this: usually, you have different tests for each file.  Is that not true for you?

John Clements


Reply all
Reply to author
Forward
0 new messages