From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.devel Subject: RE: seq-some-p and nil Date: Tue, 8 Sep 2015 12:48:23 -0700 (PDT) Message-ID: References: <1441295429.4215.0@smtp.gmail.com> <87si6vl21r.fsf@petton.fr> <878u8k2vnp.fsf@udel.edu> <878u8i69ok.fsf@petton.fr> <674102d7-0e97-478a-af05-ca6d82c17c28@default> <87mvwym01x.fsf@petton.fr> <87h9n5mloa.fsf@petton.fr> <8737ypm547.fsf@petton.fr> <87pp1s976u.fsf@fencepost.gnu.org> <3dc0f1d9-caf1-446a-ab14-2b3e210a02e7@default> <87r3m8lop9.fsf@petton.fr> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1441741749 29569 80.91.229.3 (8 Sep 2015 19:49:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 8 Sep 2015 19:49:09 +0000 (UTC) Cc: Mark Oteiza , emacs-devel@gnu.org To: Nicolas Petton , David Kastrup , Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Sep 08 21:48:56 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZZOsx-0004eY-86 for ged-emacs-devel@m.gmane.org; Tue, 08 Sep 2015 21:48:55 +0200 Original-Received: from localhost ([::1]:36977 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZOsx-00037J-5c for ged-emacs-devel@m.gmane.org; Tue, 08 Sep 2015 15:48:55 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34435) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZOsZ-000346-F7 for emacs-devel@gnu.org; Tue, 08 Sep 2015 15:48:32 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZZOsW-0006oy-8D for emacs-devel@gnu.org; Tue, 08 Sep 2015 15:48:31 -0400 Original-Received: from userp1040.oracle.com ([156.151.31.81]:26003) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZOsW-0006oq-2O; Tue, 08 Sep 2015 15:48:28 -0400 Original-Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t88JmQII021349 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 8 Sep 2015 19:48:27 GMT Original-Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id t88JmOO2026669 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Tue, 8 Sep 2015 19:48:24 GMT Original-Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id t88JmOGY019904; Tue, 8 Sep 2015 19:48:24 GMT In-Reply-To: <87r3m8lop9.fsf@petton.fr> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9 (901082) [OL 12.0.6691.5000 (x86)] X-Source-IP: userv0021.oracle.com [156.151.31.71] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 156.151.31.81 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:189737 Archived-At: > > Was there something wrong with the suggestion to return, > > as the non-nil value, a cons (ELEMENT . VALUE)? > > > > (Where ELEMENT is the sequence element that satisfies the > > predicate, and VALUE is the return value of the predicate > > for that element.) > > > > That gives you "some" element that satisfies the predicate > > (the first such). And it gives you the result of the test. > > Each of these can be useful, depending on the context. >=20 > It would work, and I believe Scheme has a similar function, but I don't > want seq-some to have this extra complexity. It could be another > function though, just like in Scheme. What extra complexity? It creates one cons cell which has as its car and cdr things that presumably already exist. I realize you are dealing with general sequences, and that the sequence code can be complex, but the cons part of it, as the return value, should be simple, no? Isn't it true for all sequence types supported, that the car and cdr will exist after the predicate is called, and so they can just be pointed to by the cons? For lists only, this is what I use, FWIW: (defun zz-some (predicate list) "Return non-nil if PREDICATE applied to some element of LIST is true. The value returned is a cons, (ELEMENT . VALUE), where ELEMENT is the first list element that satisfies PREDICATE and VALUE is the value of PREDICATE applied to ELEMENT." (let (elt val) (catch 'zz-some (while list (when (setq val (funcall predicate (setq elt (pop list)))) (throw 'zz-some (cons elt val)))) nil)))