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: 2 macros in one expression Date: Sat, 15 Apr 2023 18:25:46 +0200 Message-ID: References: <4187fdcf-5bee-8e9d-3ec1-19cc55e36fc3@gmail.com> 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="6529"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user@gnu.org To: Matt Wette Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Apr 15 18:26:25 2023 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 1pnijJ-0001a4-AP for guile-user@m.gmane-mx.org; Sat, 15 Apr 2023 18:26:25 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pnij2-0004i9-Ty; Sat, 15 Apr 2023 12:26:09 -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 1pniiw-0004gn-Jr for guile-user@gnu.org; Sat, 15 Apr 2023 12:26:04 -0400 Original-Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pniiu-0001re-26 for guile-user@gnu.org; Sat, 15 Apr 2023 12:26:02 -0400 Original-Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-5055141a8fdso2521582a12.3 for ; Sat, 15 Apr 2023 09:25:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681575958; x=1684167958; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=6OycD4ixxDN9rBg83tXFaREWHr9GsX3AuweeFXfwfMc=; b=fdZ/dYNtNqKA/Hivjhd59+pWUBG+esyBRsGxSKMroZ2U5RlDmRH/XxdCqMn9bhTNSP kDwHuCOt2FvILICmPNVZiNO91idF3Of/p2w7bjq5IQ0OJDQn0TwPrL2AHucpMkxXA9U+ IbZKLiMgoBi5olGvexdn2tsuvv1Su1IRSJKImHTZumVMuGXFTlquTqAxd1RSpRLGuIhY zS6jdqBl+Fty1zhJzSZ52lI3BNJZJEcNqItZdXpswB0xuVI5cFAecTs4fu+5+1Qi+fwe A0LfOaINrIwe4vvI0n0P6SGhsiOePkhEYaNgr58LoRS9E/9rw/L2hnANQ1dYmSj7hrW/ wiBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681575958; x=1684167958; h=cc: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=6OycD4ixxDN9rBg83tXFaREWHr9GsX3AuweeFXfwfMc=; b=fRxlBx60tfYW7yqZNrDuav+sBwW/UTDwqF7abQVisBt2l90R77zfVTSbJiRuMcqLdJ R42Cmr9SSUCg/pw0lnRVdtZ6n0ELVmnra7DCGgjf4FpA7HFSNVMcNrKTJDzvNfNbcNV7 M2Czk1G19MXiTcLBAcjyrb4Y7BeBQ+qheC9AypEnKDjhtttwpKXXYwOXiF958AfaX6XP O9HYCyySxiwfZ5dTFP0l+xGTShW3OhKlPnBn2mGYRyzJhra4xxaBdHVREMAJnadLqKaC bW0MXylVSw2KWaabxNtWNpEzPMFFPm+c+sBGvxqMQShkBSzjZh6WbH9u/KHiaTR4vQGy ddMw== X-Gm-Message-State: AAQBX9faxbrSUu8G+78ZXjUss9iHSYopFgDSvgTNrMhkrPUzKI2v3ZXD CeYWZiK1lgsE7h3QdWpherQRko792Ob141FsdtpOmHJC0jw= X-Google-Smtp-Source: AKy350a3PqKWxeCtacWGXbLhh5jKvSKCTbktIJM19LxtwH+Qiw4+wk+4NgtDKcS9gham4fomFypuWuGL4xfZZre1H+w= X-Received: by 2002:a50:9b0e:0:b0:504:7684:a23c with SMTP id o14-20020a509b0e000000b005047684a23cmr4794986edi.8.1681575958016; Sat, 15 Apr 2023 09:25:58 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::52c; envelope-from=damien.mattei@gmail.com; helo=mail-ed1-x52c.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:18965 Archived-At: the same expression in Scheme would be: (set! xp (/ (- x (* v t)) (sqrt (- 1 (/ (expt v 2) (expt c 2)))))) > xp -1102228130.2405226 a bit less readable than: {xp <- {x - v * t} / (sqrt {1 - v ** 2 / c ** 2})} -1102228130.2405226 or: {xp =E2=86=90 {x - v * t} / (sqrt {1 - v ** 2 / c ** 2})} -1102228130.2405226 note: i admit the =E2=86=90 is hard to get on keyboards ;-) On Sat, Apr 15, 2023 at 6:15=E2=80=AFPM Damien Mattei wrote: > it works pretty well again now the new version is debugged, this code is > related to infix evaluation in Scheme+ with operator precedence , here is > an example: > > ;;; compiled > /Users/mattei/.cache/guile/ccache/3.0-LE-8-4.6/usr/local/share/guile/site= /3.0/Scheme+.scm.go > scheme@(guile-user)> { 4 + 3 * 2 - 19 < 0 - 4} > $1 =3D #t > scheme@(guile-user)> (define i 3) > scheme@(guile-user)> {i <- i + 1} > $2 =3D 4 > scheme@(guile-user)> (define c 300000) > scheme@(guile-user)> (define v 299990) > scheme@(guile-user)> (define t 30) > scheme@(guile-user)> (define x 120) > scheme@(guile-user)> (declare xp) > scheme@(guile-user)> {xp <- {x - v * t} / (sqrt {1 - v ** 2 / c ** 2})} > $3 =3D -1102228130.2405226 > scheme@(guile-user)> '{xp <- {x - v * t} / (sqrt {1 - v ** 2 / c ** 2})} > $4 =3D ($nfx$ xp <- ($nfx$ x - v * t) / (sqrt ($nfx$ 1 - v ** 2 / c ** 2)= )) > > could be written also this way: > {c <+ 300000} > {v <+ 299990} > {t <+ 30} > {x <+ 120} > (declare xp) > { xp <- {x - v * t} / (sqrt {1 - v ** 2 / c ** 2}) } > =3D -1102228130.2405226 > xp > =3D -1102228130.2405226 > > it is not far from what the Python syntax allow in term of readability: > > c=3D300000 > v=3D299990 > t=3D30 > x=3D120 > xp =3D (x - v * t) / math.sqrt (1 - v ** 2 / c ** 2) > xp > -1102228130.2404253 > > > On Sat, Apr 15, 2023 at 4:45=E2=80=AFPM Damien Mattei > wrote: > >> my problem is solved by quoting the variable that CAN store a special >> form (example: <-) and forcing its evaluation ! : (eval (quote opspecia= l) >> (interaction-environment)) >> >> here is my 'else clause: >> >> (else (! ident (eval (quote opspecial) (current-namespace)) term1 op >> term2)))))) >> >> for Racket, in Guile , not tested but it should be: >> (else (! ident (eval (quote opspecial) (interaction-environment)) term1 >> op term2)))))) >> >> again the else clause WILL NEVER be evaluated with opspecial being a >> special form but it is always expanded and that was enought to make an >> error. >> >> I admit reading Kent Dybvig article on macro and with a good scheme (as >> Guile) that implement some special feature of the article and it should >> exist a more elegant solution than : (eval (quote opspecial) >> (interaction-environment)) >> quoting with immediate evaluation ! :-/ >> Damien >> >> >> >> On Sat, Apr 15, 2023 at 4:18=E2=80=AFPM Damien Mattei >> wrote: >> >>> yes i tried it, i often get this answer :-) with this sort of problem i >>> recurrent have with macros and it never helps ,at the point i never >>> understood what is the use of this option in syntax-rules. >>> >>> My error i think was to forget the expansion stage of macro expansion >>> that is always done for all the macros used in an expression at any lev= el, >>> even if the code is not used in a branch of 'if ,'cond or other conditi= onal >>> the macros will be expansed. >>> >>> I will quote the <- in the opspecial and tried to eval it later, the >>> problem is with eval which is not really normalised between all >>> implementations of scheme concerning its environment of evaluation. >>> I will post the result. >>> The problem was also that in an infix evaluator i wanted to be able to >>> evaluate all procedure (that is ok) and all the macro too which is not >>> always possible with the evaluation technique i use ,it is hard to writ= e an >>> infix evaluator with precedence in the language itself.But the problem >>> arise only with the special forms, so first i quoted them all but then = i >>> can not find the difference in the language with '(sin 30) a procedure = call >>> and '(1 2 3) a list when evealuating it is has sense for (sin 30) but = not >>> for (1 2 3) then i removed all quotation and the macro problem arise..= . >>> just after i added some overloading functionalities in my Scheme+ when >>> using abstract types the evaluation of abstract object (list) with for >>> example the + operator overloaded became a problem. >>> Damien >>> >>> On Sat, Apr 15, 2023 at 3:50=E2=80=AFPM Matt Wette wrote: >>> >>>> Did you try using the following? >>>> >>>> (define-syntax $nfx$ >>>> (syntax-rules (<-) >>>> ((... >>>> >>>> >>>> On 4/14/23 4:02 AM, Damien Mattei wrote: >>>> > hello, >>>> > >>>> > i have 2 macros used in one expression like this: >>>> > scheme@(guile-user)> (define i 2) >>>> > scheme@(guile-user)> {i <- i + 1} >>>> > and i got this error: >>>> > While compiling expression: >>>> > Syntax error: >>>> > unknown location: source expression failed to match any pattern in >>>> form <- >>>> > >>>> > i use SRFI-105 so : >>>> > '{i <- i + 1} expand in: >>>> > ($nfx$ i <- i + 1) >>>> > >>>> > and i'm expecting $nfx$ to be called but none of this happens: >>>> > scheme@(guile-user)> ($nfx$ i <- i + 1) >>>> > While compiling expression: >>>> > Syntax error: >>>> > unknown location: source expression failed to match any pattern in >>>> form <- >>>> > >>>> > it seems to be the <- macro and i do not understand why? >>>> > >>>> > any idea? >>>> > >>>> > macros are defined like this for the beginning: >>>> > ;; from file assignment.scm >>>> > (define-syntax <- >>>> > >>>> > (syntax-rules () >>>> > ;; special form like : (<- ($bracket-apply$ T 3) >>>> ($bracket-apply$ T 4)) >>>> > >>>> > ;; one dimension array, example: {a[4] <- 7} >>>> > ;; $bracket-apply$ is from SRFI 105 bracket-apply is an >>>> argument of >>>> > the macro >>>> > ((_ (bracket-apply container index) expr) >>>> > >>>> > .... >>>> > >>>> > ;; from file scheme-infix.scm >>>> > (define-syntax $nfx$ >>>> > (syntax-rules () >>>> > >>>> > ((_ ident opspecial term1 op term2) (cond ((or (equal? (quote >>>> > opspecial) (quote <-)) (equal? (quote opspecial) (quote =E2=86=90))) >>>> > (begin >>>> > (display "$nfx$") (newline) >>>> > (opspecial ident (op term1 term2)))) ;; {ident <- {term1 op term2}} >>>> > >>>> > ... >>>> > >>>> > >>>> > it is in a module like this: >>>> > >>>> > (define-module (Scheme+) >>>> > >>>> > #:use-module (growable-vector) >>>> > #:use-module (srfi srfi-69) ;; Basic hash tables >>>> > #:use-module (srfi srfi-31) ;; rec >>>> > #:export ($nfx$ def $bracket-apply$ <- =E2=86=90 -> =E2=86=92 <+ = =E2=A5=86 +> =E2=A5=85 declare $ >>>> & condx >>>> > <> =E2=89=A0 ** =E2=87=9C =E2=87=9D repeat) >>>> > #:replace (do when unless)) >>>> > >>>> > >>>> > >>>> > (include-from-path "def.scm") >>>> > (include-from-path "array.scm") >>>> > (include-from-path "set-values-plus.scm") >>>> > (include-from-path "apply-square-brackets.scm") >>>> > (include-from-path "assignment.scm") >>>> > (include-from-path "declare.scm") >>>> > (include-from-path "condx.scm") >>>> > (include-from-path "block.scm") >>>> > (include-from-path "not-equal.scm") >>>> > (include-from-path "exponential.scm") >>>> > (include-from-path "while-do-when-unless.scm") >>>> > (include-from-path "repeat-until.scm") >>>> > (include-from-path "scheme-infix.scm") >>>> > >>>> > if it can help. >>>> > >>>> > Regards, >>>> > Damien >>>> >>>