Search code examples
schemeguile

Determine whether Guile is running interactively


How to test whether Guile running interactively?

The purpose is the following: implement an exception handler such that, if not running interactively, exceptions should print a message and exit Guile, otherwise they should print a message and do nothing (i.e. return to the REPL).


Solution

  • There might be a better way but I have one suggestion. in your .guile define a variable *interactive* to #t in the guile module via e.g.

    (module-define! (resolve-module '(guile)) '*interactive* #t)
    

    As far as I know .guile is executed exactly when guile is interactive and not when run as a program.

    then you can define the following check

    (define (interactive?) (module-defined? (resolve-module '(guile)) '*interactive*)