guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Jean Abou Samra
Subject: Re: with-syntax return error in Guile, not in Kawa or Racket
Date: Sat, 11 May 2024 00:23:29 +0200
User-agent: Evolution 3.52.1 (3.52.1-1.fc40)

> 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 :-)

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]