Expected a module declaration, found something else?
Asked Answered
J

1

15

I'm working on a Racket script (on a Linux machine) that requires the math/number-theory library. My entire script at the moment is thus:

#!/usr/bin/racket

(require math/number-theory)

Yes, it's literally just requiring the library.

When I try to run it, I get an error that reads "expected a `module' declaration found: something else".

However, when I actually start up Racket in the terminal like so:

/usr/bin/racket

and enter (require math/number-theory) in the command line, it treats it like it's totally valid.

What's going on here?

Joni answered 21/6, 2016 at 18:38 Comment(4)
The difference between a program and the REPL. Try adding an expression (like #f) after require.Rightly
I did that; it didn't help at all.Joni
You need #lang racket at the top, just underneath the shebang.Tricotine
Alexis has the right answer, but also see the Unix scripts section of the Guide which has a thorough explanation.Maenad
A
24

Make sure the top of your racket files contains a #lang statement as well.

In other words, you need this at the top of the file:

#!/usr/bin/racket
#lang racket
Annaleeannaliese answered 18/8, 2016 at 21:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.