guile-user
[Top][All Lists]
Advanced

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

Re: with-syntax return error in Guile, not in Kawa or Racket


From: Damien Mattei
Subject: Re: with-syntax return error in Guile, not in Kawa or Racket
Date: Sat, 11 May 2024 12:53:16 +0200

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
>


reply via email to

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