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: Re: Fwd: Announcing the first stable release of guile-for-loops Date: Fri, 24 Jan 2020 22:23:43 +0100 Message-ID: <9d853449-2dbd-49ae-b17c-15fa592d4cc0@www.fastmail.com> References: 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="129257"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Cyrus-JMAP/3.1.7-777-gdb93371-fmstable-20200123v1 To: "Stefan Israelsson Tampe" , guile-devel Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Fri Jan 24 22:24:21 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 1iv6RB-000XaH-AP for guile-devel@m.gmane-mx.org; Fri, 24 Jan 2020 22:24:21 +0100 Original-Received: from localhost ([::1]:48188 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iv6RA-0007Et-7Q for guile-devel@m.gmane-mx.org; Fri, 24 Jan 2020 16:24:20 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53322) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iv6Qz-0007Ei-84 for guile-devel@gnu.org; Fri, 24 Jan 2020 16:24:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iv6Qx-0005V5-Ti for guile-devel@gnu.org; Fri, 24 Jan 2020 16:24:09 -0500 Original-Received: from wout5-smtp.messagingengine.com ([64.147.123.21]:50159) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iv6Qx-0005RB-Gh for guile-devel@gnu.org; Fri, 24 Jan 2020 16:24:07 -0500 Original-Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 42582861; Fri, 24 Jan 2020 16:24:05 -0500 (EST) Original-Received: from imap1 ([10.202.2.51]) by compute3.internal (MEProxy); Fri, 24 Jan 2020 16:24:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=veryfast.biz; h= mime-version:message-id:in-reply-to:references:date:from:to :subject:content-type:content-transfer-encoding; s=fm1; bh=Omxwx IZ0piXRgEzs+Ns10lFHMIK3zh8/pqFR63NE36w=; b=NwdQB0ufZNCaQ5G3kIkeI eGU7kOxmCeb6QXv7WznfJ5iuSR2vwVajI81bnCUbe8WTqc4Z98EJGV98dhi6o6tv 6qw6DtRWsTGIaeDD2X4BPa/yiPINGt6FwcSqGQjvyDJnfFgLMZySAg/p1L2coKdm 9P3FSMjrrFbF+/UnPfSyOQDxUgn5T8LMwqXHTAhxBZMR/bNw1wbepq4HVcBkjdiK JIO5p59rShTV9hlSAPe/rmUR/lyUvi4qMabtStOelHnaVNp2KvgIYmmHSPdBNn1+ IOr6WbsnJO7xd55pv1H9/ynpsGb+nYh7giKlonFeEeEwotvwOAKf0upo8RvP4PKP A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=OmxwxIZ0piXRgEzs+Ns10lFHMIK3zh8/pqFR63NE3 6w=; b=PnXnHBF8Ya5g9HZyRPbLzr1MyT0tUczyX+Syflz6Dy7aRqgZvRe4C9ADT eYjnmr0QlNBElxOphxL/NQCxOlSOnZGShmLouXRC1XGTSsEDlUhSZ6kWxgzCXMAy 53LBEjtjBIz3FVZj1uRBd2pmTbpKj/yvHlbKDqCFYW+5h0FLq0IA3pk1mroM8dg/ afR4rlry2hZ4h3tBLCGxB/XAuDDzmXJ/Po3butADaw+hn6rjZ4zo9m6cvKme2VVR 1NWGyiyAOKJTmpQyfhvGPvtKnlLKrA3zJ1fGPQ0qr1OzlSbOWGq9cBi/pPTibnDj mQ4CGT7MemDtz/VJ18dk/M/kx4atg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrvdehgddugecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepnfhinhhu shgpuehjnphrnhhsthgrmhcuoehlihhnuhhsrdgsjhhorhhnshhtrghmsehvvghrhihfrg hsthdrsghiiieqnecuffhomhgrihhnpehsrhdrhhhtnecuvehluhhsthgvrhfuihiivgep tdenucfrrghrrghmpehmrghilhhfrhhomheplhhinhhushdrsghjohhrnhhsthgrmhesvh gvrhihfhgrshhtrdgsihii X-ME-Proxy: Original-Received: by mailuser.nyi.internal (Postfix, from userid 501) id AAA1AC200A3; Fri, 24 Jan 2020 16:24:04 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 64.147.123.21 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:20330 Archived-At: Yeah, when iterating through many different things at the same time it i= s extremely helpful.=20 I would have loved syntax parse when writing the macros :) I read your f= or loops code in awe, at least until I saw how you "cheated" with set! := -P My only chance of getting it into guile proper would be to 1. Make a SRF= I and survive the SRFI process with my honour intact and 2. Code cleanup= . Most of for/emit is OKish, but for/foldr needs to be beaten with a sti= ck, burnt and rewritten. "bending hygiene" doesn't quite cover what I di= d to make it work. In the end I sort of kind of worked around it by maki= ng an API change, but it still stinks. Defining a new loop using for/fol= dr involves having to do a syntax->datum->syntax. No fun. I could check = how racket does it, but given they can do syntax-local-introduce (which = is specific to their "hygiene as sets of scopes") I suspect I am out of = luck.=20 V=C3=A4l m=C3=B6tt Linus Bj=C3=B6rnstam On Fri, 24 Jan 2020, at 13:13, Stefan Israelsson Tampe wrote: >=20 >=20 > ---------- 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 >=20 >=20 > Would be cool to have those implemented in guile, that would make my=20= > guile-syntax-parse a bit leaner >=20 > Regards > Stefan >=20 > On Thu, Jan 23, 2020 at 3:03 PM Linus Bj=C3=B6rnstam=20 > wrote: > > Hiya everybody! > >=20 > > 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 impl= ementing generalized support for non-tail-recursive loops and am happy t= o announce for/foldr. It is a generic right fold, with support for delay= ing it's arguments as either thunks or promises.=20 > >=20 > > 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 fas= t as hand-rolled code. They are all expressed as left or right folds, an= d are as such (apart from for/list, but read about that in the documenta= tion) free of mutation. They are all converted to named lets.=20 > >=20 > > Some examples: > >=20 > > (for/list ((a (in-range 1 6))) > > (* a a)) ;; =3D> (1 4 9 16 25) > >=20 > > (for*/list ((a (in-string "ab")) (b (in-range 1 3))) > > (list a b))=20 > > ;; =3D> ((#\a 1) (#\a 2) (#\b 1) (#\b 2)) > >=20 > > There are many more looping constructs, among others:=20 > > for/sum, for/vector, for/or, for/and, for/first, for/last and a sid= e-effecting simple for. > >=20 > > Here is a sieve of erathostenes: > >=20 > > (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)) > >=20 > > The code and documentation is available here:=20 > > https://hg.sr.ht/~bjoli/guile-for-loops > >=20 > > A web-friendly documentation can be found here:=20 > > https://man.sr.ht/%7Ebjoli/for-loops-docs/for-loops.md > >=20 > > The thing I had been waiting for is right fold. That allows us to w= rite loops like guile's map: non-tail recursive: > > (for/foldr ((identity '())) ((a (in-list '(1 2 3)))) > > (cons (* a a) identity)) > >=20 > > becomes equivalent to: > >=20 > > (let loop ((random-identifier '(1 2 3))) > > (if (null? random-identifier) > > '() > > (let ((a (car random-identifier))) > > (cons (* a a) (loop (cdr random-identifier)))))) > >=20 > > Happy hacking > > Linus Bj=C3=B6rnstam > >