[plt-scheme] Can a module tell if it's being run interactively?

From: Robby Findler (robby at cs.uchicago.edu)
Date: Tue Apr 15 20:08:03 EDT 2008

You can also put something into the commandline at the top of the file
(ie the call to `run').

Robby

PS: I'm looking forward to that day ;)

On Tue, Apr 15, 2008 at 6:42 PM, Matthias Felleisen
<matthias at ccs.neu.edu> wrote:
>
>  At some point Robby will turn into a systems guy and produce a full-fledged
> virtual script IDE. In the meantime, you may wish to consider turning your
> input for debug mode into a command-line argument and supplying them via the
> language menu (details) so you don't have to re-type them and so you don't
> have to remember to comment out anything when done debugging.
>
>  (Unless your input is truly large.) -- Matthias
>
>
>
>
>
>
>
>  On Apr 15, 2008, at 7:12 PM, Richard Cobbe wrote:
>
> > Is there a way for code in a module to tell if it's being run in the
> > DrScheme REPL or as part of a script?
> >
> > Right now, I'm trying to debug a script that reads input from stdin and
> > writes output to stdout.  I've got the file structured as follows:
> >
> >    #!/path/to/mzscheme
> >    #lang mzscheme
> >
> >    (define (run)
> >       (pretty-print (munge-input (read))))
> >
> >    (define munge-input ...)
> >
> >    (run)
> >
> > Now, If my script hits a bug, my first idea is to load the module into
> > DrScheme -- which immediately stops, waiting for input.  The input to the
> > script is larger than I want to type at the REPL, so I comment out the
> call
> > to `run', reload the module, then do (with-input-from-file ... run).
> After
> > I get the bug fixed, I inevitably forget to uncomment the call to run, so
> > the script is a NOP the first time I run it.
> >
> > It'd be really handy to say something like
> >
> >    #!/path/to/mzscheme
> >    #lang scheme
> >
> >    (define (run)
> >      (pretty-print (munge-input (read))))
> >
> >    (define munge-input ...)
> >
> >    (unless (running-at-repl?) (run))
> >
> > where `running-at-repl?' is provided by the "scheme" language.  That way,
> > `run' gets called when I run the script from the Unix shell but not when I
> > load it into DrScheme and hit the "Run" button.
> >
> > OCaml's Sys.interactive
> >
> (http://caml.inria.fr/pub/docs/manual-ocaml/libref/Sys.html#VALinteractive)
> > is basically what I'm looking for here.  In OCaml, one can write something
> > like
> >
> >    let _ =
> >      if not !Sys.interactive
> >      then run ()
> >      else ()
> >
> > at module top-level to get the behavior I described above.
> >
> > Is this possible?  If not, would it be possible to add this feature?
> >
> > Thanks,
> >
> > Richard
> > _________________________________________________
> >  For list-related administrative tasks:
> >  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> >
>
>  _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>


Posted on the users mailing list.