unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Damien Mattei <damien.mattei@gmail.com>
To: guile-user <guile-user@gnu.org>
Subject: equality of syntax objects
Date: Mon, 20 May 2024 13:42:15 +0200	[thread overview]
Message-ID: <CADEOadf=KK2dZpa=sES+YrfG7qsYTjg4EYDg6pBMVB-EaxjrTQ@mail.gmail.com> (raw)

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	other threads:[~2024-05-20 11:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-20 11:42 Damien Mattei [this message]
2024-05-20 14:53 ` equality of syntax objects Damien Mattei
2024-05-20 21:21   ` Damien Mattei
2024-05-22 22:12   ` Maxime Devos
2024-05-23 13:55     ` Damien Mattei

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='CADEOadf=KK2dZpa=sES+YrfG7qsYTjg4EYDg6pBMVB-EaxjrTQ@mail.gmail.com' \
    --to=damien.mattei@gmail.com \
    --cc=guile-user@gnu.org \
    /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).