[racket] How to prevent code from running when `required`?

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Thu Jun 2 17:45:20 EDT 2011

Not available yet, but thanks for asking: I requested this feature a month ago on our 'dev' list. 




On Jun 2, 2011, at 5:42 PM, Rodolfo Carvalho wrote:

> Sorry if I didn't find it somewhere obvious, but I don't know how to do the following.
> 
> I would like a have a file that when run standalone executes some code, and when "required" by another module just provides some definitions.
> 
> Example:
> 
> ;-------------------------------------------------------
> ; my-lib.rkt
> (provide make-milk-shake)
> 
> (define (make-milk-shake flavor)
>   ...)
> 
> ; run this only when run standalone
> (magic-thing
>   (make-milk-shake 'banana)
> 
> 
> ;-------------------------------------------------------
> ; some-other.rkt
> (require "my-lib.rkt")
> 
> (make-milk-shake 'strawberry)
> ; only make 1 milk shake of strawberry...
> 
> 
> 
> That is, I am searching for an equivalent idiom for what in Python I'd write:
> 
> if __name__ == "__main__":
>     do_things()
> 
> 
> 
> 
> []'s
> 
> Rodolfo Carvalho
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users




Posted on the users mailing list.