Skip to content

Instantly share code, notes, and snippets.

@mk12
Last active April 22, 2022 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mk12/dc5a54107e46e67d702bb377304b144f to your computer and use it in GitHub Desktop.
Save mk12/dc5a54107e46e67d702bb377304b144f to your computer and use it in GitHub Desktop.
Getting syntax location in Guile, Racket, and Chez Scheme

I can't figure out why Guile isn't working. In Racket and Chez, getting the source location of #'e works fine. In Guile, it seems to convert to strip off the outer syntax information so that it becomes a list of syntax objects.

#!r6rs
(import (rnrs (6)))
(define-syntax foo
(lambda (x)
(syntax-case x ()
((_ e)
(begin
(display (syntax-source #'e))
(newline)
#'(display (syntax-source #'e)))))))
(foo (list 1))
; $ guile --no-auto-compile --r6rs test-0-guile.ss
; ((filename . test-0-guile.ss) (line . 13) (column . 5))
; Backtrace:
; 2 (primitive-load "/path/to/test-0-guile.ss")
; In ice-9/eval.scm:
; 191:35 1 (_ #f)
; In unknown file:
; 0 (syntax-source (#<syntax list> #<syntax 1>))
;
; ERROR: In procedure syntax-source:
; In procedure syntax-source: Wrong type argument in position 1 (expecting syntax object): (#<syntax list> #<syntax 1>)
#!r6rs
(import (rnrs (6))
(for (only (racket base) syntax-source) run expand))
(define-syntax foo
(lambda (x)
(syntax-case x ()
((_ e)
(begin
(display (syntax-source #'e))
(newline)
#'(display (syntax-source #'e)))))))
(foo (list 1))
; $ racket test-1-racket.ss
; /path/to/test-1-racket.ss
; /path/to/test-1-racket.ss
#!r6rs
(import (rnrs (6))
(only (chezscheme) annotation-source syntax->annotation))
(define-syntax foo
(lambda (x)
(syntax-case x ()
((_ e)
(begin
(display (annotation-source (syntax->annotation #'e)))
(newline)
#'(display (annotation-source (syntax->annotation #'e))))))))
(foo (list 1))
; $ chez --program test-2-chez.ss
; #<source test-2-chez.ss[367:375]>
; #<source test-2-chez.ss[367:375]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment