it works :-)

(define (syntax-string=? obj1 obj2)
  (define str-obj1 (format #f "~s" obj1))
  (define str-obj2 (format #f "~s" obj2))
  (define lst-split-str-obj1 (string-split str-obj1 #\space))
  (define lst-split-str-obj2 (string-split str-obj2 #\space))
  (string=? (car (reverse lst-split-str-obj1)) (car (reverse
lst-split-str-obj2))))

(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)
    (or (free-identifier=? obj1 obj2) ; a procedure can be overloaded
          (syntax-string=? obj1 obj2)))) ; this solve the overloaded problem
  ;;(display "check-syntax=? : rv =") (display rv) (newline)(newline)
  rv)

scheme@(guile-user)> (define x 3)
scheme@(guile-user)> {2.0 / 3.0 * 4.0 + 2.0 ** x ** 4.0 - 1.0}
= 2.4178516392292583e24

Python check:
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.
x=3
2.0 / 3.0 * 4.0 + 2.0 ** x ** 4.0 - 1.0
2.4178516392292583e+24

same result :-)

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

> 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