From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: John Mastro Newsgroups: gmane.emacs.help Subject: Re: cl-dolist, dolist, cl-return, Date: Tue, 7 Jul 2015 17:31:35 -0700 Message-ID: References: <87fv4za4jo.fsf@nl106-137-147.student.uu.se> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1436315530 17693 80.91.229.3 (8 Jul 2015 00:32:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 8 Jul 2015 00:32:10 +0000 (UTC) To: "help-gnu-emacs@gnu.org" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jul 08 02:32:10 2015 Return-path: Envelope-to: geh-help-gnu-emacs@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 1ZCdHW-0003vx-3r for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Jul 2015 02:32:10 +0200 Original-Received: from localhost ([::1]:60878 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZCdHV-0000WX-Fg for geh-help-gnu-emacs@m.gmane.org; Tue, 07 Jul 2015 20:32:09 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34953) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZCdHK-0000WK-KM for help-gnu-emacs@gnu.org; Tue, 07 Jul 2015 20:31:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZCdHI-000243-TJ for help-gnu-emacs@gnu.org; Tue, 07 Jul 2015 20:31:58 -0400 Original-Received: from mail-oi0-x22d.google.com ([2607:f8b0:4003:c06::22d]:35956) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZCdHI-00023t-Nx for help-gnu-emacs@gnu.org; Tue, 07 Jul 2015 20:31:56 -0400 Original-Received: by oiaf66 with SMTP id f66so122724769oia.3 for ; Tue, 07 Jul 2015 17:31:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=2BJPh9TTKXfbPhkxejAdgHaF+FRpqhNWhHuM1PZfBfA=; b=rwNzW6m1kaSgIPkmBKN4FHv2F5Qv78Hk85VJ3q55+0l+61Dr3OV+2pg4MUHMSL/3KM 5lv8WPhTASq5y371EoG8HP2SNSlRn8cFOAoP6Wndp1qf2VGQsD5g6E8o7mOqQdJ4R+WD b9t4gUZWOdw/3mLhMxOWaEqWw+iKtDztVFzt3nDXG6qn+w+jDEDHEdrfmynadhJGB/dY q6GubewOcROgSL9HLntHPmXevQkXQOG6ljDoeW17hz8u/MMMt7MZfGEk4rHtr5GPcHH2 D28Q4MFDwtCHOmRgPswP1FyojX2eKQ0TB5RP1go7w+BuvEOzycnxEx7mJvpEHeu6gt6Y fP5w== X-Received: by 10.202.48.22 with SMTP id w22mr6529958oiw.95.1436315515115; Tue, 07 Jul 2015 17:31:55 -0700 (PDT) Original-Received: by 10.76.168.70 with HTTP; Tue, 7 Jul 2015 17:31:35 -0700 (PDT) In-Reply-To: <87fv4za4jo.fsf@nl106-137-147.student.uu.se> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c06::22d X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 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.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:105509 Archived-At: Emanuel Berg wrote: > I just wrote the below code. > > `cl-return' works for `cl-dolist', but not for > `dolist' because it hasn't an "implicit nil block ... > established around the loop". And there is no > `return'! I think this "cl-" stuff is confusing. > Anyone cares to explain? The `cl' prefix stands for Common Lisp, from whence the functionality there came (or was inspired by). > By the way, I know there are one zillion loops > in Lisp. What is the conventional way to > > 1. iterate a list > 2. until some condition is met for some element > 3. then break, to speak in C I don't know if there's one most-conventional way, but here are a couple options: ;; Use `catch' and `throw' (catch 'done (dolist (elt list) (do-something elt) (when (some-condition) (throw 'done t)))) ;; Use `while' and a condition variable (let (done) (while (and list (not done)) (let ((elt (pop list))) (do-something elt) (when (some-condition) (setq done t))))) > And: With [cl-]dolist, if the list is an expression > and not an atom, does that get evaluated once, or does > it happen every iteration like, say, a string length > test would, again in C? Just once. Besides inefficiency, evaluating it every time would lead to wrong results. > Also: why isn't there a "neq"? I don't know the real answer, but it may be because then people would expect `n=', `neql', `nequal', `nequalp', `nstring=', and so on. Or perhaps some would have a "not variant" and others wouldn't, in which case we'd need to remember which did and didn't. IMHO it's simpler and cleaner to have a single `not' which can be used with any predicate as needed. -- john