Question

When using DrScheme with R5RS, there is no error function. I plan to write my own, but can't figure out how to halt the program execution. I tried commands such as:

  • (halt)
  • (exit)
  • (error)

and none worked. How do you halt program execution?

Was it helpful?

Solution

SLIB (the portable Scheme library) has an implementation of ERROR. You might want to either look at that, or use SLIB in your programs.

Other than that, one way to halt the program is simply to raise a different error! Try something like this (thanks to Stephen Houben):

(define (error reason . args)
      (display "Error: ")
      (display reason)
      (for-each (lambda (arg) 
                  (display " ")
          (write arg))
        args)
      (newline)
      (scheme-report-environment -1))  ;; we hope that this will signal an error

While this does raise a second (unrelated) error, it will surely halt program execution.

OTHER TIPS

Is there a reason you need to use R5RS? Other language definitions in DrScheme define error and exit. For example, the (module ...) PLT language defines error and exit. Invoking mzscheme from the command line also gives you these definitions.

Note: I have DrScheme 372, which is pretty old. Things shouldn't have changed too much, though.

an ugly solution is to define abort to become a runtime error. for example any of these should do the trick (define abort "the program was aborted") (define abort 123) (define abort #f) any call to abort (abort) should generate a runtime error, if your lucky even show the string , error code or whatever you care.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top