I'd like Guile to support something like the patch below - i.e. some way of being able to execute arbitrary code before a Guile script starts running, so as to be able to set up breakpoints (or whatever other mechanisms are available) to trace or debug the script execution. (And without having to edit the script.)
Some possible questions... Is GUILE_BOOT_FORM a good name? Is it too general? Should we instead support a variable GUILE_PRE_SCRIPT_REPL, which causes us to run a normal REPL before loading the script? Or perhaps a more limited or debugging-focussed REPL? I think the generality of GUILE_BOOT_FORM is useful. If the only option is starting a REPL, that makes automated operation less convenient. Also, imagine a build in which there might be several Guile script invocations, and you only want to debug one of them. Then the boot form could include a check of the script name - (car (command-line)) - and only start a REPL (or set a breakpoint, or whatever) for that one. Thoughts? Regards, Neil diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm index a1537d1..86ab725 100644 --- a/module/ice-9/boot-9.scm +++ b/module/ice-9/boot-9.scm @@ -3514,4 +3514,9 @@ module '(ice-9 q) '(make-q q-length))}." (define-module (guile-user) #:autoload (system base compile) (compile)) +(let ((boot-form (getenv "GUILE_BOOT_FORM"))) + (if (and (string? boot-form) + (not (zero? (string-length boot-form)))) + (primitive-eval (with-input-from-string boot-form read)))) + ;;; boot-9.scm ends here