[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: macro definition for continue and break
From: |
Jean Abou Samra |
Subject: |
Re: macro definition for continue and break |
Date: |
Sun, 4 Sep 2022 13:13:52 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 |
Hi,
Adding back the list in CC.
Le 04/09/2022 à 12:49, Damien Mattei a écrit :
hello jean,
yes (thank you for your help) i'm a sorcerer's apprentice that always
push to later the understanding of literals in syntax-rules, but by
instinct i finally succeed in making works the weird thing :-) , here
is my macro definition now for a for with break and continue:
(define-syntax for
(lambda (stx)
(syntax-case stx ()
((kwd (init test incrmt) body ...)
(with-syntax
((BREAK (datum->syntax #'kwd 'break))
(CONTINUE (datum->syntax #'kwd 'continue)))
#`(call/cc
(lambda (escape)
(let-syntax
((BREAK (identifier-syntax (escape))))
init
(let loop ()
(when test
#,#'(call/cc
(lambda (next)
(let-syntax
((CONTINUE
(identifier-syntax (next))))
body ...)))
incrmt
(loop)))))))))))
note the mysterious #,#' that save the day ;-)
For me, it works without it… ?
and a few examples (in Scheme+)
;; scheme@(guile-user)> (for ({i <+ 0} {i < 5} {i <- {i + 1}}) {x <+
7} (display x) (newline) (break))
;; 7
;; scheme@(guile-user)> (for ({i <+ 0} {i < 5} {i <- {i + 1}}) {x <+
7} (continue) (display x) (newline) (break))
;; scheme@(guile-user)>
;; (for ({k <+ 0} {k < 3} {k <- {k + 1}})
;; (display k)
;; (newline)
;; (for ({i <+ 0} {i < 5} {i <- {i + 1}}) {x <+ 7}
;; (display x)
;; (newline)
;; (break))
;; (newline))
;; 0
;; 7
;; 1
;; 7
;; 2
;; 7
;; (for ({k <+ 0} {k < 3} {k <- {k + 1}})
;; (display k)
;; (newline)
;; (continue)
;; (for ({i <+ 0} {i < 5} {i <- {i + 1}}) {x <+ 7}
;; (display x)
;; (newline)
;; (break))
;; (newline))
;; 0
;; 1
;; 2
https://github.com/damien-mattei/library-FunctProg/blob/master/for-next-step.scm
it also works with imbricated loops in a natural way (but other
interpretation and implementation could be done , C act like this ,i
think)
but if it could be coded better i will use a better version
Yes, it can be done better; see my reply on the other thread.
Best,
Jean
- macro definition for continue and break, Damien Mattei, 2022/09/04
- Re: macro definition for continue and break, Jean Abou Samra, 2022/09/04
- Message not available
- Re: macro definition for continue and break,
Jean Abou Samra <=
- Re: macro definition for continue and break, Linus Björnstam, 2022/09/12
- Loop macros (was: Re: macro definition for continue and break), Maxime Devos, 2022/09/12
- Re: Loop macros (was: Re: macro definition for continue and break), Linus Björnstam, 2022/09/12
- Re: Loop macros (was: Re: macro definition for continue and break), Damien Mattei, 2022/09/13
- Re: Loop macros (was: Re: macro definition for continue and break), Maxime Devos, 2022/09/13
- Re: Loop macros (was: Re: macro definition for continue and break), Damien Mattei, 2022/09/14
- Re: macro definition for continue and break, Damien Mattei, 2022/09/13