From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id D4C1724171 for ; Fri, 19 Jan 2024 11:28:44 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1705660124; b=CcLJ7kO/JmgG50t2pYL2wrOB82nKUAHZxUFzMqxE7olGNl+F/CpvqH9nRMqrX0nZLraH1AFnCD TFgVLZTs62T4ebeIGzE6N3bpucqdTmh89K7fH7W3/30EdybmdvfRGucNHGpQ4hjzzUbXft17FJ /pYogGEnUFTDe96olARxrnaBqQ1p1Im75cDsdDwKIfdpfTY342lJg9CpiGyp9AIWuKLDcrabj5 prPo7H8vwR/FVJwWmNwwKhQMmoKerQjsy3jmRr5Y9xPqY4Q5eo3vooeOd7brSD/zz1rN7DnmJ/ 8KEO4yuUCyjlDJEz49XUOHdQ9zQPRCSh0xYHmZsk1g6czQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (relay8-d.mail.gandi.net) smtp.remote-ip=217.70.183.201; dmarc=none header.from=chazelas.org; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1705660124; bh=ImHkEA/xhPImYmA9UsALB1/NyOBK3ciNtyqUOD3cSOk=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:DKIM-Signature; b=B4pmNACjrObbO1hLCRVOEIEI1Mb7sIVl4Iu3zH1JRE0DKclhGrlyAuVD84IoDp9YK+0LHZm0jo eRqwGD4jCpoQphNObF6ibnYM9aVa77Vig+tDI3AK/Ex/UfbPiFNalcGUVxmDk1Psl0Qx69aTxt AwH4/6WupaeKCz/bGFQu12JO9fzvgoT61vtuSjoPKtAdB5eq7NZTKh6S7192HhYClDzokE5Qhq dUaypAAxKGp+P4NFoP0/JK6Ip/WULru1E3x0mNPK4BaAfrTaQKh1jc6u3m1cFY73sMxDlYQZva sgFwPvG0i/0W6TaPsCBXktoCoJ5MIR8OwOdoG2TqUy47JQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID; bh=uqF1PkVKbW93dAaHqeChT57rZVZDDkrg7+qGMqkaO18=; b=ZDb2pcW26Ig5H6RePFMxfsTXU5 Y9T4K2i0lfS0a2wizTQIazVO8fgUjBCg5VS8M/8d//6VzR5mg8mJAiQWOI79Ek0jT+FxkUk4bMk4u DIFEZZ8P/6bPqpmJnmhQlY0DVLlUueB0+Ty2OVD/VE4kW8d9W/p8m/91jjOhTAKkdfNK7UEEtodpr tEG4H0dV/EMsSK6xscST0jXi7/ST66c+fQ5BRPKQYJX2RFmXxarhlLBEyIDlvVX4eXwwNUL+r7q3o CdHxduQ+dOzqZQ61kZRH8tY8F6yRB3F7hED9ltsI7bhwAs3lT/SpYUrWkR/L/Fk/uudMgrmC9lngx SEfuWGEQ==; Received: by zero.zsh.org with local id 1rQm78-000F5t-4U; Fri, 19 Jan 2024 10:28:42 +0000 Authentication-Results: zsh.org; iprev=pass (relay8-d.mail.gandi.net) smtp.remote-ip=217.70.183.201; dmarc=none header.from=chazelas.org; arc=none Received: from relay8-d.mail.gandi.net ([217.70.183.201]:40339) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1rQm6Q-000EOQ-If; Fri, 19 Jan 2024 10:27:59 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 46ACA1BF20A; Fri, 19 Jan 2024 10:27:57 +0000 (UTC) Date: Fri, 19 Jan 2024 10:27:55 +0000 From: Stephane Chazelas To: Ray Andrews Cc: zsh-users@zsh.org Subject: Re: Empty element elision and associative arrays (was Re: Slurping a file) Message-ID: <20240119102755.5ma5psbccsuo5ohj@chazelas.org> Mail-Followup-To: Ray Andrews , zsh-users@zsh.org References: <7b20b425-59b2-466d-a9aa-a2768d1d4633@app.fastmail.com> <4b475319-ef78-4d46-a62c-27c3b0af3ea4@eastlink.ca> <49702cd2-814c-4461-9819-cc2b85bd3ea2@eastlink.ca> <50941e8e-86e2-4e89-8644-c863f846e805@eastlink.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-GND-Sasl: stephane@chazelas.org X-Seq: 29521 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: 2024-01-18 18:58:41 -0800, Ray Andrews: > > On 2024-01-18 18:46, Bart Schaefer wrote: > > On Thu, Jan 18, 2024 at 3:08 PM Ray Andrews wrote: > > > How hard would it be to get the first hash 'right'? > > That's not how hash tables work. > > I have no idea how they work which is why my comments have little value.  If > ksh can do it then it can be done, but as I said, it simply might not be > worth the effort and I'm in no position to judge the matter.  I wish I'd > gotten that far in C, I'd heard of hash tables but never coded one.  But I > did note in that code previous that the order seemed not to change.  > Nevermind. As said before, in "${!hash[@]}", ksh93 orders the keys lexically, not in the order they were inserted in the hash table. It doesn't record that order either. If you want to do the same in zsh, use the o parameter expansion flag to order the keys. See also n to order numerically: $ ksh -c 'typeset -A a; for i do a[$i]=$(( ++n )); done; printf "%s\n" "${!a[@]}"' ksh {1..20} 1 10 11 12 13 14 15 16 17 18 19 2 20 3 4 5 6 7 8 9 $ zsh -c 'typeset -A a; for i do a[$i]=$(( ++n )); done; printf "%s\n" "${(ko@)a}"' ksh {1..20} 1 10 11 12 13 14 15 16 17 18 19 2 20 3 4 5 6 7 8 9 $ zsh -c 'typeset -A a; for i do a[$i]=$(( ++n )); done; printf "%s\n" "${(kn@)a}"' ksh {1..20} 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 -- Stephane