From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/30727 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: BPJ Newsgroups: gmane.text.pandoc Subject: Re: Walk and deep copy in Lua filters Date: Sun, 12 Jun 2022 20:00:13 +0200 Message-ID: References: Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000002e290005e143f241" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16826"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCWMVYEK54FRBO6TTCKQMGQEOYOACZQ-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Sun Jun 12 20:00:31 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-ej1-f59.google.com ([209.85.218.59]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1o0Rt0-0004EH-W5 for gtp-pandoc-discuss@m.gmane-mx.org; Sun, 12 Jun 2022 20:00:31 +0200 Original-Received: by mail-ej1-f59.google.com with SMTP id mb1-20020a170906eb0100b00710c3b46a9asf939192ejb.22 for ; Sun, 12 Jun 2022 11:00:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1655056830; cv=pass; d=google.com; s=arc-20160816; b=KumaN9Z06yphUV1eEeBvxXnN+cF9fyAnVaqmWtgQZLDoV8W4f/alXHrU0k+HZ5CVcV sZH1s1sG8Xr0ru6WxJGKQZmjpO2BFLBEh0QWgv90W8kWNBRFSc4PtsEx1mmwdbs2kxou LOwBN0OS1euZIlkAjrML6OoGNiSeAoj8tKLB6TQUuWMj+K8BXwjq2rzmySbAEo9e2FiI 2UsBoWi/larekomVPTCYdBXXaq4LCdGwP8OkdV7e+ps13IrgwJpC6X9OL/9qCL1tfhD/ o+DhgMJADtDviJxLai8LBvYSxNb9sApkSS1udy9t9GiTI9aje6pJaJq+FAvYK16T2BRk qajw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:to:subject:message-id:date :from:in-reply-to:references:mime-version:sender:dkim-signature :dkim-signature; bh=/V+8zR8kgL30/SvXO6rJk4gPv6iRSWXNdW+yIP8dkp0=; b=xEPZdJLMV6MsdFVqbrn5FUjvyDLjKOdo+xFbD+vMMxp+O+GxP8/39c1NA7/EnoNxYL Y0cHDC99QoaneMvfOjp/053lqnwnioAIKutwd4T+xzgeVaVbEoIscQAxA5UlBnCmEZGC xo6Dij22yVlc6EXd0DFm1HThNmYR6XP8N58Uv1+SzEnHRQuB5rHkVmzK8TCkWIdFpNdR lqj630PB7kvgsehFJM1WVYeZ2+Ixu948G1PPBeDG2hu3XKzsZBemw/DKCF/57/L2cFbr frBu/O26PL265R3zeieRvrvoa3YxtPZdimjKXn2+F1eGrLCJNrvi0HrqaH3hUKLS4ZSJ i1Hg== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=LXJ9KRGA; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::62c as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:mime-version:references:in-reply-to:from:date:message-id :subject:to:x-original-sender:x-original-authentication-results :reply-to:precedence:mailing-list:list-id:list-post:list-help :list-archive:list-subscribe:list-unsubscribe; bh=/V+8zR8kgL30/SvXO6rJk4gPv6iRSWXNdW+yIP8dkp0=; b=i5dhMlOuh9FKw191TYSlBRN5iduEACKEvbQ8Z5aoW3tFZI4x2H9vkMCaMFxAH6Vo6W jRevEOEbi68vysDALvp2S+OJ7E9QWdct4e2WFFig427RaXDva1+nYzSMIkoQuDNzO48L nM5wPQhiAP7WXqMKDI8melnk218KyimdVP+stLXrDVv29ROMF4qveZaE5PQU5bNUa9iU ZfdYcX02SoE78WxczxmkiMimYDbTZNKmBLX/Nv+JTjqjbZaYJwIQRy/RaoI1xHLOZKB2 L739OIDtIx3GSHpe/BaTj91YRfXdyHjl4zA2Hg97IHxbArMbK7EPeYUwVOg75rGmmBXh 2qCg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :x-original-sender:x-original-authentication-results:reply-to :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=/V+8zR8kgL30/SvXO6rJk4gPv6iRSWXNdW+yIP8dkp0=; b=Dc4B3Zd6heEUK0+oDO4UOPyxLpI6eGw3tvKL2hbhtYWuz9W3vMTbtdms6cNXOy1i7v KgC5vnlBKTac5GtrWV8oJzgrCUDhuoZHuQ9dFB7QQUwqbV5pggIHVOhFvFa6OliV+NKA QgL8PSSTI/jLKzJWVs9pxkuNbBDwK6k4aJGhd62yABz+alxtGLs/pYyd82/NzNZtt0+Q XG4qQMLo02856kLeSva0NIMQz1BNvI1uMmHPS+Pkn2Vu7RUsZBFAoPJ8hWa7jKrNXjkg LEDsNy6j7NFcSm1iazKYaw+zpuuJ27e/YTUmE/hLoFvD6K5wdwFuC2buYqqBNGvFLrYZ Cr3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:mime-version:references:in-reply-to:from :date:message-id:subject:to:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=/V+8zR8kgL30/SvXO6rJk4gPv6iRSWXNdW+yIP8dkp0=; b=Pw+5wiJyYcspYKz2BLHDHiJyG2OvKQgjonGfAyi23ofSvsSEwANwKPu0hgD4l+JfC4 zIjmhAQIYniix2Rt+Ua3T2t/n7eBoFObWcX5Vd2NQF5W52hJuUkSfwCmOvp1PpeqiZkg Pk5CkNwJVFI4EEOBvjzQIv1UtGGVirbeupQzG0x4xs3KcTz87U3Qjzy6G705Kotpjx+6 J8TdWD8jWD7ev3IBu6ERKdyD5WkSwaOgLz0LBr+eWQH2aPE0Hf4UiFKJTPIlwfctKGdN rGu+suPZiS62IIOyyqAGc63WRyPPtAFVgJ6PX0WAo4sIs++yzQM26BhQegXpBSZMjIJf NeXw== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM531KG7IbT/l7i5/ZKS4AGPxYiIg+hXUSr+zeMXDBzcx0G0rpjm1g xTvuwM1plYNKG2dgevBdC84= X-Google-Smtp-Source: ABdhPJxEXjzrKMkwkgT8zCV7j5Z3Vtd+zpfCcee5WcNu+rzBuQzyMA+HVbkPqO+hKglIgeBhsFzcEw== X-Received: by 2002:aa7:d456:0:b0:42d:d7d9:34c1 with SMTP id q22-20020aa7d456000000b0042dd7d934c1mr61997864edr.21.1655056830586; Sun, 12 Jun 2022 11:00:30 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a17:907:9705:b0:70d:ff46:7086 with SMTP id jg5-20020a170907970500b0070dff467086ls850105ejc.4.gmail; Sun, 12 Jun 2022 11:00:26 -0700 (PDT) X-Received: by 2002:a17:907:ea7:b0:70f:a27a:dac0 with SMTP id ho39-20020a1709070ea700b0070fa27adac0mr42532110ejc.25.1655056826122; Sun, 12 Jun 2022 11:00:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655056826; cv=none; d=google.com; s=arc-20160816; b=Uw9Y4MmQfgKYF06uX3t+HPWgN0gw2OguzCXnNxg9sq8u2cCWZKgcw4J8eomorOPzZR ttwKQjQC3JnCABLk4S9A/7IzrxK4DPQZRYJO479wCt954Es1PQ7cG/U+TcJZZMpD4qbf Fc+1bNGMheW1aUCh25i2jvCj4tvrvxmCoiMAfBm+HP6I/PxW/qPYl+6Hmx7YBhyF6hNt 65reqMZB+GMVrNLRDC0pnTGUojORN2/coAlja9LS4M50h5FQJZIDMu7hzLfY2Rx9GAHX kb+T0ZanSvl7G/Abp80RPin8SsPjwe1LDBzW88OZDSCon/XvJtoDqJD2rUoh7QGyrXtJ L96Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=f9KTGC12r04/fcBhm8vQD00g6548jVWjADJRSqafwfc=; b=QqrDmnvdfpAv24rmZ5tOhOAbFPDYjy1B7bpwU55/bLDxzTCzood2C2PKFA0+ECYnQ9 GXa0YzTAzP+mi7PECkmeY9gevQa75aOpmozi33UL8ggzkOKnG9CLNzqlPDHrwlDDjt6l C978g7j4U5tVdnlatv1ZRwesZtfigM17AO4oDEM7KcQrE6i6JBjxCMQT5rGCtGaMmhxM OiJR0yeJzHFjrXLk2xsut6bvFNj0lEtKkaz1FIROlXMsBkCz1FAYku8NW2Okw7KkH2Y6 Kepnp8QhZa4QVZmC2rnRdd2fFKaEGHqiLIbayqmW/RMZ5MCQc9i/TThtwwn/wbRwfkjX VYwQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=LXJ9KRGA; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::62c as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Original-Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com. [2a00:1450:4864:20::62c]) by gmr-mx.google.com with ESMTPS id sd14-20020a170906ce2e00b006fefa121de4si132280ejb.1.2022.06.12.11.00.26 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Jun 2022 11:00:26 -0700 (PDT) Received-SPF: pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::62c as permitted sender) client-ip=2a00:1450:4864:20::62c; Original-Received: by mail-ej1-x62c.google.com with SMTP id v1so7046857ejg.13 for ; Sun, 12 Jun 2022 11:00:26 -0700 (PDT) X-Received: by 2002:a17:907:62a6:b0:6ef:8118:d3e2 with SMTP id nd38-20020a17090762a600b006ef8118d3e2mr49146079ejc.605.1655056825722; Sun, 12 Jun 2022 11:00:25 -0700 (PDT) In-Reply-To: X-Original-Sender: melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=LXJ9KRGA; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::62c as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Precedence: list Mailing-list: list pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org; contact pandoc-discuss+owners-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-ID: X-Google-Group-Id: 1007024079513 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Xref: news.gmane.io gmane.text.pandoc:30727 Archived-At: --0000000000002e290005e143f241 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Why not use the clone method to get a copy? That said I like that walk modifies a copy. The only builtin Lua function which alters its argument in place I can think of OTTOMH is table.sort, which is a gotcha because strings are immutable so I always forget that table.sort modifies in place. Den s=C3=B6n 12 juni 2022 13:18Bastien DUMONT s= krev: > Hi all, > > I just discovered by chance that the method walk returns a deep copy of > the passed object, leaving the original object untouched. See the followi= ng > test case: > > ```deep-copy.lua > local orig =3D pandoc.Emph({ pandoc.Str('one'), pandoc.Space(), > pandoc.Str('two') }) > local copy =3D orig:walk({}) > table.insert(copy.content, pandoc.Space()) > table.insert(copy.content, pandoc.Str('three')) > assert(#orig.content =3D=3D 3) > assert(#copy.content =3D=3D 5) > ``` > `pandoc -L deep-copy.lua <<< ''` should return nothing (i.e. no error). > > However, in the documentation, it is only stated that the =E2=80=9CResult= =E2=80=9D is the > =E2=80=9Cfiltered block/inline element=E2=80=9D: from this indication alo= ne, it seems not > obvious to me whether the passed object is changed (as it is customary wi= th > functions operating on Lua tables or userdata) or the method returns a ne= w > object. > > To be clear, I am very happy with the current behaviour, for it gives a > very simple means to get several deep copies of an objet and to manipulat= e > them separately without having to regenerate the original object (e.g. vi= a > rather expensive calls to `pandoc.read()`). Nevertheless, since it is not > really documented, can it be considered to be deliberate and stable? If > this is the case, could it be possible to make explicit in the > documentation, under the header =E2=80=9CResult=E2=80=9D, that the origin= al block or inline > element is left unchanged? > > -- > You received this message because you are subscribed to the Google Groups > "pandoc-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msgid/pandoc-discuss/YqXK0Gyv%2B18RwQd1%40loc= alhost > . > --=20 You received this message because you are subscribed to the Google Groups "= pandoc-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an e= mail to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/= pandoc-discuss/CADAJKhA9JY8Xm0X6SFe_2E8DBCwcdtSctuMgKWn2EoYC4gQyCQ%40mail.g= mail.com. --0000000000002e290005e143f241 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Why not use the clone method to get a copy? That said I l= ike that walk modifies a copy.

The only builtin Lua function which alters its argument in place I can thi= nk of OTTOMH is table.sort, which is a gotcha because strings are immutable= so I always forget that table.sort modifies in place.

Den s=C3=B6n 12= juni 2022 13:18Bastien DUMONT <bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org> skrev:
Hi all,

I just discovered by chance that the method walk returns a deep copy of the= passed object, leaving the original object untouched. See the following te= st case:

```deep-copy.lua
local orig =3D pandoc.Emph({ pandoc.Str('one'), pandoc.Space(), pan= doc.Str('two') })
local copy =3D orig:walk({})
table.insert(copy.content, pandoc.Space())
table.insert(copy.content, pandoc.Str('three'))
assert(#orig.content =3D=3D 3)
assert(#copy.content =3D=3D 5)
```
`pandoc -L deep-copy.lua <<< ''` should return nothing (i.= e. no error).

However, in the documentation, it is only stated that the =E2=80=9CResult= =E2=80=9D is the =E2=80=9Cfiltered block/inline element=E2=80=9D: from this= indication alone, it seems not obvious to me whether the passed object is = changed (as it is customary with functions operating on Lua tables or userd= ata) or the method returns a new object.

To be clear, I am very happy with the current behaviour, for it gives a ver= y simple means to get several deep copies of an objet and to manipulate the= m separately without having to regenerate the original object (e.g. via rat= her expensive calls to `pandoc.read()`). Nevertheless, since it is not real= ly documented, can it be considered to be deliberate and stable? If this is= the case, could it be possible to make explicit in the documentation, unde= r the header =E2=80=9CResult=E2=80=9D, that the original block or inline el= ement is left unchanged?

--
You received this message because you are subscribed to the Google Groups &= quot;pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to pandoc-discuss+unsubscribe@googlegroups.= com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-dis= cuss/YqXK0Gyv%2B18RwQd1%40localhost.

--
You received this message because you are subscribed to the Google Groups &= quot;pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to pand= oc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.= google.com/d/msgid/pandoc-discuss/CADAJKhA9JY8Xm0X6SFe_2E8DBCwcdtSctuMgKWn2= EoYC4gQyCQ%40mail.gmail.com.
--0000000000002e290005e143f241--