From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Nala Ginrut Newsgroups: gmane.lisp.guile.devel Subject: Re: Announcing the first stable release of guile-for-loops Date: Sat, 25 Jan 2020 02:26:50 +0800 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000684c22059ce6e75d" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="101375"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-devel To: Stefan Israelsson Tampe Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Fri Jan 24 19:27:19 2020 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iv3fq-000QK4-RX for guile-devel@m.gmane-mx.org; Fri, 24 Jan 2020 19:27:18 +0100 Original-Received: from localhost ([::1]:46284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iv3fp-0006rP-Vw for guile-devel@m.gmane-mx.org; Fri, 24 Jan 2020 13:27:18 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40887) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iv3fd-0006r2-Ec for guile-devel@gnu.org; Fri, 24 Jan 2020 13:27:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iv3fb-0007wQ-Uj for guile-devel@gnu.org; Fri, 24 Jan 2020 13:27:05 -0500 Original-Received: from mail-yw1-xc2f.google.com ([2607:f8b0:4864:20::c2f]:32771) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iv3fb-0007v7-O1 for guile-devel@gnu.org; Fri, 24 Jan 2020 13:27:03 -0500 Original-Received: by mail-yw1-xc2f.google.com with SMTP id 192so1306003ywy.0 for ; Fri, 24 Jan 2020 10:27:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0fD8ROl/wGk3kIJYWvoB4ShWcUTGM6zezqMvDC6VwPs=; b=gr0k/dGp6tOUntZXFmnLflgH0KShKL7SOc0xPuZ8gKCv9rbHts5NjVOOfshteMPZeZ RHxFxWEN9+xS9WIz67ClEKztzV1WZ4JHK5c4lM4njKbwghfLKLcfbp7eaxxeAmnwtLUj S1jLVh72pdRUaDQtVJJc2Uxc2tkHuUosI0WnMUKB7Jbb1oU8M7Bc/1l6imk7t8ODI3dl 30PCBPflg03nI6HzRnLl5pITuAztdHnIb8V2OiBjPCRVd/79rjatvV2hEYZ05F5ruwru sEHiJXRPwdeTZEzvkd1xiMkfxgQatXYVwCFzdgiDcxC4MwCcmn+vygg8+atD5i6onQnI sQmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0fD8ROl/wGk3kIJYWvoB4ShWcUTGM6zezqMvDC6VwPs=; b=JWvLFgb1iOg82G+tJYRsILA/Rv6qs2LU8OwHb2Pl1WDV0rAf4P7UZrzl21PCef5eqk q+zkA3QTOr6JIh6D8Bi+FR1i4+wML6dvqWgCSU+iJnchXd3GgXZVaogOA3IqgkLiPfl8 BoEbkDkJa0J1PifN6OAD3/6Ig0KBmR3iZzDFBi3OtRM0AsT7tL27jGtsI434/w6rLkiS Yk9TYFkgRwrjsFd8ov8fS0NonUkCWEybqGXgfilySW9gsofPbpwuW4jG8kcTcvNHhiuI DeqWo0J3n/FR8LxSUhGX/OHGodtYiEqVm3eVYcfq76yEhIf+Yb7TA+OAWvwjo3nZPZmp MrpQ== X-Gm-Message-State: APjAAAWbRdpAqynqihH/Ry8FC4uLc9CWwVV/tYxJL4gYLfCrkX6jYNf/ 95vzuJPsEs705atbaINpl9mbXLRlHh7ViuuAsJM= X-Google-Smtp-Source: APXvYqwh7uTSMizcTP6gK1Tr6fznUVu+smDViO6F55HcyQmn3m1lMMJBMbQ1jWXJWfuhx/XZBxXQpbKBiFJe6UTKhHk= X-Received: by 2002:a81:bb41:: with SMTP id a1mr2971128ywl.253.1579890422335; Fri, 24 Jan 2020 10:27:02 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::c2f X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.io gmane.lisp.guile.devel:20329 Archived-At: --000000000000684c22059ce6e75d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable +1 On Fri, Jan 24, 2020, 20:13 Stefan Israelsson Tampe wrote: > > > ---------- Forwarded message --------- > From: Stefan Israelsson Tampe > Date: Fri, Jan 24, 2020 at 12:42 PM > Subject: Re: Announcing the first stable release of guile-for-loops > To: Linus Bj=C3=B6rnstam > > > Would be cool to have those implemented in guile, that would make my > guile-syntax-parse a bit leaner > > Regards > Stefan > > On Thu, Jan 23, 2020 at 3:03 PM Linus Bj=C3=B6rnstam < > linus.bjornstam@veryfast.biz> wrote: > >> Hiya everybody! >> >> I have spent some time implementing efficient for loops for guile, and >> they are baked and ready to go. I have worked the last weeks at >> implementing generalized support for non-tail-recursive loops and am hap= py >> to announce for/foldr. It is a generic right fold, with support for >> delaying it's arguments as either thunks or promises. >> >> The syntax is more or less the same as racket's loops, and they are >> generally compatible. The code generated is for almost all cases as fast= as >> hand-rolled code. They are all expressed as left or right folds, and are= as >> such (apart from for/list, but read about that in the documentation) fre= e >> of mutation. They are all converted to named lets. >> >> Some examples: >> >> (for/list ((a (in-range 1 6))) >> (* a a)) ;; =3D> (1 4 9 16 25) >> >> (for*/list ((a (in-string "ab")) (b (in-range 1 3))) >> (list a b)) >> ;; =3D> ((#\a 1) (#\a 2) (#\b 1) (#\b 2)) >> >> There are many more looping constructs, among others: >> for/sum, for/vector, for/or, for/and, for/first, for/last and a >> side-effecting simple for. >> >> Here is a sieve of erathostenes: >> >> (define (erathostenes n) >> (define vec (make-vector n #t)) >> (for/list ([i (in-range 2 n)] #:when (vector-ref vec i)) >> (for ([j (in-range/incr (* 2 i) n i)]) >> (vector-set! vec j #f)) >> i)) >> >> The code and documentation is available here: >> https://hg.sr.ht/~bjoli/guile-for-loops >> >> A web-friendly documentation can be found here: >> https://man.sr.ht/%7Ebjoli/for-loops-docs/for-loops.md >> >> The thing I had been waiting for is right fold. That allows us to write >> loops like guile's map: non-tail recursive: >> (for/foldr ((identity '())) ((a (in-list '(1 2 3)))) >> (cons (* a a) identity)) >> >> becomes equivalent to: >> >> (let loop ((random-identifier '(1 2 3))) >> (if (null? random-identifier) >> '() >> (let ((a (car random-identifier))) >> (cons (* a a) (loop (cdr random-identifier)))))) >> >> Happy hacking >> Linus Bj=C3=B6rnstam >> >> --000000000000684c22059ce6e75d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
+1

On Fri, Jan 24, 2020, 20:13 Stefan Israelsson Tampe <= ;stefan.itampe@gmail.com>= wrote:


---------- F= orwarded message ---------
From: Stefan Israelsson Tampe <st= efan.itampe@gmail.com>
Date: Fri, Jan 24, 2020 at 12:42 PM=
Subject: Re: Announcing the first stable release of guile-for-loops
= To: Linus Bj=C3=B6rnstam <linus.bjornstam@veryfast.biz>=


Would be cool to have those implemented= =C2=A0in guile, that would make my guile-syntax-parse a bit leaner

=
Regards
Stefan

On Thu, Jan 23, 2020 at 3:03 PM Li= nus Bj=C3=B6rnstam <linus.bjornstam@veryfast.biz> wrote= :
Hiya everybody= !

I have spent some time implementing efficient for loops for guile, and they= are baked and ready to go. I have worked the last weeks at implementing ge= neralized support for non-tail-recursive loops and am happy to announce for= /foldr. It is a generic right fold, with support for delaying it's argu= ments as either thunks or promises.

The syntax is more or less the same as racket's loops, and they are gen= erally compatible. The code generated is for almost all cases as fast as ha= nd-rolled code. They are all expressed as left or right folds, and are as s= uch (apart from for/list, but read about that in the documentation) free of= mutation. They are all converted to named lets.

Some examples:

(for/list ((a (in-range 1 6)))
=C2=A0 (* a a)) ;; =3D> (1 4 9 16 25)

(for*/list ((a (in-string "ab")) (b (in-range 1 3)))
=C2=A0 (list a b))
;; =3D> ((#\a 1) (#\a 2) (#\b 1) (#\b 2))

There are many more looping constructs, among others:
for/sum, for/vector, for/or, for/and, for/first, for/last and a side-effect= ing simple for.

Here is a sieve of erathostenes:

(define (erathostenes n)
=C2=A0 (define vec (make-vector n #t))
=C2=A0 (for/list ([i (in-range 2 n)] #:when (vector-ref vec i))
=C2=A0 =C2=A0 (for ([j (in-range/incr (* 2 i) n i)])
=C2=A0 =C2=A0 =C2=A0 (vector-set! vec j #f))
=C2=A0 =C2=A0 i))

The code and documentation is available here:
https://hg.sr.ht/~bjoli/guile-for-loops

A web-friendly documentation can be found here:
https://man.sr.ht/%7Ebjoli/for-loop= s-docs/for-loops.md

The thing I had been waiting for is right fold. That allows us to write loo= ps like guile's map: non-tail recursive:
(for/foldr ((identity '())) ((a (in-list '(1 2 3))))
=C2=A0 (cons (* a a) identity))

becomes equivalent to:

(let loop ((random-identifier '(1 2 3)))
=C2=A0 (if (null? random-identifier)
=C2=A0 =C2=A0 =C2=A0 '()
=C2=A0 =C2=A0 =C2=A0 (let ((a (car random-identifier)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (cons (* a a) (loop (cdr random-identifier)))))= )

Happy hacking
Linus Bj=C3=B6rnstam

--000000000000684c22059ce6e75d--