From: Damien Mattei <damien.mattei@gmail.com>
To: Jean Abou Samra <jean@abou-samra.fr>
Cc: Maxime Devos <maximedevos@telenet.be>, guile-user <guile-user@gnu.org>
Subject: Re: with-syntax return error in Guile, not in Kawa or Racket
Date: Sat, 11 May 2024 12:53:16 +0200 [thread overview]
Message-ID: <CADEOadeFJ+x6LXZEwu+d5vwWyS9DDb8Erk2JGMeUeHz9B9FxGg@mail.gmail.com> (raw)
In-Reply-To: <CADEOadcC3UPOxo=ZV5L9cdvC9wWEz50mHpESQbXJjOPB7D6K4A@mail.gmail.com>
i understand the problem i have now in this new version, it is in the
features of SRFI 105 :
$brackett-apply$ $nfx$ and more that deals with [ ] , infix where i need to
parse for operator precedence
i have procedure for that: optimizer-parse-square-brackets-arguments-lister
it takes a list in infix ,more complex than infix because it is compatible
with the sliced format in Python (you know start : stop : step ,start ,step
,stop being infix expressions...)
the problem when pre-compiling/pre-computing those lists is that with #' ,i
mean syntax, the optimizer-parse-square-brackets-arguments-lister no more
receive lists but this sort of expression:
scheme@(guile-user)> (define T (make-vector 7))
scheme@(guile-user)> {T[2 + 1] <- 7}
<- : #'(index ...) = (#<syntax:unknown file:3:3 2> #<syntax:unknown
file:3:5 +> #<syntax:unknown file:3:7 1>)
<- : (syntax->datum #'(index ...)) = (2 + 1)
optimizer-parse-square-brackets-arguments-lister :
args-brackets=(#<syntax:unknown file:3:3 2> #<syntax:unknown file:3:5 +>
#<syntax:unknown file:3:7 1>)
this expression is send to optimizer-parse-square-brackets-arguments-lister:
(#<syntax:unknown file:3:3 2> #<syntax:unknown file:3:5 +> #<syntax:unknown
file:3:7 1>)
because i removed the (syntax->datum #'(index ...))
and simply give:
#'(index ...)
index ... are from the macro pattern:
((_ (brket-applynext container index ...) expr)
my question is how to deal with that? becaue in the parser i check ,for
example for + being '+ not some sort of #<syntax:unknown file:3:5 +>
i suppose the problem come from here
should i modify the parser to check for #'+ #'- #'* #'/ #'expt #'and #'or
etc... or is there something to do when i pass arguments in the macro?
also i pass #'(index ...) creating a sort of ( ) list ,how to pass th index
and ellipsis in a syntax form ?? should i put that in a list with list
procedure?
my parser used to be like this and worked with operators ,it is in multiple
file ,hard to display here:
(define (optimizer-parse-square-brackets-arguments-lister args-brackets)
(display "optimizer-parse-square-brackets-arguments-lister :
args-brackets=") (display args-brackets) (newline)
(optimizer-parse-square-brackets-arguments args-brackets
(lambda (op a b) (list op a b))
infix-operators-lst-for-parser))
sintax below is a bit scheme+ (use return...) but can easily understand , i
could have written it in tail recursive scheme also:
;; !*prec is defined in optimize-infix.scm
;; split the expression using slice as separator
(def (optimizer-parse-square-brackets-arguments args-brackets creator
operator-precedence)
;;(display "optimizer-parse-square-brackets-arguments : args-brackets=")
(display args-brackets) (newline)
(define operators-lst (apply append operator-precedence))
(when (null? args-brackets)
(return args-brackets))
(declare result partial-result)
(def (psba args) ;; parse square brackets arguments ,note: it is a
tail-recursive function (see end)
;;(display "psba : args=") (display args) (newline)
;;(display "psba : partial-result =") (display partial-result)
(newline)
(when (null? args)
;;(display "before !*prec") (newline)
(if (infix? partial-result operators-lst)
(set! result (append result (!*prec-generic partial-result
operator-precedence creator))) ;; !*prec-generic is defined in
optimize-infix.scm
(set! result (append result partial-result)))
;; (display "after !*prec") (newline)
;; (display result) (newline)
;; (display "return-rec") (newline)
(return-rec result)) ;; return from all recursive calls, as it is
tail recursive
(define fst (car args))
;;(display "fst=") (display fst) (newline)
(if (equal? slice fst) ; separator
($>
;;(display "slice detected") (newline)
;;(display "psba : partial-result =") (display partial-result)
(newline)
(when (not (null? partial-result))
;;(display "not null") (newline)
(if (infix? partial-result operators-lst) ;; TODO infix? plante a cause
des operateurs quotés
(begin
;;(display "infix detected") (newline)
(set! result (append result (!*prec-generic partial-result
operator-precedence creator)))) ;; convert to prefix and store the
expression
(set! result (append result partial-result)))
(set! partial-result '())) ;; empty for the next possible portion
between slice operator
(set! result (append result (list fst)))) ;; append the slice operator
(set! partial-result (append partial-result (list fst)))) ;; not a
slice operator but append it
;;(display "psba : result=") (display result) (newline)
;;(display "psba 2 : partial-result=") (display partial-result)
(newline)
(psba (cdr args))) ;; end def, recurse (tail recursive)
;;(display "parse-square-brackets-arguments : args-brackets=") (display
args-brackets) (newline)
(define rs (psba args-brackets))
;;(display "parse-square-brackets-arguments : rs=") (display rs) (newline)
rs
) ;; initial call
(define infix-operators-lst-for-parser
'(
(expt **)
(* / %)
(+ -)
(<< >>)
(& ∣)
(< > = ≠ <= >= <>)
(and)
(or)
;;(list 'dummy) ;; can keep the good order in case of non left-right
assocciative operators.(odd? reverse them)
(<- -> ← → := <v v> ⇜ ⇝)
(<+ +> ⥆ ⥅ :+)
)
)
;; liste à plate des operateurs
(define operators-lst
(apply append infix-operators-lst-for-parser))
there is too much code i can not put it here...
n-arity
infix?
too long...
it. is just to give an idea, i hope problem can be solved in the macro
call to optimizer-parse-square-brackets-arguments-lister
On Fri, May 10, 2024 at 10:21 PM Damien Mattei <damien.mattei@gmail.com>
wrote:
>
>
> On Fri, May 10, 2024 at 5:24 PM Jean Abou Samra <jean@abou-samra.fr>
> wrote:
>
>>
>> I'd need a reproducible example to debug this. I have no explanation
>> other than that there must be a trivial mistake somewhere in your
>> code or testing procedure (happens to everyone).
>>
>>
> i will try to isolate the problem out of 10000 lines of code but not sure
> to succeed
> there is no caveit in the testing procedure , i just have to
> comment/uncomment your procedure and mine, so no possible error in this
> procedure
>
> a mistake in my code would not change the fact that this code is a counter
> example to the cloning of a macro, the way you clone the macro should work
> for any macro that at least compile well. There is no error in the
> compilation of the macros.
>
>>
>> Well, here, the second example runs but display 6, not 5, i.e. it looks
>> up the global variable defined earlier, not the local one.
>>
> yes i did not noticed it
>
next prev parent reply other threads:[~2024-05-11 10:53 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
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 [this message]
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=CADEOadeFJ+x6LXZEwu+d5vwWyS9DDb8Erk2JGMeUeHz9B9FxGg@mail.gmail.com \
--to=damien.mattei@gmail.com \
--cc=guile-user@gnu.org \
--cc=jean@abou-samra.fr \
--cc=maximedevos@telenet.be \
/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).