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:23:14 +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="26206"; 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:23:44 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 1nFN6N-0006bn-F4 for guile-user@m.gmane-mx.org; Wed, 02 Feb 2022 22:23:43 +0100 Original-Received: from localhost ([::1]:46596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nFN6L-0007be-TZ for guile-user@m.gmane-mx.org; Wed, 02 Feb 2022 16:23:41 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:52686) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFN6A-0007bW-QL for guile-user@gnu.org; Wed, 02 Feb 2022 16:23:30 -0500 Original-Received: from [2607:f8b0:4864:20::b34] (port=37391 helo=mail-yb1-xb34.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nFN66-0008CB-SK for guile-user@gnu.org; Wed, 02 Feb 2022 16:23:30 -0500 Original-Received: by mail-yb1-xb34.google.com with SMTP id k31so2682221ybj.4 for ; Wed, 02 Feb 2022 13:23:26 -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=9sUseXmQJGM08nZa04cq6JyKKmBH7APkFWEplyUx3VQ=; b=o7OAgczlz0wOExiZk/oOw4SoZkf6i2opZ44CZ1j6JO0g9nWRm0cqfFyNJ/1pYmk/Aa Xydnjwe6tKtteO1NPfLAdBjIUhQ7LUU1P7fj3eQtIIybGDH8t+tN2UasYVPKgIa5H6jO oCL//WuGXF/YjfWqL0aUWnbjxvGpUiSA4OP0iBuR7xLWmo0sOqE/Zi2fJ7dDTtKhcM+7 rAAYUKQEblL81VeNMpx9ZWJv86CyioVxbnpBa8TXL/mz4OD0PV26ukV/E9IMFZxP/6ny CnHb9qZwcv2pt5moDZXBbxiGzM4mD23FGQCRB44GGhI10+V2akMiTI3GLcP6jms5yRjz s5+A== 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=9sUseXmQJGM08nZa04cq6JyKKmBH7APkFWEplyUx3VQ=; b=v8v7Tn3r8NOHJK5JiHlcLiA3AtvO6aUZs+2Bx9s+pLouQuEQOGavX95LUzm6ruV9n3 EZmAW3s+nANVB2Igi8W9i18sLQ5wggOkRVFNvkhTjOHCr3tJRX4bkSUCgstGdkXvFl4t yEafJJVTOhks2xMaOe9jgpDdllcgjYF8jjysSPD2aeND2SQIaKL8dTEXs2mN/Y0hIbXN Z19VCP2fvYsBe74ulzo3w2bYpe3b/n7VPdElaQa60V8Ihw72qilV9SBKMniqXkjdkfT5 bf8OjAYLDN0U6ekSWxKGJalWerYeAkWIm0VuZfKnvruMcY2yAsoS0EqU7UKpT8cmSIOW jHCQ== X-Gm-Message-State: AOAM533DUrP+3KUjc/qW5uoXkFTPGm/1THz2SAySJ5JJkv5VK09ifxm3 bO3rT4yKsfdIkFWhTSvOYhntXfRjFtIbLzsp/zArzwyx X-Google-Smtp-Source: ABdhPJx2N0BDHmuanySMnubhP3h7Qs01Ox0Txc8SmMyqwjhtp2VshbW6OQtbSJiiHwmB2X21rY30OWmW/vEl92aiRNE= X-Received: by 2002:a25:7285:: with SMTP id n127mr44220297ybc.430.1643837005599; Wed, 02 Feb 2022 13:23:25 -0800 (PST) In-Reply-To: X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::b34 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::b34; envelope-from=damien.mattei@gmail.com; helo=mail-yb1-xb34.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:17986 Archived-At: really,nothing have an idea? seems $bracket-apply$ is bind to the variable 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!") (newlin= e) > (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 variable > ;; (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:1= 201: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 so > 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 >> >>