signal.scm 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Richard Kelsey, Jonathan Rees, Mike Sperber
  3. ; For backwards compatibility with old versions of Scheme 48
  4. ; only---don't use in new code.
  5. ;;;; Signalling conditions
  6. ; I don't like the term "signal," but that's the one Gnu Emacs Lisp,
  7. ; Common Lisp, and Dylan use, so it's probably best to stick with it.
  8. (define (make-condition type stuff)
  9. (let ((base
  10. (case type
  11. ((error) (make-error))
  12. ((warning) (make-warning))
  13. ((note) (make-note))
  14. ((syntax-error) (make-syntax-violation #f #f))
  15. ((call-error) (make-assertion-violation))
  16. (else (make-assertion-violation)))))
  17. (call-with-values
  18. (lambda ()
  19. (cond
  20. ((null? stuff) (values #f '()))
  21. ((string? (car stuff)) (values (car stuff) (cdr stuff)))
  22. (else (values #f stuff))))
  23. (lambda (message irritants)
  24. (let* ((con
  25. (if message
  26. (condition base
  27. (make-message-condition message))
  28. base))
  29. (con
  30. (condition con (make-irritants-condition irritants))))
  31. con)))))
  32. (define (signal type . stuff)
  33. (signal-condition
  34. (make-condition type stuff)))
  35. ; Error
  36. (define (error message . irritants)
  37. (apply signal 'error message irritants))
  38. ; Warn
  39. (define (warn message . irritants)
  40. (signal-condition (make-condition 'warning (cons message irritants))))
  41. ; Note
  42. (define (note message . irritants)
  43. (signal-condition (make-condition 'note (cons message irritants))))
  44. ; Syntax errors
  45. (define (syntax-error message . rest) ; Must return a valid expression.
  46. (signal-condition (make-condition 'syntax-error (cons message rest)))
  47. ''syntax-error)
  48. ; "Call error" - this means that the condition's "stuff" (cdr) is of
  49. ; the form (message procedure . args), and should be displayed appropriately.
  50. ; Proceeding from such an error should return the value that the call
  51. ; to the procedure on the args should have returned.
  52. (define (call-error message proc . args)
  53. (signal-condition (make-condition 'call-error
  54. (cons message (cons proc args)))))