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 15:52:46 +0200 Message-ID: References: <4A2B38C7-AB6F-4EC5-939C-4F2DE1DEC050@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="40559"; 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 15:53:43 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 1s5Qgw-000AHh-DN for guile-user@m.gmane-mx.org; Fri, 10 May 2024 15:53:42 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s5QgK-00044W-OZ; Fri, 10 May 2024 09:53:04 -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 1s5QgJ-00044D-A2 for guile-user@gnu.org; Fri, 10 May 2024 09:53:03 -0400 Original-Received: from mail-qk1-x72a.google.com ([2607:f8b0:4864:20::72a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s5QgG-0003S1-4o for guile-user@gnu.org; Fri, 10 May 2024 09:53:03 -0400 Original-Received: by mail-qk1-x72a.google.com with SMTP id af79cd13be357-792b8c9046bso158913385a.3 for ; Fri, 10 May 2024 06:52:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715349179; x=1715953979; 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=N3+vTE8lqMS42R1GQVZqdamfUxaJhmc5ZzFADWYTk+w=; b=H9/L0pDRL4vufgeJtzm5B9gzVSzMzk7fpuQQCF0OKbij5rfQ8yYOGlJRt3cBRDIotr sHd4cTUOtAvrZfxHBqJNasyO03eLdipCoIPASlkoiLLpV5Xi4XAgd1H+pEdlPOGZCiFj 3IZwNA0qrPBDTSIRG/OmOxIrlcTqGBj9w2h8AznfJnhdnpoOj0plYYQd7a/ufpDFKE4n fekTwWqjnmG9m/31DqVVgNKkUqoS37k34j+QsWTX5ilm4TpYjwew0X2Qt75WknSM1wO5 JI5Ae1LcrZ3W0i9ysOc2kdn2B1xX78MNtg5OLLX37qILgUdjL796xxJsQerpi03OpeHr HqyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715349179; x=1715953979; 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=N3+vTE8lqMS42R1GQVZqdamfUxaJhmc5ZzFADWYTk+w=; b=BEPrC6JEq7KgJcYRC/5HM3P/fUwLazYPxMkBPy56/fNFYHdgyx1a6LaPh4ZLd2/91T T4ftf36m4nHJf51kk7fjCLW5XITxNXBkf+qN6nB3ldaqcMYcoXaZ8ZsNMG6FNjr4DOuA Yz4Bg/30TeL/AEKOysdYlMr1logD8aoa5l1L6gXkIMcK9bEQJTZr/cl0fRPTGn/yF1Hs x4g59e7K3HSAJAgIZOeW4JJsAiZsMT4dDWj4zaSeSlZIozdMl/AfC0ETjD62tJvOEaRZ YKTPVwLoXux1lfFlcA9VxhTgX3jGBNZSqmwHzlX4LPggsV3OUMwp+CQLZT5ENk5z/K65 VQBQ== X-Forwarded-Encrypted: i=1; AJvYcCVXYq/yEwpYWpLIjUNXd72voqimn8kkbznl7hgzN9ZA/6KBFrWOupJiuqI4LOzyNBnis5OVOh0FA8+R4AdbqtNIm5w= X-Gm-Message-State: AOJu0YwFqlTAK7/jbeUoKKKmAZsGzR8PmlVNcFHwLsgBE0vnCpATT/qc spNPhvuwP0q23FOioM0WTiHXNui971lk41esTFpdN6TYVI+XzkytLkKIzO3qeM8KIUcAtx6ImY3 IN+VEtlZDXo9lgR++DZ0MtLr7Zpc7n44JT1c= X-Google-Smtp-Source: AGHT+IGEJqBdaXP7IlDomANQPdQYKr85roSvDUsy7Ld2pIET1EGDZ3DYqgZ6ctA4L0T5silav0mKLhJU6myMVltiKMA= X-Received: by 2002:a05:6214:3d9d:b0:6a0:b3db:c6d1 with SMTP id 6a1803df08f44-6a168160db6mr32598446d6.22.1715349178762; Fri, 10 May 2024 06:52:58 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::72a; envelope-from=damien.mattei@gmail.com; helo=mail-qk1-x72a.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, 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:19619 Archived-At: i re-test all, and your are right this working: (define-syntax foo (syntax-rules () ((foo . args) (display 'args)))) (define-syntax bar (syntax-rules () ((bar . args) (foo . args)))) (foo 1 2 3) (1 2 3) (bar 1 2 3) (1 2 3) (foo 1) (1) (bar 1) (1) (define-syntax my-macro (syntax-rules () ((my-macro arg ...) (begin (display arg) ...)))) (define-syntax bar-my-macro (syntax-rules () ((bar-my-macro . args) (my-macro . args)))) still working: (my-macro 1 2 3) 123 (bar-my-macro 1 2 3) 123 but there should be something different with my macro and code because if i put: (define-syntax =E2=86=90 (syntax-rules () ((=E2=86=90 . args) (<- . args)))) in my code i get again the warnings at compilation: ;;; /Users/mattei/library-FunctProg/guile/logiki+.scm:2526:19: warning: possibly unbound variable `lin' ;;; /Users/mattei/library-FunctProg/guile/logiki+.scm:2546:18: warning: possibly unbound variable `col' ;;; /Users/mattei/library-FunctProg/guile/logiki+.scm:2554:13: warning: possibly unbound variable `lin-pos-epi' and the error at runtime: scheme@(guile-user)> (logic-test) test 1 (or (and (not a) (not b) (not c) (not d)) (and (not a) (not b) (not c) d) (and (not a) (not b) c (not d)) (and (not a) b (not c) d) (and (not a) b c (not d)) (and (not a) b c d) (and a (not b) (not c) (not d)) (and a (not b) (not c) d) (and a (not b) c (not d)) (and c (not d))) =3D 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]> so strictly talking it is not the same thing as calling =E2=86=90 defined l= ike this: (define-syntax =E2=86=90 (syntax-rules () ((=E2=86=90 . args) (<- . args)))) and not the same as calling =E2=86=90 defined like this: (define-syntax =E2=86=90 (lambda (stx) (syntax-case stx () ;; silly case ((_ ( ) expr) #'(void)) ;; void is not portable ;'()) ;; one value in values ! ;; > {(x) =E2=86=90 (values 7)} ;; > x ;; 7 ((_ (var) expr) #'(set!-values-plus (var) expr)) ;; example: {a[4] =E2=86=90 7} ;; $bracket-apply$ is from SRFI 105 bracket-apply is an argument of the macro ((_ (brket-applynext container index ...) expr) ; possible to have NO index : ; minimal form is (_ (brket-applynext container) expr) ;; We will let the second $bracket-apply$ be executed and forbid the execution of first $bracket-apply$. (cond ((equal? (quote $bracket-apply$next) (syntax->datum #'brket-applynext)) ;; already parsed and optimised by parser #'(assignmentnext container expr index ...)) ; possible to have NO index ;; integrated curly-infix of guile (no parsing) at REPL ((equal? (quote $bracket-apply$) (syntax->datum #'brket-applynext)) (display "=E2=86=90 : #'(index ...) =3D ") (display #'(index ...)) (ne= wline) (display "=E2=86=90 : (syntax->datum #'(index ...)) =3D ") (display (syntax->datum #'(index ...))) (newline) ;;(display "=E2=86=90 : (number? (car (syntax->datum #'(index ...)))) = =3D ") (display (number? (car (syntax->datum #'(index ...))))) (newline) ;; parse arguments at posteriori here: (with-syntax ((parsed-args (datum->syntax stx ; #f (cons #'list (optimizer-parse-square-brackets-arguments-lister (syntax->datum #'(index ...))))))) ;; (with-syntax ((parsed-args ;; (cons #'list ;; otherwise:Wrong type to apply: 0 ,list will be interpreted as code ! ;; (optimizer-parse-square-brackets-arguments-lister #'(index ...))))) (display "=E2=86=90 : #'parsed-args=3D") (display #'parsed-args) (newline= ) (display "=E2=86=90 : (syntax->datum #'parsed-args)=3D") (display (synta= x->datum #'parsed-args)) (newline) (case (length (cdr (syntax->datum #'parsed-args))) ;;(case (length (cdr #'parsed-args)) ;;(case (length #'parsed-args) ;; 0 argument in [] ;; T[] ;; {v[] =E2=86=90 #(1 2 3)} ;; > v ;;'#(1 2 3) ((0) #'(assignment-argument-0 container expr)) ; possible to have NO index ;; 1 argument in [ ] ;; T[index] ((1) #'(assignment-argument-1 container (first parsed-args) expr)) ;; 2 arguments in [ ] ;; ex: T[i1 :] , T[: i2], T[i1 i2] , T[: :] ;; {#(1 2 3 4 5)[inexact->exact(floor(2.7)) :]} ;; '#(3 4 5) ((2) #'(assignment-argument-2 container (first parsed-args) (second parsed-args) expr)) ;; 3 arguments in [ ] ;; T[i1 : i2] , T[i1 i2 i3] , T[: : s] ((3) #'(assignment-argument-3 container (first parsed-args) (second parsed-args) (third parsed-args) expr)) ;; 4 arguments in [ ] ;; T[: i2 : s] , T[i1 : : s] , T[i1 : i3 :] , T[i1 i2 i3 i4] ((4) #'(assignment-argument-4 container (first parsed-args) (second parsed-args) (third parsed-args) (fourth parsed-args) expr)) ;; 5 arguments in [ ] ;; T[i1 : i3 : s] , T[i1 i2 i3 i4 i5] ((5) #'(assignment-argument-5 container (first parsed-args) (second parsed-args) (third parsed-args) (fourth parsed-args) (fifth parsed-args) expr)) ;; more than 5 arguments in [ ] ;; T[i1 i2 i3 i4 i5 i6 ...] (else ; case #'(assignment-argument-6-and-more container parsed-args expr))))) (else ; cond #'(set!-values-plus (brket-applynext container index ...) expr)))) ; warning: the argument's names does not match the use ;;(=E2=86=90 x 5) ((_ var expr) #'(set! var expr)) ;; (declare x y z t) ;; {x =E2=86=90 y =E2=86=90 z =E2=86=90 t =E2=86=90 7} ;; 7 ;; (list x y z t) ;; (7 7 7 7) ;; > (require srfi/25) ;; > {I =E2=86=90 (make-array (shape 0 4 0 4))} ;; # ;; > {I[0 0] =E2=86=90 I[1 1] =E2=86=90 I[2 2] =E2=86=90 I[3 3] =E2= =86=90 1} ;; 1 ;; > {I[0 0]} ;; 1 ;; > {I[0 1]} ;; 0 ;; > I ;; # ;; > (declare a b c d) ;; > {(a b) =E2=86=90 (c d) =E2=86=90 (values 5 7)} ;; > a ;; 5 ;; > b ;; 7 ;; > c ;; 5 ;; > d ;; 7 ;; without declare: ;; > {(a b) =E2=86=90 (c d) =E2=86=90 (values 5 7)} ;; > (list a b c d) ;; '(5 7 5 7) ((_ var var1 ... expr) #'(begin ;; i do not do what the syntax says (assignation not in the good order) but it gives the same result ;;(display "=E2=86=90 : case (_ var var1 ... expr)") (newline) (define return-values-of-expr (create-return-values expr)) (=E2=86=90 var (return-values-of-expr)) ;;(display "=E2=86=90 : case : passed (=E2=86=90 var expr)") (newline) ;;(display "=E2=86=90 : case : var=3D") (display var) (newline) (=E2=86=90 var1 (return-values-of-expr)) ...)) ))) even if the version above of =E2=86=90 is the same as <- ,i just replaced a= t any place <- by =E2=86=90 i have no explains. I suppose there is something hard too understand with the macro syntax system. i even tried this : (define-syntax =E2=86=90 (syntax-rules () ((_ ( ) expr) (<- ( ) expr)) ((_ (var) expr) (<- (var) expr)) ((_ (brket-applynext container index ...) expr) (<- (brket-applynext container index ...) expr)) ((_ var expr) (<- var expr)) ((_ var var1 ... expr) (<- var var1 ... expr)))) to better respect the pattern of <- it fails too when call from =E2=86=90 when i will port this version of scheme+ to kawa or racket i will check all this again to see if it is a problem related to guile or scheme (but with kawa or racket i will have no support for curly-infix so the problem could be different...) On Fri, May 10, 2024 at 12:33=E2=80=AFPM Jean Abou Samra wrote: > > > sorry, but this can not works because my macro is defined this way: > > (define-syntax <- > > (lambda (stx) > > (syntax-case stx () > > ;; silly case > > ((_ ( ) expr) > > #'(void)) ;; void is not portable ;'()) > > ;; one value in values ! > > ;; > {(x) <- (values 7)} > > ;; > x > > ;; 7 > > ((_ (var) expr) > > #'(set!-values-plus (var) expr)) > > > > etc... other case continues > > > > so my arguments are not put in a list as in your definition. > > > That has no influence whatsoever. The macro =E2=86=90 just replaces > itself with <- and then <- does its job as usual. > > For example, this works perfectly: > > (define-syntax <- > (syntax-rules () > ((<- foo bar) (set! foo bar)) > ((<- foo) (set! foo #f)))) > > (define-syntax-rule (=E2=86=90 . args) (<- . args)) > > (define a 5) > (=E2=86=90 a 7) > (display a) (newline) > (=E2=86=90 a) > (display a) (newline) > > > It is similar to how you can alias a procedure with > > (define alias (lambda args (apply old-procedure args))) > > > > > > ok i see it is not define-syntax but define-syntax-rules, first not in > R6RS, > > so not portable ,does not exist in Kawa: > > #|kawa:1|# define-syntax-rules > > /dev/tty:1:1: warning - no declaration seen for define-syntax-rules > > /dev/tty:1:1: unbound location: define-syntax-rules > > > OK, make that > > (define-syntax =E2=86=90 > (syntax-rules () > ((=E2=86=90 . args) > (<- . args)))) > > define-syntax-rule is merely a shortcut for syntax-rules > macros with just one rule like this (but it's indeed no > standard). > > > > but i test it with my guile code,fails too at run-time: > > scheme@(guile-user)> (logic-test) > > test 1 > > (or (and (not a) (not b) (not c) (not d)) (and (not a) (not b) (not c) = d) > > (and > > (not a) (not b) c (not d)) (and (not a) b (not c) d) (and (not a) b c > (not > > d)) > > (and (not a) b c d) (and a (not b) (not c) (not d)) (and a (not b) (not > c) > > d) > > (and a (not b) c (not d)) (and c (not d))) =3D 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 /Users/mattei/library-FunctProg/guile/logiki+.scm: > > 2848:18 5 (_ #) > > 743:23 4 (infix-symb-min-dnf _) > > 1777:41 3 (minimal-dnf _) > > 2707:38 2 (_ _) > > 2526:19 1 (identify-essential-prime-implicants _ _) > > In ice-9/boot-9.scm: > > 1685:16 0 (raise-exception _ #:continuable? _) > > > > the offending code is here: > > > > ;; construction of the array > > ;; set the left column containing prime implicants > > (for-basic (lin 0 {lgt-pi - 1}) > > ;;(display "lin=3D") (display lin) (newline) > > ;;(display "{vct-prime-implicants[lin]}=3D") (display > > {vct-prime-implicants[lin]}) (newline) > > ;;(display "{iepi[{lin + 1} 0]}=3D") (display {iepi[{lin + 1} 0]}) > > (newline) > > {iepi[{lin + 1} 0] =E2=86=90 vct-prime-implicants[lin]}) > > ;;{iepi[{lin + 1} 0] <- vct-prime-implicants[lin]}) > > > > ;(display "iepi after") (newline) > > > > exactly here, just in the macro: > > {iepi[{lin + 1} 0] =E2=86=90 vct-prime-implicants[lin]}) > > in the macro lin is not more binded, so i suppose there is a problem of > > hygiene, the macro wipe out the binding of lin > > > > but it works at REPL,strange ... : > > > > 1685:16 0 (raise-exception _ #:continuable? _) > > scheme@(guile-user) [1]> ,q > > scheme@(guile-user)> {v <+ (vector 1 2 3 4)} > > scheme@(guile-user)> {v[1 : 3] <- #(-1 -2 -3 -4 -5 -6 -7)[2 : 4]} > > <- : #'(index ...) =3D (# # file:6:5 > > :> #) > > <- : (syntax->datum #'(index ...)) =3D (1 : 3) > > <- : #'parsed-args=3D# 1 := 3)> > > <- : (syntax->datum #'parsed-args)=3D(list 1 : 3) > > $bracket-apply$ : parsed-args=3D# > (# 2 : 4)> > > scheme@(guile-user)> v > > $1 =3D #(1 -3 -4 4) > > scheme@(guile-user)> {v[1 : 3] =E2=86=90 #(-1 -2 -3 -4 -5 -6 -7)[2 : 4]= } > > <- : #'(index ...) =3D (# # file:8:5 > > :> #) > > <- : (syntax->datum #'(index ...)) =3D (1 : 3) > > <- : #'parsed-args=3D# 1 := 3)> > > <- : (syntax->datum #'parsed-args)=3D(list 1 : 3) > > $bracket-apply$ : parsed-args=3D# > (# 2 : 4)> > > scheme@(guile-user)> v > > $2 =3D #(1 -3 -4 4) > > scheme@(guile-user)> (define lin 1) > > scheme@(guile-user)> {v[lin : 3] =E2=86=90 #(-1 -2 -3 -4 -5 -6 -7)[2 : = 4]} > > <- : #'(index ...) =3D (# # > file:11:7 :> #) > > <- : (syntax->datum #'(index ...)) =3D (lin : 3) > > <- : #'parsed-args=3D# lin= : > 3)> > > <- : (syntax->datum #'parsed-args)=3D(list lin : 3) > > $bracket-apply$ : parsed-args=3D# > (# 2 : 4)> > > scheme@(guile-user)> v > > $3 =3D #(1 -3 -4 4) > > > > and even with a variable ,i defined lin in the example > > > Hard to tell with so much code and without context on what > you're trying to do, but this might be caused precisely by > stripping identifier annotations. Consider: > > (define-syntax mac > (lambda (sintax) > (syntax-case sintax () > ((mac arg) > (datum->syntax #f (syntax->datum #'arg)))))) > > ;; Works: > ;; (define lin 6) > ;; (display (mac lin)) > > ;; Fails (as expected): > (let ((lin 5)) > (display (mac lin))) > > > yes frightening... the variable just disappeared... note in Racket the 2 examples fails: Welcome to DrRacket, version 8.12 [cs]. Language: racket, with debugging; memory limit: 8192 MB. > (define lin 6) > (display (mac lin)) lin: unbound identifier; also, no #%top syntax transformer is bound in: lin > (let ((lin 5)) (display (mac lin))) lin: unbound identifier; also, no #%top syntax transformer is bound in: lin > 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)> about my code , as i said it earlier, if i remove the datum->syntax #f (syntax->datum from my <- macro then your solution for =E2=86=90 works pref= ectly in the logic code but it then fails in the backpropagation deep learning code where + is overloaded with GOOPS so as i want the most compatible system i can not use it.But of course that would be better to understand what really happens. I'm not sure my code is well written but i can not clone this macro this way. About my code , i use a parser in command line and a macro system to extend the syntax of scheme, with macro doing the job in guile of parser in pre-compil time this is better because transparent for a guile coder that want to use scheme+. It is important to have pre-compil parsing of infix expression because the infix to prefix parsing is done one time before run time as it does not change after at runtime it is something that can be done before.(unless that the parsing is done at run time and if the calulus is in a loop this could be a big penalty about time)