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.user Subject: Announcing the first actually stable release of guile-for-loops Date: Thu, 23 Jan 2020 13:10:46 +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="92252"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Cyrus-JMAP/3.1.7-775-g74f2d12-fmstable-20200121v1 To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Thu Jan 23 15:04:37 2020 Return-path: Envelope-to: guile-user@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 1iud64-000NxL-IQ for guile-user@m.gmane-mx.org; Thu, 23 Jan 2020 15:04:36 +0100 Original-Received: from localhost ([::1]:57622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iud62-0007Mf-Uy for guile-user@m.gmane-mx.org; Thu, 23 Jan 2020 09:04:35 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44248) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iubKH-00089c-KW for guile-user@gnu.org; Thu, 23 Jan 2020 07:11:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iubKG-0005Db-C6 for guile-user@gnu.org; Thu, 23 Jan 2020 07:11:09 -0500 Original-Received: from out2-smtp.messagingengine.com ([66.111.4.26]:52939) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iubKG-0005Ct-4V for guile-user@gnu.org; Thu, 23 Jan 2020 07:11:08 -0500 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id E64B722316 for ; Thu, 23 Jan 2020 07:11:06 -0500 (EST) Original-Received: from imap1 ([10.202.2.51]) by compute1.internal (MEProxy); Thu, 23 Jan 2020 07:11:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.se; h= mime-version:message-id:date:from:to:subject:content-type :content-transfer-encoding; s=fm2; bh=DkodTLrzCzg280h6goTDTaDaiB saXqtIjGAqaMtfkYA=; b=hRk9YsTeL11gZB5WiuQsYBKNOjkar6CQ+mfNiG06AP bQikNiZU4G4alU2OS5eTdupqV3pnfkA5u568XLObRTHvgBIdVberN5Y4PliDmtgS P3VFR0QZLAu9HM8JOYWP6Pe6DsGfKINxl0T/T7ZXUHOb+RjML5MxMP6UCnWfWsfp PFGkI7pstcrnrFSkkT3BJ6UTwet9IpcUVXG2j+X/Za0UFYQvhuTJcphrmlEcwUc2 6FulM1pqIjBcMi8xNHlXKkmnnAGtO6UNL91u5sW5FY8TzNxTrH6FZySfhMvd0zs+ GOGLIFDxwuTGisUuFOEaDQfDwaFlsyFJrBzNh4eqRLfg== 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=ZIKD6zi7MB01X80NzkSbed TKY/cJGoVdzyiWliuyddJlznryZbEZx/YV9QG4/BpSvaQh0AD44snbzT3Xu3FhOn SNYtqM3p4tf89JLNz90efgH2pc18uNF4pvr2kgCfi/B8vXTDazzDYurckeUGFQ6x UIyESrPqYVdi/pGtDJIUlMDbcFSSd9amdkxCROevaeTWlbu2fU5/fG59grpcySmt NPWNO0pbgnbwH/nCZ8/LORAa1ab9D5/b9pJ/4m4CAgNU3qtvLbL/W1LPrEnocGAO GGnQov3AshHhKEtsy0ji/BH/RAuT1BiYwNf5io4pb5ampEmXWHkxnEC4jRE9Yh0g == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrvddvgddvjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepofgfggfkfffhvffutgfgsehtqhertd erreejnecuhfhrohhmpefnihhnuhhspgeujhpnrhhnshhtrghmuceolhhinhhushdrihhn thgvrhhnvghtsehfrghsthhmrghilhdrshgvqeenucffohhmrghinhepshhrrdhhthenuc evlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehlihhnuhhs rdhinhhtvghrnhgvthesfhgrshhtmhgrihhlrdhsvg X-ME-Proxy: Original-Received: by mailuser.nyi.internal (Postfix, from userid 501) id 88ED0C200A4; Thu, 23 Jan 2020 07:11:06 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface x-forwarded-message-id: 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-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:16090 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