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: Fwd: reserved-keyword in macro Date: Wed, 2 Feb 2022 14:02:52 +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="34844"; 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 14:22:23 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 1nFFaY-0008oi-TT for guile-user@m.gmane-mx.org; Wed, 02 Feb 2022 14:22:23 +0100 Original-Received: from localhost ([::1]:33992 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nFFaV-0005jd-Dp for guile-user@m.gmane-mx.org; Wed, 02 Feb 2022 08:22:19 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:59710) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nFFI4-0007ER-5x for guile-user@gnu.org; Wed, 02 Feb 2022 08:03:20 -0500 Original-Received: from [2607:f8b0:4864:20::b34] (port=45692 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 1nFFI0-0006mm-6c for guile-user@gnu.org; Wed, 02 Feb 2022 08:03:15 -0500 Original-Received: by mail-yb1-xb34.google.com with SMTP id w81so38479875ybg.12 for ; Wed, 02 Feb 2022 05:03:04 -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=GjvHTwlSFjr6sb8AjYzGuQNSjjtJb7ur67Ow3gIR+fg=; b=YDRmbT2FahpSffYm9Db7Gh5T6vMQM5dBNtJA7vBe5JP1T0Y+BwdMttHDNxZTexD5Bk NmIx5RoF7hcRZm1vCnuD230FdJnK6VutBJf8CyVFakXxgOACSFSQfGxqHnCed8XSPGed COQtDpziiivM3khc3w9eUdAae01jmp7nGqj1gnfZ1vu1nuocO6wHlGhdBj6jDRm++Zaj BdlXZg5NE86/pQCPvv0I0G59ZJwEq+arB6KuUwwnUQFxlbm+JXggjHmmgWqPVPNCwRbw CQ0yeyO9HnP4IbTRIrDMsQJZDITfhoptiEF4fqn3syy47EG//Nus/8GvRjOdLVqcXPI0 iWog== 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=GjvHTwlSFjr6sb8AjYzGuQNSjjtJb7ur67Ow3gIR+fg=; b=HE0RtQvrSxVuBiRrAJcB5zKaEuj8ebTPW2jAnznnMy8BaCIAYhXm7LvvXyKz0GqqCZ 42m99EYJrlYZq45wQ3ykxtULNGLE25g+udhNT6RwRjIM19JGKwKriUw3skmNRki0Vzac TEvfpeSLMLtys/4NpXI4jO7dbdbMG/dMg3MLVSfGuLTTUGYKIiJHa3TdU/5upj62D27C NisYHd2tHPH0DJSfSgAlR12twh2kA+CW1oueZJA2mCs21rZk+Zqy0dSRRPG0uyCUoeNR MYgoKs1yQYTl5u1M30NN+izTo8WumALVDNI/R/KefsmeTxCjuxEeUwgyjUfjBjT2URFm OKEg== X-Gm-Message-State: AOAM530JSJqto6SdJBTl1ZjdKt/EUZ2AIyQ+7zYrrkB+m2Kr4+Mn7beq NlQ4QolgZN6FshNu/PLIkEVMOUP7GUO4Hx/jxz9R9R/D X-Google-Smtp-Source: ABdhPJxzUvmMS9IHmvCdMa4tIn+SLfcW65onRmv+r7gXBKaIVB8WUZpEXGqRUXfGx7/Fvq1Ajmn0DDfyuzrbIMCfsmk= X-Received: by 2002:a25:d106:: with SMTP id i6mr40544182ybg.125.1643806983270; Wed, 02 Feb 2022 05:03:03 -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:17985 Archived-At: 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 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=A9m= oire : 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:120= 1: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 > >