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