asked more simply:

how to know ,for two syntax objects now different but that represents two
different procedures created with the same name at two different moment,how
to know that the names are still the same?

i see two solutions:
-parse the representation string to know for example expt that expt is in
both string:
"#<syntax:unknown file:2:7 expt>"
"#<syntax:operation-redux.scm:88:12 expt>"
not really pretty but will work.I test it in Racket and kawa too...

-keep an up to date value of #'expt to use it for compare to avoid falling
on an old #'expt that match an old procedure ,i'm not sure it is clear but
i already do it last year for the same problem when parsing not syntax but
sexpr composed of real procedures (that were changing in time due to
overloading) or quoted ones (which is the worse because you have to
re-evaluate later and it again depends of context....and that not reliable,
but quoting (with syntax) is the only solution to manipulate 'and' / 'or'.

So i think the best solution is the simple and not pretty that rely on
parsing the string representation.

On Mon, May 20, 2024 at 1:42 PM Damien Mattei <damien.mat...@gmail.com>
wrote:

> hello,
>
> i want to check the equality of two syntax objects.
>
> i wrote this macro:
>
> (define (check-syntax=? obj1 obj2)
>   (display "check-syntax=? : obj1 =") (display obj1) (newline)
>   (display "check-syntax=? : obj2 =") (display obj2) (newline)
>   (define rv
>     (and (identifier? obj1) ;(syntax? obj1)
>             (identifier? obj2) ;(syntax? obj2)
>             (free-identifier=? obj1 obj2)))
>   (display "check-syntax=? : rv =") (display rv) (newline)(newline)
>   rv)
>
> What works:
>
> if i have expt (exponentiation) , the same procedure used and checked from
> to different files, i have this output in debug when doing some processing,
> note i think  it is important to focus on the filenames of the syntax
> object also:
>
> when computing {1 + 2 expt 3}
> gives right result:
> 9
>
> note that this computation requires operator precedence analysis doing on
> the syntax by the process...
>
> debug output include:
>
> check-syntax=? : obj1 =#<syntax:unknown file:2:7 expt>
> check-syntax=? : obj2 =#<syntax:operation-redux.scm:88:12 expt>
> check-syntax=? : rv =#t
>
> now i change expt by overloading itself by one of my macro:
>
> (overload-existing-operator expt expt (number? number?))
>
> i will not explain what is the overloading algorithm here and why i
> overload expt.(in summary to allow n-arity with exponential such as {2 ** 3
> ** 4} or {2 expt 3 expt 4}
> But note that expt is still working,even in infix guile mode:
> scheme@(guile-user)> {2 expt 3}
> $2 = 8
> and is now an n-arity operator:
> scheme@(guile-user)> {2 expt 3 expt 4}
> $6 = 2417851639229258349412352
> scheme@(guile-user)> (expt 2 3 4)
> $7 = 2417851639229258349412352
> (and with evaluation from right to left as by convention for expt ,which
> is different for operator such as + or - or * and / that are evaluated from
> left to right)
> but that is of little importance with the current problem.
>
> expt looks now like that:
> scheme@(guile-user)> expt
> $3 = #<procedure new-funct args>
> new-funct is an inner function created by overloading process.
>
> and :
> scheme@(guile-user)> #'expt
> $4 = #<syntax:unknown file:7:2 expt>
>
> syntax looks like the original expt , no problem with that.
>
> now the ouput in debug,after overloading expt:
>
> on the calculus:
> {1 + 2 expt 3}
> note that this computation again requires operator precedence analysis
> doing on the syntax by the process...
>
> check-syntax=? : obj1 =#<syntax:unknown file:8:7 expt>
> check-syntax=? : obj2 =#<syntax:operation-redux.scm:88:12 expt>
> check-syntax=? : rv =#f
>
>
> and the result 3 is wrong  .(calculus has been truncated to first value 3
> at rightmost as computation with expt goes from right to left but that is
> of no concern with the problem again)
>
> What i understand is even if obj1 and obj2 display the same in the output
> debug,the expt definition has changed and the checking is not only about
> litteral syntax but also with an hidden environment or context.
>
> That seems normal about syntax in all scheme.
>
> But i want ,for this point , only to manipulate "mathematic" syntax here.
>
> I have a few simple or complex idea for solution , some not really pretty
> and i ask opinion for solving this problem?
>
> just what i need is a way to find equal the expt even if it has been
> modified, only from a litteral point of view here.
>
> regards,
>
> damien
>
>
>
>
>
>

Reply via email to