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]>
> it is clear that calling <- via ← give a bad result, if instead i use directly
> <- code works.

OK, I think I get it now:

(define-syntax <-
  (lambda (sintax)
    (syntax-case sintax ()
      ((<- arg)
       (datum->syntax sintax (syntax->datum #'arg))))))

;; Works:
(let ((foo "ABCD\n"))
  (display (<- foo)))

(define-syntax-rule (← . args) (<- . args))

;; Fails (as expected, documented and standard):
(let ((foo "ABCD\n"))
  (display (← foo)))



Well, I was wrong that you had to go out of your way to make
a difference between <- and ←. In fact it's a lot simpler than
I thought, as the example above shows. But Maxime and I told
you that this syntax->datum → process → datum->syntax dance
was not a good idea. Now you've learnt why, the hard way :-)

In the datum->syntax call, if you use the macro's argument
(which I called "sintax"), the lexical context introduced
is wherever the macro was expanded. In the case of ←,
that's in the body of the macro definition of ←, so variables
from the let form where foo is bound are unavailable.

Don't make your life complicated for no reason :-)
signature.asc (application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE-----

iHUEABYKAB0WIQSZ7TKxnKGyBvBjzBmj8PYLiTOX/gUCZj6eYQAKCRCj8PYLiTOX
/oChAP4+qbF6DvpOfdDK55DgBv2z+TwDYrCQvw7Tr3WZdygKswD+IV/wBJ6PUYVd
AkO3GsPu5Fqvb0JJjC4Ee5LwaeUitQ8=
=7iHe
-----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.