Re: with-syntax return error in Guile, not in Kawa or Racket

Jean Abou Samra <[email protected]>
Newsgroups gmane.lisp.guile.user
Message-ID <[email protected]>
> (base) mattei@mbp-touch-bar Scheme-PLUS-for-Guile % guile
> GNU Guile 3.0.8.99-f3ea8
> Copyright (C) 1995-2022 Free Software Foundation, Inc.
> 
> Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
> This program is free software, and you are welcome to redistribute it
> under certain conditions; type `,show c' for details.
> 
> Enter `,help' for help.
> scheme@(guile-user)> (define-syntax test-it
>    (lambda (stx)
>     (syntax-case stx ()
>     ((_ term1)
>      (with-syntax ((var (syntax->datum #'term1)))
>        #'var)))))
> scheme@(guile-user)> (test-it (+ 2 3))
> While compiling expression:
> Syntax error:
> unknown file:#f:#f: encountered raw symbol in macro output in subform + of
> (test-it (+ 2 3))


As the error message says, your macro contains the raw symbol `term1`.
The expression (syntax->datum #'term1) is equivalent to 'term1 .
What's raising the error is not with-syntax itself, it's the fact
that a hygienic macro must return syntax objects, and a raw
symbol is not a syntax object. Kawa and Racket probably have some
fallback where the macro becomes non-hygienic when it returns
raw symbols. But R6RS makes it clear that this is not standard
Scheme. See

https://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-13.html#node_sec_12.2

"""
a syntax object is:

- a pair of syntax objects,
- a vector of syntax objects,
- a nonpair, nonvector, nonsymbol value, or
- a wrapped syntax object
"""

"""
A transformation procedure is a procedure that must accept one argument, a
wrapped syntax object (section 12.2) representing the input, and return a syntax
object (section 12.2) representing the output. 
"""
signature.asc (application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE-----

iHUEABYKAB0WIQSZ7TKxnKGyBvBjzBmj8PYLiTOX/gUCZjeACwAKCRCj8PYLiTOX
/vAjAP0ZVvQlTd4CEBd6ggIgP5s2kL7H2LKyU/kkUl6mefExswD/SkPH4F4Pt4+L
HqXMGYI1WfuouAxJkOHr0STRX0WiVAo=
=e893
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.