The following codes are from "Successful Lisp" Charpter 23 .
I just can't understand what decides the destination of the stream in
the lambda function..
Any one can help me ?
Many Thanks!!
(define-condition high-disk-utilization ()
((disk-name :initarg :disk-name :reader disk-name)
(current :initarg :current :reader
current-utilization)
(threshold :initarg :threshold :reader threshold))
(:report (lambda (condition stream)
(format stream "Disk ~A is ~D% full; threshold is ~D%."
(disk-name condition)
(current-utilization condition)
(threshold condition)))))
In article <························@o13g2000cwo.googlegroups.com>,
··········@bbs.ee.ncu.edu.tw wrote:
> The following codes are from "Successful Lisp" Charpter 23 .
> I just can't understand what decides the destination of the stream in
> the lambda function..
> Any one can help me ?
> Many Thanks!!
>
> (define-condition high-disk-utilization ()
> ((disk-name :initarg :disk-name :reader disk-name)
> (current :initarg :current :reader
> current-utilization)
> (threshold :initarg :threshold :reader threshold))
> (:report (lambda (condition stream)
> (format stream "Disk ~A is ~D% full; threshold is ~D%."
> (disk-name condition)
> (current-utilization condition)
> (threshold condition)))))
CL-USER 1 > (define-condition high-disk-utilization ()
((disk-name :initarg :disk-name :reader disk-name)
(current :initarg :current :reader
current-utilization)
(threshold :initarg :threshold :reader threshold))
(:report (lambda (condition stream)
(format stream "Disk ~A is ~D% full; threshold is ~D%."
(disk-name condition)
(current-utilization condition)
(threshold condition)))))
HIGH-DISK-UTILIZATION
The report function will be called by the Lisp system with the condition
and the stream.
CL-USER 3 > (error 'high-disk-utilization :disk-name "foo-disk" :current 0.9 :threshold 0.8)
Disk foo-disk is 0.9% full; threshold is 0.8%.
1 (abort) Return to level 0.
2 Return to top loop level 0.
Type :b for backtrace, :c <option number> to proceed, or :? for other options
CL-USER 4 : 1 >
··········@bbs.ee.ncu.edu.tw writes:
> The following codes are from "Successful Lisp" Charpter 23 .
> I just can't understand what decides the destination of the stream in
> the lambda function..
> Any one can help me ?
> Many Thanks!!
>
> (define-condition high-disk-utilization ()
> ((disk-name :initarg :disk-name :reader disk-name)
> (current :initarg :current :reader
> current-utilization)
> (threshold :initarg :threshold :reader threshold))
> (:report (lambda (condition stream)
> (format stream "Disk ~A is ~D% full; threshold is ~D%."
> (disk-name condition)
> (current-utilization condition)
> (threshold condition)))))
It's an argument to the report function. It's obviously the caller of
the function that decides which stream to pass. Usually, the caller
of the report function of a condition is the error handler or the
debugger. Usually, it will be *ERROR-OUTPUT*.
(handler-case
(error 'HIGH-DISK-UTILIZATION :disk-name "A" :current 0.4 :threshold 0.35)
(t (err) (with-output-to-string (*error-output*)
#+clisp(SYSTEM::REPORT-ERROR err))))
Note, it's the implementation specific function SYSTEM::REPORT-ERROR
which decides to write the error message to the *ERROR-OUTPUT* stream.
--
"You cannot really appreciate Dilbert unless you read it in the
original Klingon"
On 13 Nov 2005 05:08:20 -0800, ··········@bbs.ee.ncu.edu.tw tried to
confuse everyone with this message:
>The following codes are from "Successful Lisp" Charpter 23 .
>I just can't understand what decides the destination of the stream in
>the lambda function..
>Any one can help me ?
>Many Thanks!!
Lisp implementation. It outputs errors in a separate stream, but they
end up in REPL anyway. You can control it by binding *error-output* to
your own stream.
>
>(define-condition high-disk-utilization ()
> ((disk-name :initarg :disk-name :reader disk-name)
> (current :initarg :current :reader
>current-utilization)
> (threshold :initarg :threshold :reader threshold))
> (:report (lambda (condition stream)
> (format stream "Disk ~A is ~D% full; threshold is ~D%."
> (disk-name condition)
> (current-utilization condition)
> (threshold condition)))))
>
--
|a\o/r|,-------------.,---------- Timofei Shatrov aka Grue ------------.
| m"a ||FC AMKAR PERM|| mail: grue at mail.ru http://grue3.tripod.com |
| k || PWNZ J00 || Kingdom of Loathing: Grue3 lvl 18 Seal Clubber |
`-----'`-------------'`-------------------------------------------[4*72]