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: with-syntax return error in Guile, not in Kawa or Racket Date: Fri, 10 May 2024 23:57:32 +0200 Message-ID: References: <4A2B38C7-AB6F-4EC5-939C-4F2DE1DEC050@abou-samra.fr> <1462d1698cf779cc58ce9e2d5841acc7cfd24b08.camel@abou-samra.fr> 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="34837"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Maxime Devos , guile-user To: Jean Abou Samra Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Fri May 10 23:58:16 2024 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 1s5YFs-0008qz-B7 for guile-user@m.gmane-mx.org; Fri, 10 May 2024 23:58:16 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s5YFR-0005yi-1s; Fri, 10 May 2024 17:57:49 -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 1s5YFQ-0005ya-5C for guile-user@gnu.org; Fri, 10 May 2024 17:57:48 -0400 Original-Received: from mail-oi1-x232.google.com ([2607:f8b0:4864:20::232]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s5YFN-0008V4-Uj for guile-user@gnu.org; Fri, 10 May 2024 17:57:47 -0400 Original-Received: by mail-oi1-x232.google.com with SMTP id 5614622812f47-3c74b27179dso1724900b6e.1 for ; Fri, 10 May 2024 14:57:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715378264; x=1715983064; darn=gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=pDmT0DS19AIDHqKRIL9onnyZfDlD5L27AkRg3nx6yDk=; b=IT2MwjPbE7f24TmOn/B/nzVnrGGI0DYFrgrkzb1lfKp5D4ZGW52/pD7qe5mZ6hAvln 0xYpOgb7x3X7eIRmyCwgZiCtbG2Tpe7tPDM4QbNQVltFdojf/+rMjcxsWZGz/kJZzi8y HCY7VVWO1a6KpF9VRKN1GaALQYvt9JwbbFCxGlf8SGxSo5cxK+48fcJxedvWzSCdnBgo leb6FSDXBhmMy2jtrBIBgBjQ4CAv9RQWAXkGJb19bg6am+VeKisqtooNHxndJC77Y03H hBWrmO8jWhJNOpU69r6flAuCtJ3fCCh7MUDJJkmf5X7d0c1hT+Z5E9DhqwJpVlTYu6oy /nmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715378264; x=1715983064; h=cc: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=pDmT0DS19AIDHqKRIL9onnyZfDlD5L27AkRg3nx6yDk=; b=pxaTbsOF4deS1QnDa8za6EPz6urw+AWAPVgGfFw2Dr05bHauysm87JZGUz6SAJmAcj bX4en2eUBXU5iAY7+nfhXX306+YJLuL+GtfPEoY7IElknaTIzs/SzbVHWlPmGpXyxE0m 9NrSIbzedgIt4OA+JKhyQRtGuEbNFK8pw8F8S/aBuFRE67zo9gM2IPr8o5TtpUGl1frx FDpNX+i6aag6Od6zNMJrTDRXTDudRUTfy2jdAbgdvdKjpnPvnuh8kdC1ubyxXaUNCjUW IqLuN/vzo0BV9KZPPxT1roN0wM9vCP2nlIWe1WKfD3rLBRSIhSxoT78qnEz4xm91jYeD YH3g== X-Forwarded-Encrypted: i=1; AJvYcCUG4CXUmGbhz5wEtc10FWYq3S2sCYFu9W9BROBmOrxc9BkQRkc4v9p/GUbNNBtQ1b9QzrsllVwwkMaEVNgSHUQ73AM= X-Gm-Message-State: AOJu0YyU00YooeZAUl9Huqk//3YngjQ8ONKZIgD+UAzv32WaLsQdctYL MfFOZfMjMetHaaIcAT3IJ1oOvHIh+DpuJ6lQK7ulYabI13nWr6qtYPWhc4xuG6rKDXENAdxJOAJ WNJa1SPZEPZzZYZs0oNfcPE4WtRk= X-Google-Smtp-Source: AGHT+IGPSYmpcQ25r/YOvtaRYHUhjSe1Mj6BMkCd+enK11WvVjCG747kv04yEt5TDYfSGcGHbRtdLguJCHjrSo3b/Tg= X-Received: by 2002:a54:4791:0:b0:3c9:606f:669 with SMTP id 5614622812f47-3c99702ca2bmr3943360b6e.1.1715378264486; Fri, 10 May 2024 14:57:44 -0700 (PDT) In-Reply-To: <1462d1698cf779cc58ce9e2d5841acc7cfd24b08.camel@abou-samra.fr> Received-SPF: pass client-ip=2607:f8b0:4864:20::232; envelope-from=damien.mattei@gmail.com; helo=mail-oi1-x232.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, LOTS_OF_MONEY=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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:19624 Archived-At: On Fri, May 10, 2024 at 5:24=E2=80=AFPM Jean Abou Samra wrote: > > the built-in let macro creates a kind of "access token" for the variable > lin, and marks the body (display (mac lin)) with that token so that it > has the variable lin in scope. This is so that forms introduced by macros > (like mac here) which happen to also use the name lin will not interfere. > Now, when you do the syntax->datum, you strip away all that information, > and with (datum->syntax #f =E2=80=A6), you convert the symbols back to sy= ntax, > but with zero scope information (as documented in the Guile manual). > That means they can only refer to top-level variables. So the lookup > of the local variable lin fails, but it works if lin is a global variable > (because global variables are dynamic in Scheme, cf. module-set! and all > that, unlike local variables which are static). > > > > in Guile the 2 examples works: > > > > scheme@(guile-user)> (define-syntax mac > > (lambda (sintax) > > (syntax-case sintax () > > ((mac arg) > > (datum->syntax #f (syntax->datum #'arg)))))) > > scheme@(guile-user)> (define lin 6) > > scheme@(guile-user)> (display (mac lin)) > > 6scheme@(guile-user)> (let ((lin 5)) > > (display (mac lin))) > > 6scheme@(guile-user)> > > > Well, here, the second example runs but display 6, not 5, i.e. it looks > up the global variable defined earlier, not the local one. > > > yes with a global variables the things are different , my macro too find the global variable here is the simplest counter example i can create,not in a program just at REPL with this version of Scheme+: i will use 2 simple example: (let ((lin 2)) {T[lin 1] <- -5}) and (let ((lin 2)) {T[lin 1] =E2=86=90 -5}) the first works ,not the second GNU Guile 3.0.8.99-f3ea8 scheme@(guile-user)>(use-modules (Scheme+)) scheme@(guile-user)> (use-modules (array)) scheme@(guile-user)> (define T (make-array-2d 5 3 0)) scheme@(guile-user)> T $1 =3D #(#(0 0 0) #(0 0 0) #(0 0 0) #(0 0 0) #(0 0 0)) scheme@(guile-user)> (let ((lin 2)) {T[lin 1] <- -5}) <- : #'(index ...) =3D (# #) <- : (syntax->datum #'(index ...)) =3D (lin 1) <- : #'parsed-args=3D# lin 1)> <- : (syntax->datum #'parsed-args)=3D(list lin 1) scheme@(guile-user)> T $1 =3D #(#(0 0 0) #(0 0 0) #(0 -5 0) #(0 0 0) #(0 0 0)) scheme@(guile-user)> (define T (make-array-2d 5 3 0)) scheme@(guile-user)> T $2 =3D #(#(0 0 0) #(0 0 0) #(0 0 0) #(0 0 0) #(0 0 0)) scheme@(guile-user)> (let ((lin 2)) {T[lin 1] =E2=86=90 -5}) <- : #'(index ...) =3D (# #) <- : (syntax->datum #'(index ...)) =3D (lin 1) <- : #'parsed-args=3D# lin 1)> <- : (syntax->datum #'parsed-args)=3D(list lin 1) ;;; :10:15: warning: possibly unbound variable `lin' ice-9/boot-9.scm:1685:16: In procedure raise-exception: Unbound variable: lin Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. scheme@(guile-user) [1]> ,bt In current input: 10:15 1 (_) In ice-9/boot-9.scm: 1685:16 0 (raise-exception _ #:continuable? _) here is a longer example, more near the logiki code and things are worst: (define (foo) {T =E2=86=90 (make-array-2d 5 3 0)} (for-basic (lin 0 4) (display lin) (newline) {T[lin 1] =E2=86=90 -5}) T) foo should create T a 2D array : #(#(0 0 0) #(0 0 0) #(0 0 0) #(0 0 0) #(0 0 0)) the for loop from 0 to 4 display lin ,set T[lin 1] to -5 and return T but it fails and the compiler warn me about lin undefined (if i define lin at top level it compile but the code will not use lin of the loop but of top level and it acts as if there is 2 lin variables! the one of toplevel that is used in {T[lin 1] =E2=86=90 -5} and the one of the loop for-basic that i= s used in (display lin) (newline) ! : scheme@(guile-user)> (define lin 1) scheme@(guile-user)> (define (foo) {T =E2=86=90 (make-array-2d 5 3 0)} (for-basic (lin 0 4) (display lin) (newline) {T[lin 1] =E2=86=90 -5}) T) <- : #'(index ...) =3D (# #) <- : (syntax->datum #'(index ...)) =3D (lin 1) <- : #'parsed-args=3D# lin 1)> <- : (syntax->datum #'parsed-args)=3D(list lin 1) scheme@(guile-user)> (foo) 0 1 2 3 4 $11 =3D #(#(0 0 0) #(0 -5 0) #(0 0 0) #(0 0 0) #(0 0 0)) notice only one element of array as been modified if i use <- directly it works: scheme@(guile-user)> (define (bar) {T <- (make-array-2d 5 3 0)} (for-basic (lin 0 4) (display lin)(newline) {T[lin 1] <- -5}) T) <- : #'(index ...) =3D (# #) <- : (syntax->datum #'(index ...)) =3D (lin 1) <- : #'parsed-args=3D# lin 1)> <- : (syntax->datum #'parsed-args)=3D(list lin 1) scheme@ of course all this is made by the datum->syntax in this part of the macro: ;; parse arguments at posteriori here: (with-syntax ((parsed-args (datum->syntax stx ; #f (cons #'list (optimizer-parse-square-brackets-arguments-lister (syntax->datum #'(index ...))))))) to run those example i did not even need to comment/uncomment code or recompile logiki, i just used the toplevel with scheme+ but in this version i use the cloning with: (define-syntax =E2=86=90 (syntax-rules () ((=E2=86=90 . args) (<- . args)))) it is clear that calling <- via =E2=86=90 give a bad result, if instead i u= se directly <- code works.