From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by sourceware.org (Postfix) with ESMTPS id ECD0A3858439 for ; Sat, 7 Oct 2023 07:53:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ECD0A3858439 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2b9c907bc68so32538921fa.2 for ; Sat, 07 Oct 2023 00:53:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696665210; x=1697270010; darn=sourceware.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=lB7dBCYA8be2XLsKXROXl3rYTY0j1iyHl67s34t4zJE=; b=VQ+OKEHzVZya+drsbBMiYPEma0ltzwihRD4lzWynNT0Fb98Sl7NQFZBcLYlQlD3CXV SZpyo1LMcWvBKleOFMhXALnFZV+Qv7lYselZRJ46LniBbsNc0M6qpnQ4sEpRkeW6UDzS LlTd5C7ObNY/nfyU2P4/Vzbhf432LGDHzoErXvO/Is9el4E2Z2+dgIWZamZABIkb/1hn gGx/atNJw2qIcNx4ikDd8rufbzuiWghn+5wrRCEqIqltthyaEpItE3wQxI224BeGAJ/3 8ZIANPJF1p2ZCTUxDPA8DIZ7dwynJhyRh32BOdm1bU5ZeBp5Gf4NbNMA4N+Vfu4LQXKv POdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696665210; x=1697270010; h=content-transfer-encoding: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=lB7dBCYA8be2XLsKXROXl3rYTY0j1iyHl67s34t4zJE=; b=CQcCROe9MXjF2cFFtB/0NyZc24egbiPocCWJGliEPMp+hk44SQB1C9Od5wowyIL6GD 3+zpYreTJTvH+eMZkPd5a3UJR6gYiriscs2nwWzNsh3vSXXuQdj7FMqfBCACwChcvDAM ncMMMJCLz1nf+KKMcXfjdFdyEQL1qOCWxwakmvy0EgkMkzP2i2sftaI6EZNl9YeYs/H4 JAZKMvHLnDPTemN/dKUT24R8UyH8278kkmuEhq892QguQlAdhqwg23JZoJie7YaZUcKj zVICn2YMZp6uMiQxBR4pyrhR5ojhI8W3uOr2M56sd/SJeFDdUO4cM6SkOzXivbRQtDsD mjNg== X-Gm-Message-State: AOJu0YxER2BCBdSDpgpOfF9OLr1ivOuitibwA+vdkeJvhZcULK+i4shl xxCMi+ZVe6/gXL1rx5MgZimx3P6Li+BUAbJ4DJYxy8vWXdY= X-Google-Smtp-Source: AGHT+IGRbREVuNUFNfA6OvqUEVedWQd+gJuz1fTqR2q8tFA4gNuF1E2ylUJd+puK7xBUyj88F0KKh6D1S6wM3CPUVtI= X-Received: by 2002:a05:651c:83:b0:2bf:f6b6:6c31 with SMTP id 3-20020a05651c008300b002bff6b66c31mr9823217ljq.41.1696665209813; Sat, 07 Oct 2023 00:53:29 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Damien Mattei Date: Sat, 7 Oct 2023 09:53:18 +0200 Message-ID: Subject: Re: macro error: ... follows template with no suitably-nested pattern variable To: kawa mailing list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: this solution works: ;; scheme@(guile-user)> (def (foo) (when #t (return "hello") "bye")) ;; scheme@(guile-user)> (foo) ;; "hello" ;; (def x) ;; (def (foo n) ;; (cond ((=3D n 0) 'end0) ;; ((=3D n 7) (return 'end7)) ;; (else (cons n (foo {n - 1}))))) ;; scheme@(guile-user)> (foo 5) ;; (5 4 3 2 1 . end0) ;; scheme@(guile-user)> (foo 10) ;; (10 9 8 . end7) ;; (def (bar n) ;; (cond ((=3D n 0) 'end0) ;; ((=3D n 7) (return-rec 'end7)) ;; (else (cons n (bar {n - 1}))))) ;; scheme@(guile-user)> (bar 5) ;; $4 =3D (5 4 3 2 1 . end0) ;; scheme@(guile-user)> (bar 10) ;; $5 =3D end7 (define-syntax def (lambda (stx) (syntax-case stx () ;; multiple definitions without values assigned ;; (def (x y z)) ((_ (var1 ...)) #`(begin (define var1 '()) ...)) ;; (def (foo) (when #t (return "hello") "bye")) ;; ((_ ( ...) * ...) ;; (let ((ret-id (datum->syntax stx 'return))) ;; #`(define ( ...) ;; (call/cc (lambda (#,ret-id) * ...))))) ((_ ( ...) * ...) (let ((ret-id (datum->syntax stx 'return)) (ret-rec-id (datum->syntax stx 'return-rec))) #`(define ( ...) (call/cc (lambda (#,ret-rec-id) (apply (rec (lambda ( ...) (call/cc (lambda (#,ret-id) * ...)))) (list ...))))))) ;; single definition without a value assigned ;; (def x) ((_ var) #`(define var '())) ;; (def x 7) ((_ var expr) #`(define var expr)) ((_ err ...) #`(syntax-error "Bad def form")) ))) ;; definition and assignment ;; { x <+ 7 } is equivalent to : (<- x 7) or (define x 7) ;; > {(a b c) <+ (values 7 8 9)} ;; 7 ;; 8 ;; 9 ;; > (list a b c) ;; '(7 8 9) ;; > { y <+ z <+ 7 } ;; > z ;; 7 ;; > y ;; 7 ;; > { x <+ y <+ z <+ 7 } ;; > (list x y z) ;; '(7 7 7) ;; > {(x y z) <+ (u v w) <+ (a b c) <+ (values 2 4 5)} ;; 2 ;; 4 ;; 5 ;; > (list x y z u v w a b c) ;; '(2 4 5 2 4 5 2 4 5) (define-syntax <+ (syntax-rules () ((_ (var1 ...) expr) (begin (define-values (var1 ...) expr) (values var1 ...))) ;; (begin ;; (define var1 '()) ;; ... ;; ;;(display "<+ multiple") (newline) ;; (set!-values (var1 ...) expr))) ;; > {(x y z) <+ (u v w) <+ (a b c) <+ (values 2 4 5)} ;; 2 ;; 4 ;; 5 ;; > (list x y z u v w a b c) ;; '(2 4 5 2 4 5 2 4 5) ;; ((_ (var10 ...) (var11 ...) ... expr) (begin ;; i do not do what the syntax says (assignation not in the good order) but it gives the same result ;; (define-values (var10 ...) expr) ;; (define-values (var11 ...) (values var10 ...= )) ;; ... ;; (values var10 ...))) ((_ (var10 ...) ... expr) (begin (define-values (var10 ...) expr) ... expr)) ((_ var expr) (begin (define var expr) var)) ;; > { y <+ z <+ 7 } ;; 7 ;; > z ;; 7 ;; > y ;; 7 ;; > { x <+ y <+ z <+ 7 } ;; 7 ;; > (list x y z) ;; '(7 7 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 (define var expr) (define var1 var) ... var)) )) (define-syntax =E2=A5=86 (syntax-rules () ((_ var ...) (<+ var ...)))) ;; > {(values 2 4 5) +> (x y z) +> (u v w) +> (a b c)} ;; 2 ;; 4 ;; 5 (define-syntax +> (syntax-rules () ((_ exp var ...) (<+ var ... exp)))) ;; > {(values 2 4 5) =E2=A5=85 (x y z) =E2=A5=85 (u v w) =E2=A5=85 (a b c)} ;; 2 ;; 4 ;; 5 ;; > (list x y z u v w a b c) ;; '(2 4 5 2 4 5 2 4 5) (define-syntax =E2=A5=85 (syntax-rules () ((_ expr ...) (+> expr ...)))) (<+ (x y z) (u v w) (a b c) (values 2 4 5)) (<+ result (list x y z u v w a b c)) (display result) (newline) (base) mattei@MacBook-Pro-Touch-Bar Scheme-PLUS-for-Kawa % kawa Scheme+.scm (2 4 5 2 4 5 2 4 5) but it is repeating the evaluation of expr On Sat, Oct 7, 2023 at 12:01=E2=80=AFAM Damien Mattei wrote: > > hello, > > this macro seems not valid for kawa but is right with Racket and Guile: > > > > (define-syntax <+ > (syntax-rules () > > ((_ (var1 ...) expr) (begin > (define-values (var1 ...) expr) > (values var1 ...))) > ;; (begin > ;; (define var1 '()) > ;; ... > ;; ;;(display "<+ multiple") (newline) > ;; (set!-values (var1 ...) expr))) > > ;; > {(x y z) <+ (u v w) <+ (a b c) <+ (values 2 4 5)} > ;; 2 > ;; 4 > ;; 5 > ;; > (list x y z u v w a b c) > ;; '(2 4 5 2 4 5 2 4 5) > ((_ (var10 ...) (var11 ...) ... expr) (begin ;; i do not do what > the syntax says (assignation not in the good order) but it gives the > same result > (define-values (var10 ...) expr) > (define-values (var11 ...) (values var10 ...)) > ... > (values var10 ...))) > > ((_ var expr) (begin > (define var expr) > var)) > > ;; > { y <+ z <+ 7 } > ;; 7 > ;; > z > ;; 7 > ;; > y > ;; 7 > ;; > { x <+ y <+ z <+ 7 } > ;; 7 > ;; > (list x y z) > ;; '(7 7 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 > (define var expr) > (define var1 var) > ... > var)) > > )) > > error: > > ... follows template with no suitably-nested pattern variable > > the error is located on the second pattern: > > ((_ (var10 ...) (var11 ...) ... expr) (begin ;; i do not do what the > syntax says (assignation not in the good order) but it gives the same > result > (define-values (var10 ...) expr) > (define-values (var11 ...) (values var10 ...)) > ... > (values var10 ...))) > > i had a few doubt long ago about multiple ... use but it worked well > with other scheme. > > Damien