unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: "Linus Björnstam" <linus.internet@fastmail.se>
To: "Jean Abou Samra" <jean@abou-samra.fr>, guile-user@gnu.org
Subject: Re: Syntax objects as traditional pairs
Date: Tue, 05 Apr 2022 20:23:23 +0200	[thread overview]
Message-ID: <0aa524c1-29b8-42ca-946a-6468ac6e6db4@www.fastmail.com> (raw)
In-Reply-To: <1024dc44-d9f2-80b5-4b26-01a3779052ee@abou-samra.fr>

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	other threads:[~2022-04-05 18:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-04 23:00 Syntax objects as traditional pairs Jean Abou Samra
2022-04-05 18:23 ` Linus Björnstam [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0aa524c1-29b8-42ca-946a-6468ac6e6db4@www.fastmail.com \
    --to=linus.internet@fastmail.se \
    --cc=guile-user@gnu.org \
    --cc=jean@abou-samra.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).