From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: How to get plist properties list? Date: Fri, 08 Jan 2021 01:50:26 -0500 Message-ID: References: <7eec4142-3c37-4084-9ea1-73df5df2c821@default> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25144"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jan 08 07:51:17 2021 Return-path: Envelope-to: geh-help-gnu-emacs@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 1kxlcD-0006TA-NV for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 08 Jan 2021 07:51:17 +0100 Original-Received: from localhost ([::1]:34816 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxlcC-00079F-OZ for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 08 Jan 2021 01:51:16 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47668) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxlbW-00077S-1G for help-gnu-emacs@gnu.org; Fri, 08 Jan 2021 01:50:34 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:64091) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxlbT-0004bB-BV for help-gnu-emacs@gnu.org; Fri, 08 Jan 2021 01:50:32 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id D51104406E8; Fri, 8 Jan 2021 01:50:29 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id A69F4440436; Fri, 8 Jan 2021 01:50:27 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1610088627; bh=WL+OzG1bUxXZzxTX2cFSWlAOGXN9Z75TqyoeTuzRNf0=; h=From:To:Subject:References:Date:In-Reply-To:From; b=fKxVyErUMFbPdqR0kFkOGBopsiid7cmo7GkjyImHaxtLxiDdTRZbCalN6NqO2ydfZ NUrWsFldgSAsDbqGE6GpwLTMOnuVtdj1ngWSHYAWhO2rjangg4wBK9eKEiGqnl703r WlaR2Ii5i5JSTAmDV8qHcj8s70HN3o8hlCf3ZpvS32qm5AJxfK2uvs4zqy+M1iKTc2 Cj6TIJhnsAQkXaZ22n5/rssRA6x5Nnbg1maR3PLNOqPbpoUDlT9U8mNvkJL3JdZZwG EactptjBX7Y4lh5Gz1zRsg9H61LFGDTVgABAPr6HVSuzmQPOuFKmMiP9F/96nMgIYE gtR+4SFIGCsGQ== Original-Received: from alfajor (unknown [45.72.224.181]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 403F61203D6; Fri, 8 Jan 2021 01:50:27 -0500 (EST) In-Reply-To: (Jean Louis's message of "Fri, 8 Jan 2021 08:46:44 +0300") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:127097 Archived-At: > I would like to understand what is the problem. I don't. You tell me > that `elt' is problem, that is how I understand it. > > Could I maybe rather use `nth' to replace `elt'? No, same problem. Think of it this way: consider your list of N elements as a road that's N kilometers long. `elt` and `nth` are operations which involve walking from the beginning of the road to the Nth kilometer. So to collect all the keys found at kilometers 0, 2, 4, ... your loop does: - walk 0 kilometers and collect the key (then come back). - walk 2 kilometers from the start and collect the key (then come back). - walk 4 kilometers from the start and collect the key (then come back). - walk 6 kilometers from the start and collect the key (then come back). ... [ the "come back" happens to be feasible as a kind of teleportation: obviously my analogy breaks down there. ] So to collect all the keys on a road of 100km you'll end up walking a total of about ... 5000km. I hope you can see that it's far from being the most efficient use of your feet. >> > But maybe there is some more simpler way to get plist properties list? >> >> Probably not the simplest but this should work: >> >> (defun plist-keys (plist) >> (let (keys iskey) >> (dolist (x plist) >> (if (setq iskey (not iskey)) (push x keys))) >> (nreverse keys))) > > As we already discussed it, `dolist' is not perfect, it would give > warnings, not logical at all. There's no warning for this code, AFAIK, no. > In the above example `x' would not give warning, but if there would be > return value then `x' would be part of warning, while return variable > would not be. That is not logical to me, so I consider `dolist' not > well handled by compiler and is better for me not to use it. Just never use that 3rd argument and you'll never get that warning. Stefan