From: Damien Mattei <damien.mattei@gmail.com>
To: Jean Abou Samra <jean@abou-samra.fr>
Cc: guile-user <guile-user@gnu.org>
Subject: Re: with-syntax return error in Guile, not in Kawa or Racket
Date: Mon, 6 May 2024 09:27:16 +0200 [thread overview]
Message-ID: <CADEOaddAP89R8ZkcsFsVtfkpHvinkq3f+Uey-26-yHGTO3W10Q@mail.gmail.com> (raw)
In-Reply-To: <CADEOadcfS0Voaw_K7z3X+Pjsa2H97zGT+wf+VYgGj_A4nPbonw@mail.gmail.com>
a working solution , but does not know if it follows standards of scheme:
(define-syntax $bracket-apply$
(lambda (stx)
(syntax-case stx ()
;; scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[6 - 4 : 5 + 2]}
;; $bracket-apply$ : parsed-evaluated-args=#<syntax (list (- 6 4) : (+ 5
2))>
;; $1 = #(3 4 5 6 7)
;; scheme@(guile-user)> (define i 5)
;; scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[6 - 4 : i + 2]}
;; $bracket-apply$ : parsed-evaluated-args=#<syntax (list (- 6 4) : (+ i
2))>
;; $2 = #(3 4 5 6 7)
(($bracket-apply$ container . args-brackets)
(with-syntax ((parsed-evaluated-args (datum->syntax #f
(cons 'list
(optimizer-parse-square-brackets-arguments-lister (syntax->datum
#'args-brackets))))))
(display "$bracket-apply$ : parsed-evaluated-args=") (display
#'parsed-evaluated-args) (newline)
#'($bracket-apply$next4list-args container parsed-evaluated-args))))))
On Sun, May 5, 2024 at 3:35 PM Damien Mattei <damien.mattei@gmail.com>
wrote:
> i understand Jean, do you have an idea to fix this macro, i'm not far away
> from the result as the display show it
>
> i'm modifying a macro that worked but i want to write it in a more modern
> way (macro talking), this do the same than in Python in this example:
> Python 3.11.2 (v3.11.2:878ead1ac1, Feb 7 2023, 10:02:41) [Clang 13.0.0
> (clang-1300.0.29.30)] on darwin
> Type "help", "copyright", "credits" or "license()" for more information.
>
> [0, 1 ,2 ,3, 4, 5,6 ,8,9][6 - 4 : 5 + 2]
> [2, 3, 4, 5, 6]
>
> the guile output:
>
> scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[6 - 4 : 5 + 2]}
> $bracket-apply$ : parsed-evaluated-args=((- 6 4) : (+ 5 2))
> While compiling expression:
> Syntax error:
> unknown file:#f:#f: encountered raw symbol in macro output in subform - of
> ($bracket-apply$ #(1 2 3 4 5 6 7 8 9) 6 - 4 : 5 + 2)
> scheme@(guile-user)> '{#(1 2 3 4 5 6 7 8 9)[6 - 4 : 5 + 2]}
> $1 = ($bracket-apply$ #(1 2 3 4 5 6 7 8 9) 6 - 4 : 5 + 2)
> scheme@(guile-user)> ($bracket-apply$ #(1 2 3 4 5 6 7 8 9) 6 - 4 : 5 + 2)
> $bracket-apply$ : parsed-evaluated-args=((- 6 4) : (+ 5 2))
> While compiling expression:
> Syntax error:
> unknown file:#f:#f: encountered raw symbol in macro output in subform - of
> ($bracket-apply$ #(1 2 3 4 5 6 7 8 9) 6 - 4 : 5 + 2)
>
> as you can see i have the good syntax from infix to prefix:
> $bracket-apply$ : parsed-evaluated-args=((- 6 4) : (+ 5 2))
> how can i make the macro result be what i want, here is the actual one:
>
> (define-syntax $bracket-apply$
>
> (lambda (stx)
>
> (syntax-case stx ()
>
> (($bracket-apply$ container . args-brackets)
>
> (with-syntax ((parsed-evaluated-args
> (optimizer-parse-square-brackets-arguments-lister (syntax->datum
> #'args-brackets))))
> (display "$bracket-apply$ : parsed-evaluated-args=") (display
> #'parsed-evaluated-args) (newline)
>
> #'($bracket-apply$next4list-args container parsed-evaluated-args))))))
>
> a working solution was:
>
> {#(1 2 3 4 5 6 7)[2 * 5 - 8 : 3 * 5 - 10]}
> '#(3 4 5)
>
> {#(1 2 3 4 5 6 7)[2 * 5 - 8 : 3 * 5 - 10 : 2 * 4 - 6]}
> '#(3 5)
> scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[6 - 4 : 5 + 2]}
> $bracket-apply$ : args-brackets=(6 #<procedure - (#:optional _ _ . _)> 4 :
> 5 #<procedure + (#:optional _ _ . _)> 2)
> $1 = #(3 4 5 6 7)
> scheme@(guile-user)> {#(1 2 3 4 5 6 7 8 9)[2 * 3 - 4 : 2 * 5 - 3]}
> $bracket-apply$ : args-brackets=(2 #<procedure * (#:optional _ _ . _)> 3
> #<procedure - (#:optional _ _ . _)> 4 : 2 #<procedure * (#:optional _ _ .
> _)> 5 #<procedure - (#:optional _ _ . _)> 3)
> $2 = #(3 4 5 6 7)
> (define ($bracket-apply$ container . args-brackets) ;; this implements a
> possible $bracket-apply$ as proposed in SRFI-105
>
> ;;(display "$bracket-apply$ : args-brackets=") (display args-brackets)
> (newline)
> ;;(display "$bracket-apply$ : infix-operators-lst=") (display
> infix-operators-lst) (newline)
> ($bracket-apply$next4list-args container
> (optimizer-parse-square-brackets-arguments-evaluator args-brackets)))
>
> but i want to avoid optimizer-parse-square-brackets-arguments-evaluator at
> run time , i prefer to use optimizer-parse-square-brackets-arguments-lister
> at a macro stage earlier ,so not rexecuted at each computation, but this an
> idea, perheaps not pertinent...
>
> sorry for long, obscure mail...
>
>
>
> On Sun, May 5, 2024 at 2:48 PM Jean Abou Samra <jean@abou-samra.fr> wrote:
>
>>
>> > (base) mattei@mbp-touch-bar Scheme-PLUS-for-Guile % guile
>> > GNU Guile 3.0.8.99-f3ea8
>> > Copyright (C) 1995-2022 Free Software Foundation, Inc.
>> >
>> > Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
>> > This program is free software, and you are welcome to redistribute it
>> > under certain conditions; type `,show c' for details.
>> >
>> > Enter `,help' for help.
>> > scheme@(guile-user)> (define-syntax test-it
>> > (lambda (stx)
>> > (syntax-case stx ()
>> > ((_ term1)
>> > (with-syntax ((var (syntax->datum #'term1)))
>> > #'var)))))
>> > scheme@(guile-user)> (test-it (+ 2 3))
>> > While compiling expression:
>> > Syntax error:
>> > unknown file:#f:#f: encountered raw symbol in macro output in subform +
>> of
>> > (test-it (+ 2 3))
>>
>>
>> As the error message says, your macro contains the raw symbol `term1`.
>> The expression (syntax->datum #'term1) is equivalent to 'term1 .
>> What's raising the error is not with-syntax itself, it's the fact
>> that a hygienic macro must return syntax objects, and a raw
>> symbol is not a syntax object. Kawa and Racket probably have some
>> fallback where the macro becomes non-hygienic when it returns
>> raw symbols. But R6RS makes it clear that this is not standard
>> Scheme. See
>>
>>
>> https://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-13.html#node_sec_12.2
>>
>> """
>> a syntax object is:
>>
>> - a pair of syntax objects,
>> - a vector of syntax objects,
>> - a nonpair, nonvector, nonsymbol value, or
>> - a wrapped syntax object
>> """
>>
>> """
>> A transformation procedure is a procedure that must accept one argument, a
>> wrapped syntax object (section 12.2) representing the input, and return a
>> syntax
>> object (section 12.2) representing the output.
>> """
>>
>>
>>
next prev parent reply other threads:[~2024-05-06 7:27 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-05 12:36 with-syntax return error in Guile, not in Kawa or Racket Damien Mattei
2024-05-05 12:48 ` Jean Abou Samra
2024-05-05 13:35 ` Damien Mattei
2024-05-06 7:27 ` Damien Mattei [this message]
2024-05-06 9:41 ` Jean Abou Samra
2024-05-06 10:29 ` Damien Mattei
2024-05-06 12:03 ` Damien Mattei
2024-05-06 17:52 ` Damien Mattei
2024-05-06 18:58 ` Maxime Devos
2024-05-06 21:34 ` Damien Mattei
2024-05-09 9:21 ` Maxime Devos
2024-05-09 21:56 ` Damien Mattei
2024-05-09 22:35 ` Jean Abou Samra
2024-05-10 9:40 ` Damien Mattei
2024-05-10 10:33 ` Jean Abou Samra
2024-05-10 13:52 ` Damien Mattei
2024-05-10 15:24 ` Jean Abou Samra
2024-05-10 20:21 ` Damien Mattei
2024-05-11 10:53 ` Damien Mattei
2024-05-11 19:14 ` Jean Abou Samra
2024-05-12 12:37 ` Damien Mattei
2024-05-10 21:57 ` Damien Mattei
2024-05-10 22:23 ` Jean Abou Samra
2024-05-10 23:04 ` Damien Mattei
2024-05-15 17:44 ` Macros that don't work Keith Wright
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=CADEOaddAP89R8ZkcsFsVtfkpHvinkq3f+Uey-26-yHGTO3W10Q@mail.gmail.com \
--to=damien.mattei@gmail.com \
--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).