From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Michael Brand Newsgroups: gmane.emacs.devel Subject: Multidimensional list comprehension with binding Date: Mon, 11 Jun 2018 18:25:24 +0200 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1528734454 32646 195.159.176.226 (11 Jun 2018 16:27:34 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 11 Jun 2018 16:27:34 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jun 11 18:27:30 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fSPfF-0008MW-5B for ged-emacs-devel@m.gmane.org; Mon, 11 Jun 2018 18:27:29 +0200 Original-Received: from localhost ([::1]:50105 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSPhM-0007QG-75 for ged-emacs-devel@m.gmane.org; Mon, 11 Jun 2018 12:29:40 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39228) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSPdH-00056Z-Or for emacs-devel@gnu.org; Mon, 11 Jun 2018 12:25:28 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSPdH-0008Bg-0g for emacs-devel@gnu.org; Mon, 11 Jun 2018 12:25:27 -0400 Original-Received: from mail-wr0-x22a.google.com ([2a00:1450:400c:c0c::22a]:34513) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fSPdG-0008Ap-P4 for emacs-devel@gnu.org; Mon, 11 Jun 2018 12:25:26 -0400 Original-Received: by mail-wr0-x22a.google.com with SMTP id a12-v6so21067021wro.1 for ; Mon, 11 Jun 2018 09:25:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=aYkvuXMrw8HM1DmbOiMKf1js6fIuH0QW3L04R+UFss0=; b=oavoI2zvLY7GRuTB5oWpHMsfsGOJ0Bz0xNBi5QkgrDkgJSpHr7HTJ3IKIZUZoftEkX gNJQI/L6mmdBcABD2Vm85BimZSjL5EQZZB6S4dJEMpS1vdOKQQi+UKS1U28PQJbIssRz nMBPSX57jrMfZAyRpxPWpXI3cV6zNS2zqdN/VIzdJ/Yc0OBpE27PwLVdJ1M8zJbOFHoC L4Z3EWCyYMKXyDqCQ/oAO3fZ8b9iY2rF9fi9qjqtyAZCNpDrubnbc69SP8dSLbmEP3L/ 7RVDbucjOUsZG44C1qT2flUBKCjAQ+nxuYrpA8047caF/TcPiHUiuFHf2+yZkAvl9Xzc iFwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=aYkvuXMrw8HM1DmbOiMKf1js6fIuH0QW3L04R+UFss0=; b=CvHCU7hSB8mdqzYz7LLqKSB7ROQJLO3BtMFDACwjcvhpIVuOT0GLOKr5VHj1yD/A9E qxNWBLTZ0vNEa+27H88fdIX+2/RntKxp9pcAOi6N0pOcVjuFFDzh1nzlUU+xTn35WMSY NuavMXN8VG8dIxP9KLbLwtuEgVR11aUXn5qocM2fSj87/CeoVA8kZzRUijka7JAY4qEv XL1KzR3IJdbUGMU0HY6PPvBEF2ngWhj2s+YZt7GjXf35rHq+9b83JewuXhz2a1YrrcfT j4eBb3XseqtfnUNTsMspaE4YHZMhEo4hk/Yg8xdIjUKKyIygX4l45uSUTEQAOAkKJzu3 ZDSA== X-Gm-Message-State: APt69E3CewmlyS3FPXHUERsarOQXvadR24aAAHL64oBBiaVv7TDN9oZW EbKKllHG+S8xoGLGqS6bwjDikspStnXKQGsJN7vi+A== X-Google-Smtp-Source: ADUXVKJbiQxgetL62N0GWBXV9EuaGXBh6t+NFHgg1lks+FaM3PXnvAQAW9A1Rt0e9/D1yvFZklNWPx8BgmI4qp+t96A= X-Received: by 2002:adf:a686:: with SMTP id t6-v6mr13301498wrc.51.1528734325199; Mon, 11 Jun 2018 09:25:25 -0700 (PDT) Original-Received: by 2002:a1c:dc8:0:0:0:0:0 with HTTP; Mon, 11 Jun 2018 09:25:24 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22a X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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:226226 Archived-At: Hi all I try to replicate the following Python list comprehension with Emacs Lisp. It reports the list elements with its length when the length is even. The expectation is to calculate the length only once and to not use a second and nested list comprehension: #+begin_src python :results verbatim return [[res, arg] for arg in ["ab", "c", ""] for res in [len(arg)] if res % 2 == 0] #+end_src #+results: : [[2, 'ab'], [0, '']] The above result is as expected (Python 2.7 and 3.6). In my trial with Emacs Lisp the syntax for the equivalent expression seems to be accepted but the result is not the expected ((2 "ab") (0 "")): #+begin_src emacs-lisp :results verbatim (cl-loop for arg in '("ab" "c" "") for res in (list (length arg)) if (= (% res 2) 0) collect (list res arg)) #+end_src #+results: : ((0 "ab")) Am I doing something wrong or is this a bug in emacs-26.1-2189-g8377ca6 and 26.1? Michael PS: A workaround would be this less elegant version: #+begin_src emacs-lisp :results verbatim (let (res) (cl-loop for arg in '("ab" "c" "") if (progn (setq res (length arg)) (= (% res 2) 0)) collect (list res arg))) #+end_src #+results: : ((2 "ab") (0 ""))