Hi,

I try to help and hope I do not mess things up. I found those start up things a bit tricky as well.

The main question is: What is available when you want to eval with the -e option? (more technically: what bindings does your current namespace provide at that point?)

The concept of namespaces is explained here: http://docs.racket-lang.org/guide/eval.html?q=namespace#%28tech._namespace%29

When you use the "-e" switch Racket requires racket/init. And racket/init provides all bindings from racket (plus some more from racket/enter and racket/help):

```
(provide (all-from-out racket
                       racket/enter
                       racket/help))
```

That's described at http://docs.racket-lang.org/guide/racket.html and in more detail in the reference at http://docs.racket-lang.org/reference/running-sa.html#%28part._init-actions%29

If you use the "-f" switch to "load" a file you get a top-level environment like in interaction mode with all the bindings from "racket".


But if you use module loading with -t (or other module loading switches) that is simply not the case. Then the top-level environment contains no bindings (not even the binding for function calls).


Given a file foo.rkt

```
#lang racket

(provide hello)

(define (hello)
  (display "Hello, world!\n"))
```

even this call fails:

$ racket -t foo.rkt -e '(+ 1 2)'

(That's because not even the function calls are provided.)

There are several ways to get your module "running":


You could provide a submodule `main` in your which is evaluated when your module is required by the racket executable:

Add
```
(module+ main
  (hello)
  )
```

and then "racket -t foo.rkt" prints "Hello, world!".


If you want to use "-e" (e.g. for testing) you need more bindings from racket. You could require "racket" with -l:

$ racket -t foo.rkt -l racket -e '(hello)'


Or your module could provide the bindings from racket. Then you could add something like

```
(provide (all-from-out racket)
```

in the foo.rkt module.


To sum up: When using interactive or load mode you get the bindings from racket, racket/init at the top-level environment. But if you use module mode your top-level environment is empty in the beginning.


Kind regards,
Daniel


Am 10.10.2015 um 20:29 schrieb Linh Chi Nguyen:
Hi everyone,
The situation is that I have a racket file with the same code but 2 version, 
one in module and one in load mode.

```
hi.rkt is in load mode
```

```
bye.rkt is the same code but in module mode

#lang racket
(provide run-some-commands)

```

Both work just fine if I use a REPL.

The load mode:
```
~@laptop$ racket
Welcome to Racket v6
(load "hi.rkt")
(run-some-commands x y z)
...
```

Or as a module
```
~@laptop$ racket
Welcome to Racket v6
(require "bye.rkt")
(run-some-commands x y z)
...
```

Now the problem is when I want to run the command without loading a REPL. I 
follow this doc (http://docs.racket-lang.org/guide/racket.html), it works just 
fine if i use the load mode:

```
~@laptop$ racket -f hi.rkt -e '(run-some-commands x y z)'
```

However, if i use the module mode, it says nothing, sometimes it says bye.rkt 
is undefined.

```
~@laptop$ racket bye.rkt -e '(run-some-commands x y z)'
```

I'm very confused because Racket recommends to use module instead of load mode.

Any help?

Thank you,
Chi


--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to