* macro definition for continue and break @ 2022-09-04 8:19 Damien Mattei 2022-09-04 10:08 ` Jean Abou Samra 0 siblings, 1 reply; 10+ messages in thread From: Damien Mattei @ 2022-09-04 8:19 UTC (permalink / raw) To: guile-user my previous question ,clearly more, is : (define-syntax for/bc (syntax-rules (continue break) ((_ (init test incrmt) b1 ...) (call/cc (lambda (break) (let () init (let loop () (when test (call/cc (lambda (continue) b1 ...)) incrmt (loop))))))))) is there a way to make working this macro in a R6RS compatible way (i know it is possible in Racket or with syntax features...) to avoid error: (for/bc ({i <+ 0} {i < 5} {i <- {i + 1}}) {x <+ 7} (display x) (newline) (break)) ;;; <stdin>:2:73: warning: possibly wrong number of arguments to `break' 7 ice-9/boot-9.scm:1685:16: In procedure raise-exception: Wrong number of arguments to #<procedure break (pred clist)> Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. Damien ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: macro definition for continue and break 2022-09-04 8:19 macro definition for continue and break Damien Mattei @ 2022-09-04 10:08 ` Jean Abou Samra [not found] ` <CADEOadd2OAL-Z4o9AAR_mQ5_NSjCA1tVz5cDgeufVZ=ocAx0vQ@mail.gmail.com> 0 siblings, 1 reply; 10+ messages in thread From: Jean Abou Samra @ 2022-09-04 10:08 UTC (permalink / raw) To: Damien Mattei, guile-user Le 04/09/2022 à 10:19, Damien Mattei a écrit : > my previous question ,clearly more, is : > (define-syntax for/bc > > (syntax-rules (continue break) > > ((_ (init test incrmt) b1 ...) > > (call/cc (lambda (break) > (let () > init > (let loop () > (when test > (call/cc (lambda (continue) b1 ...)) > incrmt > (loop))))))))) > > is there a way to make working this macro in a R6RS compatible way (i know > it is possible in Racket or with syntax features...) > > to avoid error: > (for/bc ({i <+ 0} {i < 5} {i <- {i + 1}}) > {x <+ 7} > (display x) > (newline) > (break)) > > ;;; <stdin>:2:73: warning: possibly wrong number of arguments to `break' > 7 > ice-9/boot-9.scm:1685:16: In procedure raise-exception: > Wrong number of arguments to #<procedure break (pred clist)> > > Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. You seem to be mistaken about what the literals list in syntax-rules does. It enables literal matching in the pattern part, and only has an effect on the patterns. It does not make 'break' in the expanded body expand as an unhygienic identifier. It allows to recognize keywords, but not to introduce them. Yo need to use datum->syntax for that. You're getting a break procedure from somewhere else: scheme@(guile-user)> (use-modules (srfi srfi-1)) scheme@(guile-user)> break $1 = #<procedure break (pred clist)> You seem to have corrected this mistake in your second post with a similar question, so I'll continue on that thread. ^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <CADEOadd2OAL-Z4o9AAR_mQ5_NSjCA1tVz5cDgeufVZ=ocAx0vQ@mail.gmail.com>]
* Re: macro definition for continue and break [not found] ` <CADEOadd2OAL-Z4o9AAR_mQ5_NSjCA1tVz5cDgeufVZ=ocAx0vQ@mail.gmail.com> @ 2022-09-04 11:13 ` Jean Abou Samra 2022-09-12 19:19 ` Linus Björnstam 0 siblings, 1 reply; 10+ messages in thread From: Jean Abou Samra @ 2022-09-04 11:13 UTC (permalink / raw) To: Damien Mattei; +Cc: Guile User 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: macro definition for continue and break 2022-09-04 11:13 ` Jean Abou Samra @ 2022-09-12 19:19 ` Linus Björnstam 2022-09-12 20:57 ` Loop macros (was: Re: macro definition for continue and break) Maxime Devos 2022-09-13 14:16 ` macro definition for continue and break Damien Mattei 0 siblings, 2 replies; 10+ messages in thread From: Linus Björnstam @ 2022-09-12 19:19 UTC (permalink / raw) To: Jean Abou Samra, Damien Mattei; +Cc: Guile User If you want a bit more advanced looping you could have a look at my goof-loop: https://git.sr.ht/~bjoli/goof-loop It currently does not support a break or continue clause, but adding one should not really be a problem. A good thing is that it does not rely on mutation for anything except higher order sequences, meaning it does not lead to the implicit boxing overhead of set!, which is a good idea in loops since that quickly adds up. Best regards Linus Björnstam On Sun, 4 Sep 2022, at 13:13, Jean Abou Samra wrote: > 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Loop macros (was: Re: macro definition for continue and break) 2022-09-12 19:19 ` Linus Björnstam @ 2022-09-12 20:57 ` Maxime Devos 2022-09-12 21:09 ` Linus Björnstam 2022-09-13 14:25 ` Damien Mattei 2022-09-13 14:16 ` macro definition for continue and break Damien Mattei 1 sibling, 2 replies; 10+ messages in thread From: Maxime Devos @ 2022-09-12 20:57 UTC (permalink / raw) To: Linus Björnstam, Jean Abou Samra, Damien Mattei; +Cc: Guile User [-- Attachment #1.1.1: Type: text/plain, Size: 1108 bytes --] On 12-09-2022 21:19, Linus Björnstam wrote: > If you want a bit more advanced looping you could have a look at my goof-loop: https://git.sr.ht/~bjoli/goof-loop > > It currently does not support a break or continue clause, but adding one should not really be a problem. > > A good thing is that it does not rely on mutation for anything except higher order sequences, meaning it does not lead to the implicit boxing overhead of set!, which is a good idea in loops since that quickly adds up. > > Best regards > Linus Björnstam I also have a mutation-free loop macro, named 'hat-let' or 'let^': https://git.gnunet.org/gnunet-scheme.git/tree/gnu/gnunet/utils/hat-let.scm Its origin is rather different though, goof-loop appears to be the result of combining various loop-related constructs, plus some extras, whereas let^ is the result of combining various binding constructs (including the 'let loop'), plus some extras. It combines the following: let*, lambda / define, receive, 'let loop', 'if', 'begin'. Doesn't do any accumulation though. Greetings, Maxime. [-- Attachment #1.1.2: OpenPGP public key --] [-- Type: application/pgp-keys, Size: 929 bytes --] [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 236 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Loop macros (was: Re: macro definition for continue and break) 2022-09-12 20:57 ` Loop macros (was: Re: macro definition for continue and break) Maxime Devos @ 2022-09-12 21:09 ` Linus Björnstam 2022-09-13 14:25 ` Damien Mattei 1 sibling, 0 replies; 10+ messages in thread From: Linus Björnstam @ 2022-09-12 21:09 UTC (permalink / raw) To: Maxime Devos, Jean Abou Samra, Damien Mattei; +Cc: Guile User I would say it is mostly an extension of foof-loop with the addition of subloops. It is also written mostly in syntax-rules, which makes is portable. I am not happy with the extensibility outside the possibility to add :for and :acc clauses, since it is pretty darn awful do do any changes to the internals. I have a couple of things I want to sort out, but the source code has started to scare me. -- Linus Björnstam On Mon, 12 Sep 2022, at 22:57, Maxime Devos wrote: > On 12-09-2022 21:19, Linus Björnstam wrote: >> If you want a bit more advanced looping you could have a look at my goof-loop: https://git.sr.ht/~bjoli/goof-loop >> >> It currently does not support a break or continue clause, but adding one should not really be a problem. >> >> A good thing is that it does not rely on mutation for anything except higher order sequences, meaning it does not lead to the implicit boxing overhead of set!, which is a good idea in loops since that quickly adds up. >> >> Best regards >> Linus Björnstam > > I also have a mutation-free loop macro, named 'hat-let' or 'let^': > > https://git.gnunet.org/gnunet-scheme.git/tree/gnu/gnunet/utils/hat-let.scm > > Its origin is rather different though, goof-loop appears to be the > result of combining various loop-related constructs, plus some extras, > whereas let^ is the result of combining various binding constructs > (including the 'let loop'), plus some extras. > > It combines the following: let*, lambda / define, receive, 'let loop', > 'if', 'begin'. > > Doesn't do any accumulation though. > > Greetings, > Maxime. > > Attachments: > * OpenPGP_0x49E3EE22191725EE.asc > * OpenPGP_signature ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Loop macros (was: Re: macro definition for continue and break) 2022-09-12 20:57 ` Loop macros (was: Re: macro definition for continue and break) Maxime Devos 2022-09-12 21:09 ` Linus Björnstam @ 2022-09-13 14:25 ` Damien Mattei 2022-09-13 14:28 ` Maxime Devos 1 sibling, 1 reply; 10+ messages in thread From: Damien Mattei @ 2022-09-13 14:25 UTC (permalink / raw) To: Maxime Devos; +Cc: Linus Björnstam, Jean Abou Samra, Guile User do you have any examples of use? that illustrate the features ,just with the code it is not easy. Regards, Damien On Mon, Sep 12, 2022 at 10:57 PM Maxime Devos <maximedevos@telenet.be> wrote: > > > On 12-09-2022 21:19, Linus Björnstam wrote: > > If you want a bit more advanced looping you could have a look at my > goof-loop: https://git.sr.ht/~bjoli/goof-loop > > > > It currently does not support a break or continue clause, but adding one > should not really be a problem. > > > > A good thing is that it does not rely on mutation for anything except > higher order sequences, meaning it does not lead to the implicit boxing > overhead of set!, which is a good idea in loops since that quickly adds up. > > > > Best regards > > Linus Björnstam > > I also have a mutation-free loop macro, named 'hat-let' or 'let^': > > https://git.gnunet.org/gnunet-scheme.git/tree/gnu/gnunet/utils/hat-let.scm > > Its origin is rather different though, goof-loop appears to be the > result of combining various loop-related constructs, plus some extras, > whereas let^ is the result of combining various binding constructs > (including the 'let loop'), plus some extras. > > It combines the following: let*, lambda / define, receive, 'let loop', > 'if', 'begin'. > > Doesn't do any accumulation though. > > Greetings, > Maxime. > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Loop macros (was: Re: macro definition for continue and break) 2022-09-13 14:25 ` Damien Mattei @ 2022-09-13 14:28 ` Maxime Devos 2022-09-14 15:56 ` Damien Mattei 0 siblings, 1 reply; 10+ messages in thread From: Maxime Devos @ 2022-09-13 14:28 UTC (permalink / raw) To: Damien Mattei; +Cc: Linus Björnstam, Jean Abou Samra, Guile User [-- Attachment #1.1.1: Type: text/plain, Size: 296 bytes --] On 13-09-2022 16:25, Damien Mattei wrote: > do you have any examples of use? that illustrate the features ,just with > the code it is not easy. "git grep -F let^" inside the repo. More specifically, parse-expandable from (gnu gnunet config parser), though there are other uses too. [-- Attachment #1.1.2: OpenPGP public key --] [-- Type: application/pgp-keys, Size: 929 bytes --] [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 236 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Loop macros (was: Re: macro definition for continue and break) 2022-09-13 14:28 ` Maxime Devos @ 2022-09-14 15:56 ` Damien Mattei 0 siblings, 0 replies; 10+ messages in thread From: Damien Mattei @ 2022-09-14 15:56 UTC (permalink / raw) To: Maxime Devos; +Cc: Linus Björnstam, Jean Abou Samra, Guile User thank you, i had a look directly on the web site, but since a few days i'm just using a single 'repeat ... until macro of my own (directly inspired from Pascal :-) if i do not mistake... and where i can put local define or just make mutations. ;; scheme@(guile-user)> {i <+ 5} ;; scheme@(guile-user)> (repeat (display i) (newline) {i <- {i - 1}} until {i < 0}) ;; 5 ;; 4 ;; 3 ;; 2 ;; 1 ;; 0 (define-syntax repeat (syntax-rules (until) ((repeat b1 ... until pred) (let loop () b1 ... (when (not pred) (loop)))))) regards, damien On Tue, Sep 13, 2022 at 4:28 PM Maxime Devos <maximedevos@telenet.be> wrote: > > > On 13-09-2022 16:25, Damien Mattei wrote: > > do you have any examples of use? that illustrate the features ,just with > > the code it is not easy. > > "git grep -F let^" inside the repo. More specifically, parse-expandable > from (gnu gnunet config parser), though there are other uses too. > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: macro definition for continue and break 2022-09-12 19:19 ` Linus Björnstam 2022-09-12 20:57 ` Loop macros (was: Re: macro definition for continue and break) Maxime Devos @ 2022-09-13 14:16 ` Damien Mattei 1 sibling, 0 replies; 10+ messages in thread From: Damien Mattei @ 2022-09-13 14:16 UTC (permalink / raw) To: Linus Björnstam; +Cc: Jean Abou Samra, Guile User interesting , i was just intending to have syntax and features a bit like C in fact.Your syntax goes beyond, Racket for too, i do not know Chibli scheme. Regards, Damien On Mon, Sep 12, 2022 at 9:20 PM Linus Björnstam <linus.internet@fastmail.se> wrote: > If you want a bit more advanced looping you could have a look at my > goof-loop: https://git.sr.ht/~bjoli/goof-loop > > It currently does not support a break or continue clause, but adding one > should not really be a problem. > > A good thing is that it does not rely on mutation for anything except > higher order sequences, meaning it does not lead to the implicit boxing > overhead of set!, which is a good idea in loops since that quickly adds up. > > Best regards > Linus Björnstam > > On Sun, 4 Sep 2022, at 13:13, Jean Abou Samra wrote: > > 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 > ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-09-14 15:56 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-09-04 8:19 macro definition for continue and break Damien Mattei 2022-09-04 10:08 ` Jean Abou Samra [not found] ` <CADEOadd2OAL-Z4o9AAR_mQ5_NSjCA1tVz5cDgeufVZ=ocAx0vQ@mail.gmail.com> 2022-09-04 11:13 ` Jean Abou Samra 2022-09-12 19:19 ` Linus Björnstam 2022-09-12 20:57 ` Loop macros (was: Re: macro definition for continue and break) Maxime Devos 2022-09-12 21:09 ` Linus Björnstam 2022-09-13 14:25 ` Damien Mattei 2022-09-13 14:28 ` Maxime Devos 2022-09-14 15:56 ` Damien Mattei 2022-09-13 14:16 ` macro definition for continue and break 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).