On Wed, 2009-09-02 at 12:43 -0700, Derick Eddington wrote:
> On Wed, Sep 2, 2009 at 12:27 PM, kub<[email protected]> wrote:
> > Unfortunately &trace is private and I cannot use it without parsing
> > string representation of condition.
> > Can &trace condition be made public ? Or you have reasons not to do it
> > now ?
>
> You can get the &trace info by using the conditions and records
> introspection API. I'm not on my computer right now, so I'll show you
> how later if you haven't already figured it out.
Here's the hack I thought of:
(define (get-traces cnd)
;; The cnd argument must be a condition.
(define (trace?/get x)
;; This predicate tries to be precise, but it's not perfect.
(let ((rtd (record-rtd x)))
(and (eq? '&trace (record-type-name rtd))
;; Will Clinger hates record-type-descriptor because it
;; requires knowing whether the record type was defined via the
;; syntactic or procedural interface. The below use is not
;; portable, because it's unspecified which interface a
;; particular implementation used to define &condition. So I
;; have to say, here's another example adding to my dislike of
;; record-type-descriptor.
(eqv? (record-type-descriptor &condition)
(record-type-parent rtd))
(let ((fn (record-type-field-names rtd)))
(and (= 1 (vector-length fn))
(eq? 'form (vector-ref fn 0))
((record-accessor rtd 0) x))))))
(let loop ((l (simple-conditions cnd))
(a '()))
(if (null? l)
(reverse a)
(loop (cdr l) (let ((x (trace?/get (car l))))
(if x (cons x a) a))))))
Example usage:
> (define ex
(guard (e (else e))
(eval '(let-syntax ((s (syntax-rules ()
((_) (guard)))))
(s))
(environment '(rnrs)))))
> ex
#[compound-condition (#[&who guard]
#[&message "invalid syntax"]
#[&syntax (guard) #f]
#[&trace #<syntax (guard)>]
#[&trace #<syntax (s)>])]
> (get-traces ex)
(#<syntax (guard)> #<syntax (s)>)
--
: Derick
----------------------------------------------------------------