guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: macro definition for continue and break


From: Damien Mattei
Subject: Re: macro definition for continue and break
Date: Tue, 13 Sep 2022 16:16:49 +0200

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
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]