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: Thu, 3 Feb 2022 11:09:58 +0100 Message-ID: References: <6f5e23754b7523f30e31d9006b0a5a1127d503cb.camel@telenet.be> <87bkzou5yi.fsf@vijaymarupudi.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15493"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user To: Vijay Marupudi Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Thu Feb 03 11:11:41 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 1nFZ5Y-0003tj-LB for guile-user@m.gmane-mx.org; Thu, 03 Feb 2022 11:11:40 +0100 Original-Received: from localhost ([::1]:47518 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nFZ5W-0006hP-2Y for guile-user@m.gmane-mx.org; Thu, 03 Feb 2022 05:11:39 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:52260) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFZ4A-0005t8-DV for guile-user@gnu.org; Thu, 03 Feb 2022 05:10:14 -0500 Original-Received: from [2607:f8b0:4864:20::b29] (port=40685 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 1nFZ47-0003Y6-JL for guile-user@gnu.org; Thu, 03 Feb 2022 05:10:14 -0500 Original-Received: by mail-yb1-xb29.google.com with SMTP id 23so7281601ybf.7 for ; Thu, 03 Feb 2022 02:10:11 -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 :cc; bh=FMmAM0P+WrKacMwn52wORs2OXaf+tUlTQbkEdYIsmXc=; b=limYOKsqeEZGm6E5VjnzTYnaOwn4ukrUJW6lUdKkLV+J6gAsZKLd9+cvzWmQxPqyWE M+JtOwD760dSV4Bbhcwqoi+aR/RUg7Zt77bdkEksEmmokZrwIFQRjmwTcoljs4/B8Dns NSjDfQ+HhQ1WA7V1VqLD8sMT2yvO8l2BvjVqttiGikRPIx+wqwN2ducDV+mcqXxKZber ueK87pi47W7/uvbsNonpOxe6lZFJnauN07QsMfp7M7OY6ZxbjnHKdkF3NZVfR7fjUvEq NDykepnX4MLmflsbuOnWbKKaw958JpRJOSOikk+unS7w5E4tSgfCVBQRWB2TAI7/Qrw3 DpUQ== 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:cc; bh=FMmAM0P+WrKacMwn52wORs2OXaf+tUlTQbkEdYIsmXc=; b=T92c/ZEY34QC5i24s4ZK3fx0CTg50Rczt2IhlJofOlGJ3vRlSKiJ6/m2kCpzDOe8SO E02Jj9UHjeGP5HWvVtdDlISaBaRjVbr7PuB7GzwwMO91obKaBUqnF0ONFUqyW95FCPis h8i15eF1fgX1cgTQWqUut+Rf6nDQufvyQy3Uhb6amNk+resP/Rmq9QetbNIHulwenZpP VOma+G3wS+EFU+1tm3XHs+1e3p+3l83IM94f0upV9H1uLVj0FfmJ3vm2fWMqZzr1Beqm d+GsVujJo2F/QWTLUKhwdmaNFWUwVCsS11Pzf2ykGGEFwAjOEkD8PZ4kHPdeUytz6lEZ FB3A== X-Gm-Message-State: AOAM532WJ64uGxp0stw+PyxPTDO1ASJ7yXOy/DlcNpiAMRFyEs8jEcuY kphp6hXxp8Mt5CaZem3yAlUazgINHQRI6x880+0ykDd/rq8= X-Google-Smtp-Source: ABdhPJyRDeju+xQbIdsitOjf6o7YaDwCUmL6zr0dKv66FYNIoyvJf7kUYqb75ux/GmfmQXl5ZwK0K2U05gzTo1h7Q10= X-Received: by 2002:a25:7285:: with SMTP id n127mr45922943ybc.430.1643883009966; Thu, 03 Feb 2022 02:10:09 -0800 (PST) In-Reply-To: <87bkzou5yi.fsf@vijaymarupudi.com> 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:17990 Archived-At: oh :-O yes it is the behavior expected : assign the 2nd element of an array T with value 1 : prefix notation of : (<- ($bracket-apply$ T 2) 1) is equivalent in Curly Infix syntax to : {T[2] <- 1} as expected when $bracket-apply$ is not bound we have the good result. Thanks for this result. Of course in this case {T[2] <- 1} it is not a problem to have not $bracket-apply$ bound, things became harder when doing : {T[2] <- T[4]} for example because then i want to assign the result value of T[4] to T[2] and so i need to evaluate T[4] before which is exactly ($bracket-apply$ T 4) and at this point $bracket-apply$ is bind to: (define-syntax $bracket-apply$ (syntax-rules () ((_ container index) ;(begin ;;(display "$bracket-apply$") (newline) (cond ((vector? container) (vector-ref container index)) ((hash-table? container) (hash-table-ref container index)) (else (array-ref container index))));) ((_ array index1 index2 ...) ;(begin ;;(display "$bracket-apply$") (newline) (if (vector? array) (array-n-dim-ref array index1 index2 ...) (array-ref array index1 index2 ...)))));) and is used in the RHS (right-hand side) of: {T[2] <- T[4]} which expand in Curly Infix SRFI-105 to: (<- ($bracket-apply$ T 2) ($bracket-apply$ T 4)) and then is expanded in Scheme+ in two phases: first the RHS expr is evaluate in : ((_ ($bracket-apply$ container index) expr) (let ((value expr)) ;; to avoid compute it twice in : (array-ref T 4) but the LHS (Left hand side) is not evaluated with $bracket-apply$ but with the macro <- in the body of let : (cond ((vector? container) (vector-set! container index value)) which give : (vector-set! T 2 value) where value is the value of expr, previously expanded and evaluated. And we get the good result. But for this we need to have sometimes $bracket-apply$ as a bound macro (or procedure) and sometimes not, being a reserved keyword NOT bound. This for me obscure WHY the keyword in syntax-rules MUST not be bound to behave correctly but this is like that in Scheme standarts and we have to deal with. I already faced this problem earlier and the solution is in the previously commented code: ;; (if (equal? (quote $bracket-apply$) (quote funct-or-macro)) ;; test funct-or-macro equal $bracket-apply$ which can only be understood knowing that the macro was in the past declared like this and commented code does not match present code,here is the previous definition of <- : (syntax-rules () ;; special form like : (<- ($bracket-apply$ T 3) ($bracket-apply$ T 4)) ;; one dimension array, example: {a[4] <- 7} ;; $bracket-apply$ of SRFI 105 ((_ (funct-or-macro 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]} (cond ((vector? container) (vector-set! container index value)) ((hash-table? container) (hash-table-set! container index value)) (else (array-set! container index value))) value)) so the solution will be to remove $bracket-apply$ as literal in: (define-syntax <- (syntax-rules ($bracket-apply$) and some check manually in the macro with: (if (equal? (quote $bracket-apply$) (quote funct-or-macro)) ;; test funct-or-macro equal $bracket-apply$ to branch instead of using pattern matching. i will code this later but this was of great help,thanks again all. Damien On Thu, Feb 3, 2022 at 1:52 AM Vijay Marupudi wrote: > Hi Damien, > > I tried to run the code you provided. I ran > > ----------------------------------------------------------------- > > (define-syntax <- > (syntax-rules ($bracket-apply$) > ((_ ($bracket-apply$ container index) expr) > (let ((value expr)) ;; to avoid compute it twice > (cond ((vector? container) (vector-set! container index value)) > ((hash-table? container) (hash-table-set! container index > value)) > (else (array-set! container index value)));) > value)) > ((_ ($bracket-apply$ array index1 index2 ...) expr) > (let ((value expr)) > (if (vector? array) > (array-n-dim-set! array value index1 index2 ...) > (array-set! array index1 index2 ... value));) > (newline) > value)) > ((_ (var ...) expr) > (begin > (display expr) (newline) > (let ((expr-list (call-with-values (lambda () expr) list))) > (assign-var (var ...) expr-list) > expr-list))) > ((_ var expr) > (begin > (set! var expr) > var)) > ((_ var var1 var2 ...) > (<- var (<- var1 var2 ...))))) > > (define T (make-vector 5)) > (<- ($bracket-apply$ T 2) 1) > > ----------------------------------------------------------------- > > After I ran that, T was > > #(# # 1 # #) > > Is that was you are looking for? > > > "A literal matches an input expression if the input expression is an > > identifier with the same name as the literal, and both are unbound13 > > < > https://www.gnu.org/software/guile/manual/html_node/Syntax-Rules.html#FOOT13 > >. > > " as $bracket-apply$ is already bind to a definition the pattern will > > not be matched: > > It's possible, as in my case, I did not have it bound, and it seems to > have worked the way you expected? > > ~ Vijay >