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 13:35:30 +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="18195"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-user Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Apr 15 13:36:27 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 1pneCh-0004Zv-9Z for guile-user@m.gmane-mx.org; Sat, 15 Apr 2023 13:36:27 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pneCJ-0006Za-9W; Sat, 15 Apr 2023 07:36:03 -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 1pneCG-0006WH-Aj for guile-user@gnu.org; Sat, 15 Apr 2023 07:36:00 -0400 Original-Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pneC2-0005wq-46 for guile-user@gnu.org; Sat, 15 Apr 2023 07:35:59 -0400 Original-Received: by mail-ej1-x631.google.com with SMTP id fy21so9092824ejb.9 for ; Sat, 15 Apr 2023 04:35:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681558542; x=1684150542; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=RDEMhaRULi8GpJ2iB8RVvuAVl16OQWP9p6kFFy/ExIg=; b=pIiyfLkansPvx5UK/tWnJdqzSfDiG8MwAxYhr2t71qg+2PbUotjqfwozSu51vHvvQL yHlTPsanaf3r8jICxACbbVDpSHTbnxc5W0evH5egAIWzF2NaYK2Eg6lwv6nCvVpzSCR/ Y7ujHDiCKy5nVZAfCkR9odn3aWq0wJlIeXANl8U2tewEp8NjHhYhfeNUp6qRqU5nCcI0 LzMBKun1mvsO0NmHBOYBXuXP9ICpSfQRAgeXJWoJLFsrtNRH58AtWXohZru8lPymsraL OB3eCcWQIPISdWXPoZn9oH3/nn+CKK19L4q2POFxPNqqC1xUh0IxYELZphnhg/kF1GOq qF0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681558542; x=1684150542; 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=RDEMhaRULi8GpJ2iB8RVvuAVl16OQWP9p6kFFy/ExIg=; b=MFrU4Dn7vxwGJEa6YvwsY9tWJWsCv+UNBbiR7d++kbVe/GkZ1gGrD2bjoncBjIvGV8 lgqxSDvw1HaOtPZgvsQ6EwW6p5f0YjnM4nioRU26Epx4hWBDqGLur5T5AVdttcO7E3Ta P6IcZBZd/z42Rnj9KL/zG8G0lXm6dNItqE/VfrIc0MqD+7IZT05WDo5bSCZX08fn4MdR C0TC5kaRkkyhqaQJ5rJB3ksfLnhvzkVZAvWT0U64faFXvigPec/wGqKIWr8Pirx9N4q1 BqyBj71KzV2V3RJf5gcOa7i47I8dOri3dq/PZ4CX5pggdJxveJOwmV91zcpGVPV/AwVc Ayvg== X-Gm-Message-State: AAQBX9fEdgZCaGhw+wJ0EwagszqTfBppRUfDqHqzehgboqKLONY+TBrc bvrTtc4vobsn0e0zMefrwIyj+qVyCaZI6JSXMYCIa1g1 X-Google-Smtp-Source: AKy350b4raSULpe7i9z3X9bLUaDKo2mpqQ7tdTssMI62HAIwhrgTO+wrfdVGw73tTr6glX8/OZlBmcW0CrQ5mNPGZhA= X-Received: by 2002:a17:907:11cd:b0:8b1:3298:c587 with SMTP id va13-20020a17090711cd00b008b13298c587mr993772ejb.2.1681558541919; Sat, 15 Apr 2023 04:35:41 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::631; envelope-from=damien.mattei@gmail.com; helo=mail-ej1-x631.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, 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:18961 Archived-At: just understood my error: quote is a macro, so it stop the evaluation of the other macro <- and <- is expanded in the else even if this branch will not be executed and the error arise. On Fri, Apr 14, 2023 at 9:36=E2=80=AFPM Damien Mattei wrote: > i test my previous problem both with Racket and Guile, it gave the same > error , i isolated the problem out of SRFI 105 ,so it is not related to > SRFI 105, here is a simple code to test: > > (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} > > ((or (equal? (quote op) (quote ->)) (equal? (quote op) (quote =E2=86= =92))) > (op term2 (opspecial ident term1))) ;; Warning: argument names of macro d= o > not reprensent the values contained in this case > > ;;(else (! (quote ident) (quote opspecial) (quote term1) (quote op) > (quote term2))))) > (else (! ident opspecial term1 op term2)))))) > > > > > > (define-syntax <- > > (syntax-rules () > > ((_ var expr) > > (begin > ;;(display "<- : variable set!") (newline) > (set! var expr) > var)))) > > (define i 3) > > ($nfx$ i <- i + 1) > <-: bad syntax in: <- > > it works only if i change the last line of $nfx$: > > (else (! ident (quote opspecial) term1 op term2)))))) > > note: ! which is a procedure is not defined in this example > > On Fri, Apr 14, 2023 at 4:49=E2=80=AFPM Damien Mattei > wrote: > >> i have found that the error is related with this : >> >> (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} >> >> ((or (equal? (quote op) (quote ->)) (equal? (quote op) (quote =E2= =86=92))) >> (op term2 (opspecial ident term1))) ;; Warning: argument names of macro = do >> not reprensent the values contained in this case >> >> (else (! ident (quote opspecial) term1 op term2)))) >> >> this code works: >> scheme@(guile-user)> (define i 2) >> scheme@(guile-user)> {i <- i + 1} >> $nfx$ >> 3 >> >> but if i change the last line of the else clause by removing the quote o= f >> opspecial: >> (else (! ident opspecial term1 op term2)))) >> >> it will fail: >> >> scheme@(guile-user)> {i <- i + 1} >> While compiling expression: >> Syntax error: >> unknown location: source expression failed to match any pattern in form = <- >> >> i understand the problem is with opspecial equal in this example to the >> special form <- but what i do not understand is why the code is then go= ing >> to the else clause as i know that previously it was on the same example >> evaluating the first clause: >> (begin >> (display "$nfx$") (newline) >> (opspecial ident (op term1 term2)))) ;; {ident <- term1 op term2} >> >> ??? >> >> On Fri, Apr 14, 2023 at 1:02=E2=80=AFPM 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 o= f >>> 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 >>> >>