guile-user
[Top][All Lists]
Advanced

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

Re: Syntax objects as traditional pairs


From: Linus Björnstam
Subject: Re: Syntax objects as traditional pairs
Date: Tue, 05 Apr 2022 20:23:23 +0200
User-agent: Cyrus-JMAP/3.7.0-alpha0-385-g3a17909f9e-fm-20220404.001-g3a17909f

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



reply via email to

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