From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: =?UTF-8?Q?Linus_Bj=C3=B6rnstam?= Newsgroups: gmane.lisp.guile.devel Subject: Announcing the first stable release of guile-for-loops Date: Thu, 23 Jan 2020 13:03:27 +0100 Message-ID: Mime-Version: 1.0 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="88451"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Cyrus-JMAP/3.1.7-775-g74f2d12-fmstable-20200121v1 To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Thu Jan 23 15:03:52 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 1iud5K-000Mvu-Tl for guile-devel@m.gmane-mx.org; Thu, 23 Jan 2020 15:03:50 +0100 Original-Received: from localhost ([::1]:57607 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iud5J-0006UR-Hq for guile-devel@m.gmane-mx.org; Thu, 23 Jan 2020 09:03:49 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42476) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iubDD-00078c-Td for guile-devel@gnu.org; Thu, 23 Jan 2020 07:03:53 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iubDC-0000Tk-H3 for guile-devel@gnu.org; Thu, 23 Jan 2020 07:03:51 -0500 Original-Received: from out2-smtp.messagingengine.com ([66.111.4.26]:35205) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iubDC-0000Se-6z for guile-devel@gnu.org; Thu, 23 Jan 2020 07:03:50 -0500 Original-Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 41BEF21F40 for ; Thu, 23 Jan 2020 07:03:48 -0500 (EST) Original-Received: from imap1 ([10.202.2.51]) by compute3.internal (MEProxy); Thu, 23 Jan 2020 07:03:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=veryfast.biz; h= mime-version:message-id:date:from:to:subject:content-type :content-transfer-encoding; s=fm1; bh=DkodTLrzCzg280h6goTDTaDaiB saXqtIjGAqaMtfkYA=; b=B11m/rTnv+W4UvP1TtOt1Wq2BPt3S0w+1hDu9ozGrE GtDsRQ0ZQuRyWJLMnmELUh+hDlwgu0SFy/uZgvSEgutiJu0FtKa+cXmqjIm1vcId dc8yDISVMzJlL2aRAXZJ/Dr8v8QnZaQ9cKTCw+itXNDflPJLqI7MHiJ9bjJxV1O5 BawDFowi4B0vwzjGRNEiYmXi03QIdrIToZBF/rMlZYOgWChB2kBNV9cB4Yn0ppRW y5lobD9XzLsfLNhEPqW7Ox6DhDEYzqCaA6DPTZ63yxULzE8EjQfv46mbYGsyKoY9 qLHAUC8xiN01mZCNoXV+RGlVOqr0DzZd+/mZem+GoYzA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=DkodTL rzCzg280h6goTDTaDaiBsaXqtIjGAqaMtfkYA=; b=uz1Jp5y3qIStA0RlksZUhi 1QlpKCHfp/MDxttsRrwoYM12DBB/vKu09hDnyboXNF80AoBwqpwm593tLTH/iTkE sevGgawygmylcNYukY0Z67FPHGbbbAYnuPbBeQTCG3nvopryPTl+xoJEZBRDAVlh PKkF+qrlxCmMJEws7+xDZD/KByECoXpjA6r8FBmdM1Dou27/ivJmzpTYAcEx5U+R 1qLhkwh9wUBRVBYm2awOyljJOL7El8acKXpyw/c0PyG7XxOfEoqfo4/rJiVSi6dj krujSjrmBMOZGgfakhAxrsbMeujYNVYDR8AA0BJPtMSSO4ZvIWaOOrKG26VHXTKQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrvddvgddvjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepofgfggfkfffhvffutgfgsehtqhertd erreejnecuhfhrohhmpefnihhnuhhspgeujhpnrhhnshhtrghmuceolhhinhhushdrsghj ohhrnhhsthgrmhesvhgvrhihfhgrshhtrdgsihiiqeenucffohhmrghinhepshhrrdhhth enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlihhn uhhsrdgsjhhorhhnshhtrghmsehvvghrhihfrghsthdrsghiii X-ME-Proxy: Original-Received: by mailuser.nyi.internal (Postfix, from userid 501) id CAB33C200A5; Thu, 23 Jan 2020 07:03:47 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.26 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:20324 Archived-At: Hiya everybody! I have spent some time implementing efficient for loops for guile, and t= hey are baked and ready to go. I have worked the last weeks at implement= ing generalized support for non-tail-recursive loops and am happy to ann= ounce for/foldr. It is a generic right fold, with support for delaying i= t's arguments as either thunks or promises.=20 The syntax is more or less the same as racket's loops, and they are gene= rally 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)= free of mutation. They are all converted to named lets.=20 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))=20 ;; =3D> ((#\a 1) (#\a 2) (#\b 1) (#\b 2)) There are many more looping constructs, among others:=20 for/sum, for/vector, for/or, for/and, for/first, for/last and a side-eff= ecting 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:=20 https://hg.sr.ht/~bjoli/guile-for-loops A web-friendly documentation can be found here:=20 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