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

From: Rodolfo Carvalho (rhcarvalho at gmail.com)
Date: Fri Jun 3 11:41:30 EDT 2011

Good to know about the -m switch.

Is there a similar trick to use with DrRacket?

For now I have one module from where I want to demonstrate some
functionality running it from DrRacket (with out using the Interactions
window).

And I would use this same module as a "library" from another one.


[]'s

Rodolfo Carvalho


On Thu, Jun 2, 2011 at 19:51, Robby Findler <robby at eecs.northwestern.edu>wrote:

> You can get close if you use 'racket' to run the file; define a main
> function that has the code that should only run in standalone and then
> use the -m flag on the commandline.
>
> Robby
>
> On Thu, Jun 2, 2011 at 4:45 PM, Matthias Felleisen <matthias at ccs.neu.edu>
> wrote:
> >
> > 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
> >
> >
> > _________________________________________________
> >  For list-related administrative tasks:
> >  http://lists.racket-lang.org/listinfo/users
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110603/7b0a9d1b/attachment.html>

Posted on the users mailing list.