From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: How to get plist properties list? Date: Fri, 8 Jan 2021 08:46:44 +0300 Message-ID: References: <7eec4142-3c37-4084-9ea1-73df5df2c821@default> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13452"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.0 (3d08634) (2020-11-07) Cc: help-gnu-emacs@gnu.org To: Stefan Monnier Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jan 08 06:49:12 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 1kxke7-0003PV-6m for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 08 Jan 2021 06:49:11 +0100 Original-Received: from localhost ([::1]:51524 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxke6-0000r3-9N for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 08 Jan 2021 00:49:10 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35814) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxkdX-0000qj-UF for help-gnu-emacs@gnu.org; Fri, 08 Jan 2021 00:48:35 -0500 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:38489) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxkdR-0000tm-MP for help-gnu-emacs@gnu.org; Fri, 08 Jan 2021 00:48:34 -0500 Original-Received: from localhost ([::ffff:41.210.145.49]) (AUTH: PLAIN securesender, TLS: TLS1.2,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 0000000000296BE3.000000005FF7F229.00005E4B; Thu, 07 Jan 2021 22:48:24 -0700 Mail-Followup-To: Stefan Monnier , help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-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:127094 Archived-At: * Stefan Monnier [2021-01-08 08:23]: > > (dotimes (i length (reverse properties)) > > (if (divisible-by-2-or-0-p i) > > (push (elt plist i) properties))))) > > This is another example of a dotimes+elt loop, i.e. a loop where you > end up with an unwarranted O(n²) complexity (i.e. a performance bug). Yes, I know there are complexities, but it did not bother me really. Only compiler warnings bother me. > > (while (/= n (length plist)) > > (push (elt plist n) properties) > > (setq n (+ 2 n))) > > properties)) > > Same problem here. 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'? (elt '(1 2 3) 0) (nth 0 '(1 2 3)) Which one is faster? > > 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. 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. > The simplest might be: > > (map-keys plist) That is it. Why not start with that one... Jean