* Syntax objects as traditional pairs
@ 2022-04-04 23:00 Jean Abou Samra
2022-04-05 18:23 ` Linus Björnstam
0 siblings, 1 reply; 2+ messages in thread
From: Jean Abou Samra @ 2022-04-04 23:00 UTC (permalink / raw)
To: guile-user
Hi,
I am lost as to when a syntax object whose syntax->datum is a pair
can be manipulated as a plain Scheme pair. For example:
(define synt1 #'(a b))
(pk 'syntax synt1 'pair? (pair? synt1))
(pk 'car (car synt1))
(define-syntax mysyntax
(lambda (stax)
(syntax-case stax ()
((_ thing)
(begin
(pk 'syntax #'thing 'pair? (pair? #'thing))
(pk 'car (car #'thing)))))))
(mysyntax (c d))
results in
;;; (syntax (#<syntax a> #<syntax b>) pair? #t)
;;; (car #<syntax a>)
;;; (syntax #<syntax:test.scm:13:10 (c d)> pair? #f)
Backtrace:
7 (primitive-load "/home/jean/repos/lilypond/build/test.s…")
In ice-9/eval.scm:
721:20 6 (primitive-eval (mysyntax (c d)))
In ice-9/psyntax.scm:
1229:36 5 (expand-top-sequence (#<syntax:test.scm:13:0 (mysynta…>) …)
1121:20 4 (parse _ (("placeholder" placeholder)) ((top) #(# # …)) …)
1342:32 3 (syntax-type (mysyntax #<syntax:test.scm:13:10 (c d)>) # …)
1562:32 2 (expand-macro #<procedure 7fa6fa335320 at ice-9/eval.s…> …)
In ice-9/eval.scm:
159:9 1 (_ #(#(#<directory (guile-user) 7fa6fa3dfc80>) #<synt…>))
155:9 0 (_ _)
ice-9/eval.scm:155:9: In procedure car: Wrong type argument in position
1 (expecting pair): #<syntax:test.scm:13:10 (c d)>
Why does one syntax object look like a pair and not the other?
What is the difference between the two cases?
Thanks,
Jean
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Syntax objects as traditional pairs
2022-04-04 23:00 Syntax objects as traditional pairs Jean Abou Samra
@ 2022-04-05 18:23 ` Linus Björnstam
0 siblings, 0 replies; 2+ messages in thread
From: Linus Björnstam @ 2022-04-05 18:23 UTC (permalink / raw)
To: Jean Abou Samra, guile-user
Because both syntax objects encapsulating a list and a list of syntax objects are valid syntax objects.
If you match a list using just a pattern var it will be a syntax objects. I'd you match it using (pattern ...) you will do #'(pattern ...) and get a list.
You can easily implement syntax->list that handles both cases and always returns a list.
--
Linus Björnstam
On Tue, 5 Apr 2022, at 01:00, Jean Abou Samra wrote:
> Hi,
>
> I am lost as to when a syntax object whose syntax->datum is a pair
> can be manipulated as a plain Scheme pair. For example:
>
>
> (define synt1 #'(a b))
> (pk 'syntax synt1 'pair? (pair? synt1))
> (pk 'car (car synt1))
>
> (define-syntax mysyntax
> (lambda (stax)
> (syntax-case stax ()
> ((_ thing)
> (begin
> (pk 'syntax #'thing 'pair? (pair? #'thing))
> (pk 'car (car #'thing)))))))
>
> (mysyntax (c d))
>
>
> results in
>
>
> ;;; (syntax (#<syntax a> #<syntax b>) pair? #t)
>
> ;;; (car #<syntax a>)
>
> ;;; (syntax #<syntax:test.scm:13:10 (c d)> pair? #f)
> Backtrace:
> 7 (primitive-load "/home/jean/repos/lilypond/build/test.s…")
> In ice-9/eval.scm:
> 721:20 6 (primitive-eval (mysyntax (c d)))
> In ice-9/psyntax.scm:
> 1229:36 5 (expand-top-sequence (#<syntax:test.scm:13:0 (mysynta…>) …)
> 1121:20 4 (parse _ (("placeholder" placeholder)) ((top) #(# # …)) …)
> 1342:32 3 (syntax-type (mysyntax #<syntax:test.scm:13:10 (c d)>) # …)
> 1562:32 2 (expand-macro #<procedure 7fa6fa335320 at ice-9/eval.s…> …)
> In ice-9/eval.scm:
> 159:9 1 (_ #(#(#<directory (guile-user) 7fa6fa3dfc80>) #<synt…>))
> 155:9 0 (_ _)
>
> ice-9/eval.scm:155:9: In procedure car: Wrong type argument in position
> 1 (expecting pair): #<syntax:test.scm:13:10 (c d)>
>
>
> Why does one syntax object look like a pair and not the other?
> What is the difference between the two cases?
>
> Thanks,
> Jean
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-04-05 18:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-04 23:00 Syntax objects as traditional pairs Jean Abou Samra
2022-04-05 18:23 ` Linus Björnstam
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).