Hello
While playing with Meroon (the version provided by Bradley Lucier),
I've realized that debugging is made difficult in cases where
macro-generated code has invalid syntax. The example where I've seen
this:
;; (in "test-meroon.scm":
;; I've define-class'ed area, triangle, and quadrangle, and
;; defined a generic area and a method (area (s triangle) . rest).
;; But this fails: )
(define-method (area (s quadrangle) . rest)
(let ((m (if (null? rest)
(error "missing m")
(car rest))))
(let ((triangle-area (call-next-method)))
(warn "triangle-area: " triangle-area)
(* triangle-area m))))
;; when entering the equivalent of
;; (compile-file "./test-meroon.scm" '(debug expansion verbose)) :
*** ERROR IN "/home/chris/schemedevelopment/gambit/mod/./test-meroon.scm"@156.1 -- Ill-formed procedure call
Now how am I supposed to find out what went wrong?
1- the line/col position points at the start of the define-method form.
2- the error message does not show the macro-expanded code
3- entering ,e in the debugger doesn't show the relevant syntax either,
since the gambit internals have been compiled without debugging
information. (I'm not sure if compiling with '(debug) would help,
since sometimes (frequently?) the lexical environment is not even
accessible then; well: ,e often shows it, but entering the name of
one of the variables shown by ,e cannot access it.)
4- the `expansion (and `verbose) compile flags don't help either: it
seems that the error happens during macro-expansion, before expansion
has finished.
5- this won't help either:
> (define oldexp c#expand-source)
> (define seen-syn #f)
> (define seen-res #f)
> (set! c#expand-source (lambda (syn) (set! seen-syn syn) (let ((res (oldexp syn))) (set! seen-res res) res)))
since after running compilation again, (equal? seen-syn seen-res)
is #t, which means that macro-expansion doesn't happen in the default
c#expand-source handler -- it is c#wrap-program by default and
doesn't do anything.
Of course, my example above is relatively simple, and I've tracked the
problem down to (call-next-method), it seems that with the rest
argument, meroon is building invalid syntax. But gambit doesn't help
me in any way to find out exactly what's wrong.
I'm thinking about writing a 'lowlevel' macro-expansion system which
tracks source location (as I've mentioned in a mail a few weeks
ago). That would help with problem 1 (it would directly show the
relevant line).
My other suggestions would be:
- (2) show the invalid macro-expanded code in the error message
- (3) would it be feasible to compile the gambit core with `debug ?
- (5) are there hooks into the builtin macro-expander? (to be able to
grab the partially macro-expanded code oneself)
Thanks
Christian.