From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Damien Mattei Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] Extensions for SRFI-171 (Transducers) Date: Thu, 22 Dec 2022 18:32:55 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000d972e805f06e0f55" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38418"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Thu Dec 22 18:33:46 2022 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 1p8PRx-0009lr-EJ for guile-devel@m.gmane-mx.org; Thu, 22 Dec 2022 18:33:45 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p8PRc-00046D-RO; Thu, 22 Dec 2022 12:33:24 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p8PRO-00043W-NE for guile-devel@gnu.org; Thu, 22 Dec 2022 12:33:18 -0500 Original-Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p8PRM-0006XN-Dp for guile-devel@gnu.org; Thu, 22 Dec 2022 12:33:10 -0500 Original-Received: by mail-ej1-x634.google.com with SMTP id u19so6512899ejm.8 for ; Thu, 22 Dec 2022 09:33:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=44AN2m+xMIpsHipVrxO9NYQQO0OqyT/zokxsGWG9J/4=; b=AQ42coGT+0q2tEPRSmtlTJ95SsCc92g4ccuWzsrYiNvZKe6Xn02AwNs1Jl0wq9JXt4 2z8MsIe8U3e2L7CFiBoopMCZkmPXuLh+h8gxzKL3UyBtn7FtFETAk26NiibEkwsiQ6I9 RflZ9SxmpUKmFLomOvRLuCpEF8eNfqQOt15QjoYvjRtZUoFz4gkDA9FKvxgmrHVC6e/R HYoZ975XmUfmgGwdG7/Dgs4ia1z58NMVBVdK3qrwuvaTYG9wCHwOb3nmw80NsXGjg54N clTEGcwl8DTqRKV1+SwPb6Qxi2NTJnhcAeC43ERxJ3tOFfh9cBG9DCC1Gsrq5iNsBPyP gDKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=44AN2m+xMIpsHipVrxO9NYQQO0OqyT/zokxsGWG9J/4=; b=wBmXbEq7U7W+m7x12f1DwUgU+WCOv7BApFoHAbNRAaNPII9u8V4tllntYs1RwYJcKl FydbNEqHkDoTmUa6sRP43kdow8cljX6MvhwWHhaLvtCvNLRJ4RdqefZ3pP2DncECIx8U v/PxhFCWCyIv8za7pdaTxNikd/N2FnZmuuO3ToyWNdL9RxbcWN1hwNxoyp7IWAMyTHBV sQnXAYAkbFzNFEKBraavhwpjHyi0BjtKkKcD+5Do4yHnX/HeYpDmYv6SQvZRgRVDbLER 7B3XrBVtMWTMN1jG7v04fHsk903+Ab7WLDpcRmFOxuhguFMu4tR7U1ML7VeOgzeTXwcZ La1Q== X-Gm-Message-State: AFqh2kpDZ1qagWVBpGAH1cu5jre9h+8pgLzGb+c1/ywPji2mR1bpIqSD 5f50pa8BcL4zIgtWDswEKuYMnuSExjEe6npPsF2xydmkD1sp+A== X-Google-Smtp-Source: AMrXdXumvucHJXOUZpA6VPR/W4mRAlZLvUDKZDiA0W3IHpt2mklPoDiuNB8SVFEgmsTcKOmJfyNB8jnQEIiNlNC+AZg= X-Received: by 2002:a17:906:f857:b0:835:57c9:6424 with SMTP id ks23-20020a170906f85700b0083557c96424mr837274ejb.529.1671730386530; Thu, 22 Dec 2022 09:33:06 -0800 (PST) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::634; envelope-from=damien.mattei@gmail.com; helo=mail-ej1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 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-bounces+guile-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.devel:21519 Archived-At: --000000000000d972e805f06e0f55 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable i'm interested with transducers to speed up code: ;; 8'21" MacOS Ventura M1 {unified-minterms-set-2 <+ (filter (=CE=BB (x) x) unified-minterms-set-1)= } ;; remove #f results (nodebug {unified-minterms-set-2-length <+ (length unified-minterms-set-2)} (dv unified-minterms-set-2-length)) {unified-minterms-set <+ (remove-duplicates unified-minterms-set-2)} ;;(remove-duplicates-sorted unified-minterms-set-2)} ;; uniq MODIF (nodebug {unified-minterms-set-uniq-length <+ (length unified-minterms-set)} (dv unified-minterms-set-uniq-length)) with transducers: ;; 7'08" MacOS Ventura M1 {unified-minterms-set <+ (list-transduce (compose (tfilter (=CE=BB (x) x)= ) (tdelete-duplicates)) rcons unified-minterms-set-1)} it is an interesting 15% speed up in my code. On Thu, Dec 22, 2022 at 3:52 PM Damien Mattei wrote: > i just understood the scheme :-) > > scheme@(guile-user)> (list-transduce (compose (tfilter (=CE=BB (x) x)) > (tdelete-duplicates)) rcons (list 1 2 #f 3 3 4)) > $12 =3D (1 2 3 4) > > sorry... > > > On Thu, Dec 22, 2022 at 3:33 PM Damien Mattei > wrote: > >> hello, >> just trying transducers before using it, i try to understand. >> what is wrong with that: >> scheme@(guile-user)> (list-transduce (tfilter (=CE=BB (x) x)) >> (tdelete-duplicates) (list 1 2 #f 3 3 4)) >> ice-9/boot-9.scm:1685:16: In procedure raise-exception: >> Wrong number of arguments to #> srfi/srfi-171.scm:338:2 (reducer)> >> >> Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. >> >> Regards, >> Damien >> >> On Wed, Dec 21, 2022 at 11:01 AM Linus Bj=C3=B6rnstam < >> linus.bjornstam@veryfast.biz> wrote: >> >>> As the author of both the SRFI and the guile code I am very happy you >>> like it. I don't have a computer at the moment, but I looked through th= e >>> code and it looked great. >>> >>> All additions should have been included in the original SRFI :) >>> >>> one comment: your code uses define-public, which the rest of SRFI-171 >>> code does not. >>> >>> I am not in any position to sign code off for inclusion in guile proper= , >>> but if the define-public thing is fixed it very much has my blessing. >>> >>> Best regards >>> Linus Bj=C3=B6rnstam >>> >>> On Wed, 21 Dec 2022, at 01:48, Colin Woodbury wrote: >>> > Happy holidays everyone, I hope everything is going well for you. >>> > >>> > Since discovering SRFI-171 (Transducers) I have fallen in love with >>> it. >>> > Transducers let me "talk the way I want to talk" while knowing that >>> I'm >>> > being efficient underneath w.r.t. to iteration and allocation. In >>> using >>> > Guile's implementation, I noticed a few common idioms missing that ar= e >>> > otherwise present in other languages, so I've added them in a series >>> of >>> > patches. I've been using these often for a number of weeks without >>> > issue, but of course have added unit tests as well. >>> > >>> > The full details are in the commit messages, but here are the main >>> highlights: >>> > >>> > * rfold: The fundamental reducer. This allows the user to turn any >>> > two-arg function into a valid reducer, so that they don't need to >>> worry >>> > about hand-writing reducers via case-lambda. >>> > * rfind: Yields the first item in the transduction that matches some >>> > predicate. Nice for locating some specific value from a potentially >>> > large data source (e.g. a port). >>> > * twindow: Like tsegment, but yields overlapping slices into the >>> data. >>> > Cheers, and have a great holiday. >>> > >>> > Colin >>> > >>> > Attachments: >>> > * 0001-srfi-171-add-twindow-and-various-reducers.patch >>> > * 0002-doc-add-new-SRFI-171-reducers-to-the-manual.patch >>> > * 0003-srfi-171-add-unit-tests-for-new-functions.patch >>> >>> --000000000000d972e805f06e0f55 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
i&#= 39;m interested with transducers to speed up code:

;; 8'21" MacOS Ventura M1
=C2=A0 {uni= fied-minterms-set-2 <+ (filter (=CE=BB (x) x) unified-minterms-set-1)} ;= ; remove #f results
=C2=A0 (nodebug
=C2=A0 =C2=A0{unified-minterms-se= t-2-length <+ (length unified-minterms-set-2)}
=C2=A0 =C2=A0(dv unifi= ed-minterms-set-2-length))

=C2=A0 {unified-minterms-set <+ (remov= e-duplicates unified-minterms-set-2)} ;;(remove-duplicates-sorted unified-m= interms-set-2)} ;; uniq MODIF
=C2=A0 (nodebug
=C2=A0 =C2=A0{unified-m= interms-set-uniq-length <+ (length unified-minterms-set)}
=C2=A0 =C2= =A0(dv unified-minterms-set-uniq-length))

with transducers:
;; 7'08" MacOS Ventura M1
=C2=A0 {unified-= minterms-set <+ (list-transduce (compose (tfilter (=CE=BB (x) x)) (tdele= te-duplicates)) rcons unified-minterms-set-1)}

it is an interesting 15% speed up in my code.


On Thu, Dec = 22, 2022 at 3:52 PM Damien Mattei <damien.mattei@gmail.com> wrote:
i just understood the scheme :-)

scheme@(guile-user)> (list-transduce = (compose (tfilter (=CE=BB (x) x)) (tdelete-duplicates)) rcons (list 1 2 #f = 3 3 4))
$12 =3D (1 2 3 4)

sorry...

On Thu, Dec 22, 2022 at 3:33 PM Damien Mattei <damien.mattei@gmail.com>= wrote:
hello,
=
just trying tr= ansducers before using it, i try to understand.
what is wrong with that:
scheme@(guile-user)> (list-= transduce (tfilter (=CE=BB (x) x)) (tdelete-duplicates) (list 1 2 #f 3 3 4)= )
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
Wrong numbe= r of arguments to #<procedure 10786aa60 at srfi/srfi-171.scm:338:2 (redu= cer)>

Entering a new prompt.=C2=A0 Type `,bt' for a backtrace= or `,q' to continue.

Regards,
Damie= n

On Wed, Dec 21, 2022 at 11:01 AM Linus Bj=C3=B6rnstam <linus.bjornstam= @veryfast.biz> wrote:
As the author of both the SRFI and the guile code I am very ha= ppy you like it. I don't have a computer at the moment, but I looked th= rough the code and it looked great.

All additions should have been included in the original SRFI :)

one comment: your code uses define-public, which the rest of SRFI-171 code = does not.

I am not in any position to sign code off for inclusion in guile proper, bu= t if the define-public thing is fixed it very much has my blessing.

Best regards
=C2=A0 Linus Bj=C3=B6rnstam

On Wed, 21 Dec 2022, at 01:48, Colin Woodbury wrote:
> Happy holidays everyone, I hope everything is going well for you.
>
> Since discovering SRFI-171 (Transducers) I have fallen in love with it= .
> Transducers let me "talk the way I want to talk" while knowi= ng that I'm
> being efficient underneath w.r.t. to iteration and allocation. In usin= g
> Guile's implementation, I noticed a few common idioms missing that= are
> otherwise present in other languages, so I've added them in a seri= es of
> patches. I've been using these often for a number of weeks without=
> issue, but of course have added unit tests as well.
>
> The full details are in the commit messages, but here are the main hig= hlights:
>
>=C2=A0 * rfold: The fundamental reducer. This allows the user to turn a= ny
> two-arg function into a valid reducer, so that they don't need to = worry
> about hand-writing reducers via case-lambda.
>=C2=A0 * rfind: Yields the first item in the transduction that matches = some
> predicate. Nice for locating some specific value from a potentially > large data source (e.g. a port).
>=C2=A0 * twindow: Like tsegment, but yields overlapping slices into the= data.
> Cheers, and have a great holiday.
>
> Colin
>
> Attachments:
> * 0001-srfi-171-add-twindow-and-various-reducers.patch
> * 0002-doc-add-new-SRFI-171-reducers-to-the-manual.patch
> * 0003-srfi-171-add-unit-tests-for-new-functions.patch

--000000000000d972e805f06e0f55--