From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: new function proposal alist-to-hash Date: Fri, 04 Oct 2019 15:16:13 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="55188"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Andrea Corallo Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Oct 04 21:16:53 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iGT4O-000E7E-S1 for ged-emacs-devel@m.gmane.org; Fri, 04 Oct 2019 21:16:53 +0200 Original-Received: from localhost ([::1]:51440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iGT4I-0005vB-G4 for ged-emacs-devel@m.gmane.org; Fri, 04 Oct 2019 15:16:46 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39534) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iGT3u-0005uy-S0 for emacs-devel@gnu.org; Fri, 04 Oct 2019 15:16:23 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iGT3s-00034N-90 for emacs-devel@gnu.org; Fri, 04 Oct 2019 15:16:21 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:51576) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iGT3q-00033A-FN for emacs-devel@gnu.org; Fri, 04 Oct 2019 15:16:19 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 47E2585353; Fri, 4 Oct 2019 15:16:17 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id D6EEE8124F; Fri, 4 Oct 2019 15:16:15 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1570216575; bh=EycnV3zLItSZjGjzMLHyCRETCUsWxXXLENHpugXCgTw=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=Mfj5HOcRbyiHKuhpeGE8O/FIL6MyG2EHpj+6QyAHN9wR2tNgJnAuECvCMsRq47z8Z 1+JCYgrUZJLbm+nTJM2AJCgLAl0snK1pZ1MqjSYgdRif/KjbyVKzZg0eyoudnj+7Ej Mj0UbsfIClX7QJbiv01ehp5YQxjxu5lStgGkkpHk++U+YKnePvRRRoj17ewLVPk0q8 4h62poQbuRYKCuvrkFB385FApMNCzjMIldHLOrOUm7a+nxBueUi+ZSN3tVR43aA7mo J78YpMTB5fli1bGkYSSKY9K1+voi4p0WvpQRa8qCUksYiyInFGjZNwaaW4hL1goTdr a6mCZgvJaHPow== Original-Received: from alfajor (modemcable157.163-203-24.mc.videotron.ca [24.203.163.157]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 65AA112031C; Fri, 4 Oct 2019 15:16:15 -0400 (EDT) In-Reply-To: (Andrea Corallo's message of "Fri, 04 Oct 2019 09:58:43 +0000") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 132.204.25.50 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:240578 Archived-At: > - I think is quite useful to be able to create in a concise and > explicit way nested hash tables. This is a common feature of many > "modern" languages. > Here both solutions compared: > > (alist-to-hash '((a . x) > (b . ((i . j) > (k . l))) > (c . y))) > > (map-into `((a . x) > (b . ,(map-into '((i . j) > (k . l)) > 'hash-table)) > (c . y)) > 'hash-table) Not sure I understand: if you only use it for immediate/literal data, then I guess you could just use the #s(hash-table data (...)) syntax. And for non-literal maps, this needs to somehow distinguish values that are alists from others, like (map-into (mapcar (lambda (x) (if (and (consp (cdr x)) (consp (cadr x))) (cons (car x) (map-into (cdr x) 'hash-table)) x)) my-alist) 'hash-table) But I suspect that this is not frequently needed. [ BTW, the above code is screaming for something like `map-values-apply` but which returns a *map* rather than a list. ] And if you really need this to apply recursively, it basically means you don't have a map but a *tree* where each node is originally implemented as an alist and which you want to transform into the same tree where each node is now a hash-table. Again, this is likely not needed very frequently (and I suspect that each time it's needed, it will have slightly different needs/constraints). > - map-into does not let you tweak make-hash-table parameters. > This is especially a limitation regarding :test so is effectively a > solution to say ~50% of the use cases. Yes, this is a very serious limitation of `map-into`. I decided not to try to tackle it when I converted map.el to use cl-defmethod, but I'd welcome help on this. Stefan