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: reserved-keyword in macro Date: Wed, 2 Feb 2022 22:38:31 +0100 Message-ID: References: <6f5e23754b7523f30e31d9006b0a5a1127d503cb.camel@telenet.be> 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="25653"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-user Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Wed Feb 02 22:38:59 2022 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 1nFNL9-0006TS-El for guile-user@m.gmane-mx.org; Wed, 02 Feb 2022 22:38:59 +0100 Original-Received: from localhost ([::1]:55804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nFNL7-0006Ku-WC for guile-user@m.gmane-mx.org; Wed, 02 Feb 2022 16:38:58 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:55580) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFNKw-0006Kc-Ay for guile-user@gnu.org; Wed, 02 Feb 2022 16:38:46 -0500 Original-Received: from [2607:f8b0:4864:20::b29] (port=35374 helo=mail-yb1-xb29.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nFNKt-0002Ou-UD for guile-user@gnu.org; Wed, 02 Feb 2022 16:38:46 -0500 Original-Received: by mail-yb1-xb29.google.com with SMTP id c19so2830299ybf.2 for ; Wed, 02 Feb 2022 13:38:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=Kjo0nyqabB+H428uAA8XbcLp4rsLEdf4xpoA0UPv13E=; b=g45gSKdnqyVJbMxh5Y8vLo9QdZUY2F7xgeG/LddNecEAhAIG/omcRV4ZmotxNmZN64 phtOgtzQ2JjcgPZD6u0hao8hXkH+X8BcvOSzFpqTBCb6VqBuzE8Hez1e+q3Fibmndf1P TkPZAI3ozjS0PMoawMKb89/U+3tFqQL2ys+AWrRDutQJqR8xPbSxBGh0KYXGpQWyl6xK isuZ8TRXIIzyAyCiBeXn+q1/ASyR328RHeqCDg8W7sEO6x46w/3z+3CCMshDlE+MhC/T VEfrtb83SDzmXlGuxEmZSrtWIKyMqvConqXtIfOdUL2YRDXpKOzp4e8WKLJcQE1Vdd0B QKgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=Kjo0nyqabB+H428uAA8XbcLp4rsLEdf4xpoA0UPv13E=; b=whh4SVNKPyhMF2wnNBqt4EZfrllKzgJJmReH8orbEURcASGIPlDZGX1i20inJYw5M2 JKx834ZWMSxbO411509yRkJW8l9M9pqG1JNbCx7aJXAgRUufu7dWEbdV3DxfYZ4M/iZx s2hOrlS/RPb1xxOfb+/sh7Pic1q8eSrvDfNdrnzQjZY07Y8Vz4andq8fJOSfPXwG04f/ auwlWsypj62jil2QtTOwGBbX70AqGJC/u2W1QwduhfhDKfMHJyS1pqbWuWRAXq3snByX iVInm/011LBkaQj0zjtFp5I9krLzgMbhU74HJyyVsRk5uOGJFPbymd6g1C22Vai9F4i6 pqmw== X-Gm-Message-State: AOAM530ANIyC5vjwIKv5mrvNPA6UmRr0pKDnO35k7VpuNVUNFMyd4lm8 6eIFJfZZQcwXVmAguRFwmXFOHY8lqjJ/e2ptT6wnFZunIzM= X-Google-Smtp-Source: ABdhPJzzrmy0GqagggzwxiX00hM3NnMDBM8bTuK/8VUVCQa0mEeo3pvlEQQJPeO+WI1D84G7qQW/xYQ9/T8Qaw2JLRQ= X-Received: by 2002:a25:58c5:: with SMTP id m188mr40917061ybb.81.1643837922629; Wed, 02 Feb 2022 13:38:42 -0800 (PST) In-Reply-To: X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::b29 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::b29; envelope-from=damien.mattei@gmail.com; helo=mail-yb1-xb29.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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" Xref: news.gmane.io gmane.lisp.guile.user:17987 Archived-At: i suppose it has something to see with this: "A literal matches an input expression if the input expression is an identifier with the same name as the literal, and both are unbound13 . " as $bracket-apply$ is already bind to a definition the pattern will not be matched: https://www.gnu.org/software/guile/manual/html_node/Syntax-Rules.html On Wed, Feb 2, 2022 at 10:23 PM Damien Mattei wrote: > really,nothing have an idea? seems $bracket-apply$ is bind to the variabl= e > var of the third case in the macro instead of ignored in the first case..= . > but why? (it the same thing if i change the patterns order) > > On Wed, Feb 2, 2022 at 2:02 PM Damien Mattei > wrote: > >> sorry i miss copy to mailing list... >> >> ---------- Forwarded message --------- >> From: Damien Mattei >> Date: Wed, Feb 2, 2022 at 12:09 PM >> Subject: Re: reserved-keyword in macro >> To: Maxime Devos >> >> >> thanks maxim ,it works so my problem come from elsewhere >> >> scheme@(guile-user)> (define-syntax macro >> (syntax-rules (reserved-keyword) >> ((_ reserved-keyword arg) 'first) >> ... ((_ arg1 arg2) 'second))) >> scheme@(guile-user)> (macro 4 5) >> second >> scheme@(guile-user)> (macro reserved-keyword 5) >> first >> >> this was a simplified example my real case is this: >> (define-syntax <- >> >> (syntax-rules ($bracket-apply$) >> >> ;; special form like : (<- ($bracket-apply$ T 3) ($bracket-apply$ T >> 4)) >> >> ;; one dimension array, example: {a[4] <- 7} >> ;; $bracket-apply$ of SRFI 105 >> ((_ ($bracket-apply$ container index) expr) >> (let ((value expr)) ;; to avoid compute it twice >> >> ;; (if (equal? (quote $bracket-apply$) (quote funct-or-macro)) ;; >> test funct-or-macro equal $bracket-apply$ >> >> ;; normal case >> ;; {T[2] <- 4} >> ;; {T[3] <- T[2]} >> ;;(begin >> ;;(display "<- : vector or array set! or hash-table set!") >> (newline) >> (cond ((vector? container) (vector-set! container index value)) >> ((hash-table? container) (hash-table-set! container index value)) >> (else (array-set! container index value)));) >> >> ;; rare case (to prevent any error) >> ;; (let ((var (funct-or-macro container index))) ;; MUST be in a >> variable , otherwise: >> ;; While compiling expression: >> ;; Syntax error: >> ;; unknown location: quote: bad syntax in form quote >> ;; <- : variable set! after creation >> ;; (set! var value))) >> >> value)) >> >> >> ;; multi dimensions array : {a[2 4] <- 7} >> ;; $bracket-apply$ of SRFI 105 >> ((_ ($bracket-apply$ array index1 index2 ...) expr) >> (let ((value expr)) ;; to avoid compute it twice >> >> ;; (if (equal? (quote $bracket-apply$) (quote funct-or-macro)) ;; >> test funct-or-macro equal $bracket-apply$ >> ;; normal case >> ;;(begin >> ;;(display "<- : multidimensional vector or array set!") (newline= ) >> (if (vector? array) >> (array-n-dim-set! array value index1 index2 ...) >> (array-set! array index1 index2 ... value));) >> >> ;; rare case (to prevent any error) >> ;; (let ((var (funct-or-macro array index ...))) ;; MUST be in a variabl= e >> ;; (display "<- : variable set! after creation (multidimensional)") >> (newline) >> ;; (set! var value))) >> value)) >> >> ;; not sure this case will be usefull >> ;; (define (foo) (values 1 2 3)) >> ;; (call-with-values foo list) >> ;;'(1 2 3) >> ;; (define (foo) (display "inside foo") (newline) (values 1 2 3)) >> ;; > (declare x y z) >> ;; > (<- (x y z) (foo)) >> ;; ((_ (funct-or-macro arg ...) expr) >> ;; (let ((var (funct-or-macro arg ...)) >> ;; (value expr)) ;; to avoid compute it twice >> ;; (set! var value) >> ;; var)) >> >> ((_ (var ...) expr) >> (begin >> (display expr) (newline) >> (let ((expr-list (call-with-values (lambda () expr) list))) >> >> (assign-var (var ...) expr-list) >> expr-list))) >> >> >> ;;(<- x 5) >> ((_ var expr) >> >> (begin >> ;;(display "<- : variable set!") (newline) >> (set! var expr) >> var)) >> >> >> ;; (declare x y z t) >> ;; {x <- y <- z <- t <- 7} >> ;; 7 >> ;; (list x y z t) >> ;; (7 7 7 7) >> >> ;; (declare I) >> ;; {I <- (make-array 0 4 4)} >> ;; #2((0 0 0 0) >> ;; (0 0 0 0) >> ;; (0 0 0 0) >> ;; (0 0 0 0)) >> ;; >> ;; {I[0 0] <- I[1 1] <- I[2 2] <- I[3 3] <- 1} >> ;; 1 >> ;; >> ;; I >> ;; #2((1 0 0 0) >> ;; (0 1 0 0) >> ;; (0 0 1 0) >> ;; (0 0 0 1)) >> >> ((_ var var1 var2 ...) ;; there is an expression in the last part of >> ellipsis! >> (<- var (<- var1 var2 ...))) >> >> )) >> >> >> ;; > (declare x y z) >> ;; > (assign-var (x y z) (1 2 3)) >> ;; > x >> ;; 1 >> ;; > y >> ;; 2 >> ;; > z >> ;; 3 >> (define-syntax assign-var >> (syntax-rules () >> >> ((_ (var ...) (exp ...)) (begin (set! var exp) ...)))) >> >> i'm cross developping in Guile and Racket and i'm sure Guile will do as >> Racket and here is the result: >> >> Bienvenue dans DrRacket, version 7.7 [3m]. >> Langage: reader "../SRFI/SRFI-105.rkt", avec d=C3=A9bogage; limite m=C3= =A9moire : >> 128 MB. >> > (declare x y z) >> > (define (foo) (display "inside foo") (newline) (values 1 2 3)) >> > (<- (x y z) (foo)) >> inside foo >> . . >> ../../../../../../../../usr/share/racket/collects/racket/private/kw.rkt:= 1201:25: >> result arity mismatch; >> expected number of values not received >> expected: 1 >> received: 3 >> values...: >> > (define T (make-vector 5)) >> > {T[2] <- 1} >> 1 >> . ../required-files/assignment.rkt:140:7: assign-var: bad syntax in: >> (assign-var ($bracket-apply$ T 2) expr-list) >> > (<- T[2] 1) >> . ../required-files/assignment.rkt:140:7: assign-var: bad syntax in: >> (assign-var (2) expr-list) >> > (<- ($bracket-apply$ T 2) 1) >> 1 >> . ../required-files/assignment.rkt:140:7: assign-var: bad syntax in: >> (assign-var ($bracket-apply$ T 2) expr-list) >> > >> >> the problem is that anyway i do it when using reserved keyword in >> define-syntax the macro use the third case: >> (_ (var ...) expr) >> even when i have : >> >> (syntax-rules ($bracket-apply$) >> >> ;; special form like : (<- ($bracket-apply$ T 3) ($bracket-apply$ T >> 4)) >> >> ;; one dimension array, example: {a[4] <- 7} >> ;; $bracket-apply$ of SRFI 105 >> ((_ ($bracket-apply$ container index) expr) >> >> >> with (<- ($bracket-apply$ T 2) 1) entered at toplevel i should not be in >> the third case but the first of the macro <- >> >> that is strange... i think i could not get help from mailing list on a s= o >> complex example that rely on my Scheme+ development for multiple values >> return (aka let-values replacment with <- ), >> sorry for the inconvenience >> Damien >> >> >> On Wed, Feb 2, 2022 at 11:33 AM Maxime Devos >> wrote: >> >>> Damien Mattei schreef op wo 02-02-2022 om 11:13 [+0100]: >>> > (define-syntax macro >>> > (syntax-rules () >>> > ((_ arg1 arg2) code1) >>> > ((_ reserved-keyword arg) code2))) >>> >>> The rules are matched in-order, so when the first rule matches, the >>> second rule is ignored. I suggest: >>> >>> (define-syntax macro >>> (syntax-rules (reserved-keyword) >>> ((_ reserved-keyword arg) code2) >>> ((_ arg1 arg2) code1))) >>> >>> Greetings, >>> Maxime >>> >>>