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

From: Rodolfo Carvalho (rhcarvalho at gmail.com)
Date: Thu Jun 2 17:42:54 EDT 2011

Sorry if I didn't find it somewhere obvious, but I don't know how to do the

I would like a have a file that when run standalone executes some code, and
when "required" by another module just provides some definitions.


; my-lib.rkt
(provide make-milk-shake)

(define (make-milk-shake flavor)

; run this only when run standalone
  (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

if __name__ == "__main__":


Rodolfo Carvalho
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110602/8f5e2a0c/attachment.html>

Posted on the users mailing list.