* macro error: ... follows template with no suitably-nested pattern variable
@ 2023-10-06 22:01 Damien Mattei
2023-10-07 7:53 ` Damien Mattei
0 siblings, 1 reply; 2+ messages in thread
From: Damien Mattei @ 2023-10-06 22:01 UTC (permalink / raw)
To: kawa mailing list
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: macro error: ... follows template with no suitably-nested pattern variable
2023-10-06 22:01 macro error: ... follows template with no suitably-nested pattern variable Damien Mattei
@ 2023-10-07 7:53 ` Damien Mattei
0 siblings, 0 replies; 2+ messages in thread
From: Damien Mattei @ 2023-10-07 7:53 UTC (permalink / raw)
To: kawa mailing list
this solution works:
;; scheme@(guile-user)> (def (foo) (when #t (return "hello") "bye"))
;; scheme@(guile-user)> (foo)
;; "hello"
;; (def x)
;; (def (foo n)
;; (cond ((= n 0) 'end0)
;; ((= 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 ((= n 0) 'end0)
;; ((= n 7) (return-rec 'end7))
;; (else (cons n (bar {n - 1})))))
;; scheme@(guile-user)> (bar 5)
;; $4 = (5 4 3 2 1 . end0)
;; scheme@(guile-user)> (bar 10)
;; $5 = 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"))
;; ((_ (<name> <arg> ...) <body> <body>* ...)
;; (let ((ret-id (datum->syntax stx 'return)))
;; #`(define (<name> <arg> ...)
;; (call/cc (lambda (#,ret-id) <body> <body>* ...)))))
((_ (<name> <arg> ...) <body> <body>* ...)
(let ((ret-id (datum->syntax stx 'return))
(ret-rec-id (datum->syntax stx 'return-rec)))
#`(define (<name> <arg> ...)
(call/cc (lambda (#,ret-rec-id)
(apply (rec <name> (lambda (<arg> ...)
(call/cc (lambda (#,ret-id) <body> <body>*
...)))) (list <arg> ...)))))))
;; 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 ⥆
(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) ⥅ (x y z) ⥅ (u v w) ⥅ (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 ⥅
(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 AM Damien Mattei <damien.mattei@gmail.com> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-10-07 7:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-06 22:01 macro error: ... follows template with no suitably-nested pattern variable Damien Mattei
2023-10-07 7:53 ` Damien Mattei
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).