From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/115863 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: BPJ via ntg-context Newsgroups: gmane.comp.tex.context Subject: Re: Merging two lua tables Date: Tue, 30 Aug 2022 10:56:19 +0200 Message-ID: References: Reply-To: bpj@melroch.se, mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============5064372889091084510==" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22094"; mail-complaints-to="usenet@ciao.gmane.io" Cc: BPJ To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Tue Aug 30 10:57:30 2022 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oSx3p-0005Xh-Je for gctc-ntg-context-518@m.gmane-mx.org; Tue, 30 Aug 2022 10:57:29 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 4AD80360977; Tue, 30 Aug 2022 10:56:52 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ejbgGYQSosbX; Tue, 30 Aug 2022 10:56:50 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 21D36360972; Tue, 30 Aug 2022 10:56:50 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 54A0636095D for ; Tue, 30 Aug 2022 10:56:31 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id D3VXpe4v6GPm for ; Tue, 30 Aug 2022 10:56:30 +0200 (CEST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.218.47; helo=mail-ej1-f47.google.com; envelope-from=melroch@gmail.com; receiver= Original-Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id E328736089F for ; Tue, 30 Aug 2022 10:56:29 +0200 (CEST) Original-Received: by mail-ej1-f47.google.com with SMTP id cu2so20796755ejb.0 for ; Tue, 30 Aug 2022 01:56:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:reply-to:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=bI8gmb8oMDubx5Fg71XwGa3SRzAw85VYACPj7+SeBCQ=; b=rzfMY6DwFPbcqIQhmVm3cDaigNRa66krDU9ZnoMSEvU2QytTqNvD4tJJKegpU6mEsw s59MoD8t0JqgiOpIBfLqhZ8Q8Xlvx3Uru9WkW7l4d0oLjcd5se7jkWXTkQODHQHbpCf1 2AhVLi98wA5yHFBvutXgp1/MCW5ma6PjM4ppWLF0UZ4BMoTP4W6s+E7bXK7O4XozVJFm SRc4YD7t6dSJcKyvEaVVJenQIMrv0LnTipdCylv3VqVZNAy2Vg04g3JjiI+TjWq9bFDx VKeajytW+M/E6IDTdKRZQJVuD7HwAXfnJnfz+cIuGONrGfrInRypfoOeseKbbhlkyd9A /p1A== X-Gm-Message-State: ACgBeo3Indsumi0UhLD5vsrfm4IKrCLazDm5V0oHA6xZHOGDIqPQDa72 UvxwSRmMB9m4fz7wXrIPC6GjvH5B9WOQ4de2b8R0vo+y X-Google-Smtp-Source: AA6agR4RrlpeXGyFjxUZv2ZCF+E/hOKv/UbGgq4qGnDADjUn9b9NTlYQQMtIDBe+lvHH/0lUcuUib2dmTZ1Rop4FTw8= X-Received: by 2002:a17:907:781a:b0:730:ccea:7c29 with SMTP id la26-20020a170907781a00b00730ccea7c29mr16211262ejc.85.1661849788853; Tue, 30 Aug 2022 01:56:28 -0700 (PDT) In-Reply-To: X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:115863 Archived-At: --===============5064372889091084510== Content-Type: multipart/alternative; boundary="00000000000055b19505e7718e78" --00000000000055b19505e7718e78 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Den m=C3=A5n 29 aug. 2022 20:13Hans Hagen via ntg-context skrev: > On 8/29/2022 7:33 PM, BPJ via ntg-context wrote: > > Hi, > > > > I use the attached Lua function to merge array, map and mixed tables > alike > > (but differently! :-) The trick is to check if each key is numeric or > not, > > append if it is and overwrite if it isn't. > > you really want something like this then: > > local tab =3D table.pack(...) > local rv =3D {} > Thanks. I was manually translating from MoonScript (https://moonscript.org) where variables are local by default. > > This function just ignores non-table arguments because that is what I > > usually want. You may want to throw an error instead. Also it uses > > table.pack. You might need to use `tab =3D {...}` and ipairs, or implem= ent > > pack: > I might add table.himerged (hash and index) but slightly different (and > some 30% faster) to util-tab but i think merging mixed hash/indexed > tables is rare. > > Hans > > ----------------------------------------------------------------- > Hans Hagen | PRAGMA ADE > Ridderstraat 27 | 8061 GH Hasselt | The Netherlands > tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl > ----------------------------------------------------------------- > > _________________________________________________________________________= __________ > If your question is of interest to others as well, please add an entry to > the Wiki! > > maillist : ntg-context@ntg.nl / > https://www.ntg.nl/mailman/listinfo/ntg-context > webpage : https://www.pragma-ade.nl / http://context.aanhet.net > archive : https://bitbucket.org/phg/context-mirror/commits/ > wiki : https://contextgarden.net > > _________________________________________________________________________= __________ > --00000000000055b19505e7718e78 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


Den m=C3=A5n 29 aug. 2022 20:13Hans Hagen via ntg-cont= ext <ntg-context@ntg.nl> sk= rev:
On 8/29/2022 7:33 PM, BPJ via = ntg-context wrote:
> Hi,
>
> I use the attached Lua function to merge array, map and mixed tables a= like
> (but differently! :-) The trick is to check if each key is numeric or = not,
> append if it is and overwrite if it isn't.

you really want something like this then:

local=C2=A0 tab =3D table.pack(...)
local=C2=A0 rv=C2=A0 =3D {}
<= br>
Thanks. I was manually translating from MoonScri= pt (https://moonscript.org) where va= riables are local by default.


> This function just ignores non-table arguments because that is what I<= br> > usually want. You may want to throw an error instead. Also it uses
> table.pack. You might need to use `tab =3D {...}` and ipairs, or imple= ment
> pack:
I might add table.himerged (hash and index) but slightly different (and some 30% faster) to util-tab but i think merging mixed hash/indexed
tables is rare.

Hans

-----------------------------------------------------------------
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0Hans Hagen | PRAGMA ADE
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Ridderstraat 27 | 80= 61 GH Hasselt | The Netherlands
=C2=A0 =C2=A0 =C2=A0 =C2=A0 tel: 038 477 53 69 | www.pragma-ade.n= l | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________= ________
If your question is of interest to others as well, please add an entry to t= he Wiki!

maillist : ntg-context@ntg.nl / https:= //www.ntg.nl/mailman/listinfo/ntg-context
webpage=C2=A0 : https://www.pragma-ade.nl / http:= //context.aanhet.net
archive=C2=A0 : https://bitbucket.org/ph= g/context-mirror/commits/
wiki=C2=A0 =C2=A0 =C2=A0: https://contextgarden.net
___________________________________________________________________________= ________
--00000000000055b19505e7718e78-- --===============5064372889091084510== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cHM6Ly93d3cubnRnLm5sL21haWxtYW4v bGlzdGluZm8vbnRnLWNvbnRleHQKd2VicGFnZSAgOiBodHRwczovL3d3dy5wcmFnbWEtYWRlLm5s IC8gaHR0cDovL2NvbnRleHQuYWFuaGV0Lm5ldAphcmNoaXZlICA6IGh0dHBzOi8vYml0YnVja2V0 Lm9yZy9waGcvY29udGV4dC1taXJyb3IvY29tbWl0cy8Kd2lraSAgICAgOiBodHRwczovL2NvbnRl eHRnYXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --===============5064372889091084510==--