From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Damien Mattei Newsgroups: gmane.lisp.guile.user Subject: Re: equality of syntax objects Date: Mon, 20 May 2024 23:21:34 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5716"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-user Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Mon May 20 23:22:33 2024 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1s9ASm-0001Gg-Tb for guile-user@m.gmane-mx.org; Mon, 20 May 2024 23:22:33 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9ASB-00062S-BK; Mon, 20 May 2024 17:21:55 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9AS8-00062A-V6 for guile-user@gnu.org; Mon, 20 May 2024 17:21:53 -0400 Original-Received: from mail-qv1-xf32.google.com ([2607:f8b0:4864:20::f32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s9AS5-0003Qm-W9 for guile-user@gnu.org; Mon, 20 May 2024 17:21:52 -0400 Original-Received: by mail-qv1-xf32.google.com with SMTP id 6a1803df08f44-6a919a4bb83so8635806d6.1 for ; Mon, 20 May 2024 14:21:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716240108; x=1716844908; darn=gnu.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=d68YTNol3O2h2XqQaNvI4I3etvaSLQ6/oe8XBC/gzHc=; b=iWYFufTOiabDzhx+S2Oi219WOPRJJuY/p4Lxq53ji3fWG3irvb8K/ss+9HpalcBA8Q IO2ks7bJXR8IG5C8Nwa16cT7NZjOcS7qsYrzdWEZ+4/ZGTnt9sMbJDB7ucvFB4rpyyoh ofscGy/UPXEMSsi3w3Fa82tTmbEckCzYq5sdStv6S8FTgPGvcNnXvz6AVCa4wfffpHB5 Lw1GtusfwWd0kJKyO4mdtO+sIBjRVjbwi/GnAIRXgxYAaJw9kKvPeqBNz3rzqn5n1ZO7 UrARVRFKXs9+Hp0ld0EvSJqNVON0ZGaLhL2O2HuPN3AkYCtsUpwpdTQQ6jnc3lVPy7Vu jvPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716240108; x=1716844908; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=d68YTNol3O2h2XqQaNvI4I3etvaSLQ6/oe8XBC/gzHc=; b=WFBVy4jd8jUjVnkuB3N9d8YQwCQPeHxmTJUiOfwbb1WsCnc5r7QIBBw+zUt3VnYdam QLts3ptTWeZYDzyEUaPMsAY6r48M1lBNgSl9uW51fnd4sPWEjCenO3CaRJe+ZDUvZGAr LR8XflOE567WWVdvgLTRZMsInJ4Sqzl4VZ7Qmin2m8dgNnyeyOz/8xDzL1xFdqGgFXVS TT0fBJb02BZAqs3R3hm8FA87jy0UosGpqQW1SVmPWJi5zTUMSjFbrW1G79McKeDGc9QC OXv+BWx74N6vhIq9hzMlPvybfn25qSYqChP65dgFusHIN8rh8w5ZLAy9NSKuHora2owR wM+Q== X-Gm-Message-State: AOJu0YzEHasKxAE50297X5YeI/EGySHJ+wec4i7RvTSZzAVJCtINFwiJ cYm2eoFjYV9oAsRQITqYxMtv63sqCZaHYuvuGeAEc4aPvvGv+gEX5z/H4TvjXdMNP8wBuvBQ9rW xvWXv5EtCI152k8eSKxA1cUAhf2BT6hJ5jqo= X-Google-Smtp-Source: AGHT+IGrGOmvTEYoZFAJj7d6sRAeTo3I3e5NbKm4Vo9jAH7ifIHSM7ZmtmtE87c1C1XHLXlRfrUCm2E1VYzzc3nC7qQ= X-Received: by 2002:a05:6214:3389:b0:6ab:2008:4545 with SMTP id 6a1803df08f44-6ab20178a48mr37250606d6.31.1716240108414; Mon, 20 May 2024 14:21:48 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::f32; envelope-from=damien.mattei@gmail.com; helo=mail-qv1-xf32.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.user:19663 Archived-At: it works :-) (define (syntax-string=3D? 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=3D? (car (reverse lst-split-str-obj1)) (car (reverse lst-split-str-obj2)))) (define (check-syntax=3D? obj1 obj2) ;; (display "check-syntax=3D? : obj1 =3D") (display obj1) (newline) ;; (display "check-syntax=3D? : obj2 =3D") (display obj2) (newline) (define rv (and (identifier? obj1) ;(syntax? obj1) (identifier? obj2) ;(syntax? obj2) (or (free-identifier=3D? obj1 obj2) ; a procedure can be overloaded (syntax-string=3D? obj1 obj2)))) ; this solve the overloaded prob= lem ;;(display "check-syntax=3D? : rv =3D") (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} =3D 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=3D3 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=E2=80=AFPM Damien Mattei 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,h= ow > 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: > "#" > "#" > 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 fallin= g > on an old #'expt that match an old procedure ,i'm not sure it is clear bu= t > i already do it last year for the same problem when parsing not syntax bu= t > 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 reliabl= e, > 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=E2=80=AFPM Damien Mattei > wrote: > >> hello, >> >> i want to check the equality of two syntax objects. >> >> i wrote this macro: >> >> (define (check-syntax=3D? obj1 obj2) >> (display "check-syntax=3D? : obj1 =3D") (display obj1) (newline) >> (display "check-syntax=3D? : obj2 =3D") (display obj2) (newline) >> (define rv >> (and (identifier? obj1) ;(syntax? obj1) >> (identifier? obj2) ;(syntax? obj2) >> (free-identifier=3D? obj1 obj2))) >> (display "check-syntax=3D? : rv =3D") (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 t= he >> syntax object also: >> >> when computing {1 + 2 expt 3} >> gives right result: >> 9 >> >> note that this computation requires operator precedence analysis doing o= n >> the syntax by the process... >> >> debug output include: >> >> check-syntax=3D? : obj1 =3D# >> check-syntax=3D? : obj2 =3D# >> check-syntax=3D? : rv =3D#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 =3D 8 >> and is now an n-arity operator: >> scheme@(guile-user)> {2 expt 3 expt 4} >> $6 =3D 2417851639229258349412352 >> scheme@(guile-user)> (expt 2 3 4) >> $7 =3D 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 f= rom >> left to right) >> but that is of little importance with the current problem. >> >> expt looks now like that: >> scheme@(guile-user)> expt >> $3 =3D # >> new-funct is an inner function created by overloading process. >> >> and : >> scheme@(guile-user)> #'expt >> $4 =3D # >> >> 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=3D? : obj1 =3D# >> check-syntax=3D? : obj2 =3D# >> check-syntax=3D? : rv =3D#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 i= s >> of no concern with the problem again) >> >> What i understand is even if obj1 and obj2 display the same in the outpu= t >> 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 prett= y >> 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 >> >> >> >> >> >>