Wednesday, April 6, 2011

How do you halt in DrScheme's implementation of R5RS?

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?

From stackoverflow
  • 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.

  • 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.

    Sebastian Krog : AFAIK, he is implementing his own interpreter, for which he is using R5RS.
    Kai : @Nathan - yes. I'm already using R5RS, and "change the language" only works until you have two languages with both disadvantages and advantages. Eventually you have to choose one or the other... @Sebastian - True.
    Nathan Sanders : Oops, thought this was a newbie question and didn't read it closely enough.

0 comments:

Post a Comment