On 24-02-2023 16:48, Ludovic Courtès wrote: > Maxime Devos skribis: > >> ;; Before: >> ;; unknown file:#f:#f: syntax-stuff-twice: bad in subform >> #> follow"> of #> very hard to follow"> >> ;; After: >> ;; [the same thing] >> ;; >> ;; Looks like another patch is needed ... > > What backtrace are you trying to get? > > Getting a backtrace showing which macros are being expanded (similar to > what GCC does) would be great, but it’s much more work; changing this > one line in libguile won’t achieve that. Just a regular backtrace like Guile already makes for exceptions unrelated to syntax, not some kind of expansion backtrace that tracks macro expansion. For example, let's say you have a macro that during expansion throws an exception in some cases. For non-'syntax-error' exception types, a backtrace is printed: ;; a.scm (define-module (a) #:export (whatever)) (define (syntax-negate s) (syntax-case s () (#false #true) (#true #false) (_ (error "bogus!")))) ; <--- line 6! (define (syntax-identity s) ; identity (syntax-case s () (#false #'#false) (#true #'#true) (_ (error "bogus!")))) (define-syntax whatever (lambda (s) (syntax-case s () ((_ x) #`(#,(syntax-negate #'x) #,(syntax-identity #'x)))))) ;; b.scm (use-modules (a)) (whatever 0) ;; Shell commands guild compile a.scm guild compile -L . b.scm ;; Output: a backtrace that mentions on which line of a.scm things went wrong: Backtrace: [Lots of lines] In ice-9/psyntax.scm: [More lines] In a.scm: 6:7 1 (_ _) In ice-9/boot-9.scm: 1685:16 0 (raise-exception _ #:continuable? _) ice-9/boot-9.scm:1685:16: In procedure raise-exception: bogus! However, suppose I removed the (_ (error "bogus!")) lines and hence the code produces syntax-error exceptions: ;; c.scm (define-module (c) #:export (whatever)) (define (syntax-negate s) (syntax-case s () ; L3 (#false #true) (#true #false))) (define (syntax-identity s) ; identity (syntax-case s () ; L7 (#false #'#false) (#true #'#true))) (define-syntax whatever (lambda (s) (syntax-case s () ((_ x) #`(#,(syntax-negate #'x) #,(syntax-identity #'x)))))) ;; d.scm (use-modules (c)) (whatever 0) ;; Shell commands guild compile c.scm guild compile -L . d.scm ;; Output: no backtrace at all! ice-9/boot-9.scm:1685:16: In procedure raise-exception: Syntax error: d.scm:2:10: source expression failed to match any pattern in form 0 ;; In case of complicated macros, it would be nice if it said _which_ ;; pattern matcher failed: L3, or L7, like with a.scm+b.scm. Summarised, I want the relatively nice backtrace that happens for non-'syntax-error' exceptions from a.scm+b.scm (*) (it's verbose, has lots of irrelevant stuff, but ultimately it provides an useful piece of information: the line number on which a pattern matcher failed). (*) Ideally you would have both the backtrace _and_ the line number in b.scm/d.scm. Greetings, Maxime.