From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: return Date: Fri, 26 Nov 2010 09:59:51 -0500 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1290783610 971 80.91.229.12 (26 Nov 2010 15:00:10 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 26 Nov 2010 15:00:10 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Nov 26 16:00:07 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PLzmP-00053P-79 for ged-emacs-devel@m.gmane.org; Fri, 26 Nov 2010 16:00:05 +0100 Original-Received: from localhost ([127.0.0.1]:57827 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PLzmO-0007lG-P4 for ged-emacs-devel@m.gmane.org; Fri, 26 Nov 2010 10:00:04 -0500 Original-Received: from [140.186.70.92] (port=35370 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PLzmG-0007iz-UY for emacs-devel@gnu.org; Fri, 26 Nov 2010 10:00:00 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PLzmE-0002cX-PB for emacs-devel@gnu.org; Fri, 26 Nov 2010 09:59:56 -0500 Original-Received: from pruche.dit.umontreal.ca ([132.204.246.22]:48190) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PLzmE-0002bx-Mk for emacs-devel@gnu.org; Fri, 26 Nov 2010 09:59:54 -0500 Original-Received: from pastel.home (lechon.iro.umontreal.ca [132.204.27.242]) by pruche.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id oAQExqn0030030; Fri, 26 Nov 2010 09:59:52 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id 95F61A8491; Fri, 26 Nov 2010 09:59:51 -0500 (EST) In-Reply-To: (Lars Magne Ingebrigtsen's message of "Fri, 26 Nov 2010 09:57:21 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV3690=0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:133168 Archived-At: > While debugging and fixing stuff, I often find myself in the situation > of adding more if/cond statements to a function and pushing the original > body further in. I think this usually leads to less clear code. If this is only "while debugging and fixing stuff", I don't think it's a serious enough problem to warrant such a change. Note that my preference to stick with the current situation in his respect is not just out of inertia but also because I like a more functional style of programming: usually/often you can find a formulation that's just as elegant without the need for an early exit. > This isn't the only use case, of course. A lot of functions in Emacs go > through pretty awkward contortions to end loops when certain conditions > occur. I tend to agree that early exit from loops would be sometimes welcome. Currently, people either use catch/throw, or contortions, or just decide not to exit early. Also our while loops have no way to return a value, so a `return' from a while loop can make the code *more* functional. In functional programming language early exit constructs are rarely needed because loops are written using recursion, so it's easy to exit early: just don't recurse. One constructs which would improve the situation (without adding early exits) would be to add an `until': it's just like `while' except that the condition is reversed *and* that the non-nil final condition is returned as value of the `until' expression. Very often (until (progn foo bar) baz) works well. But I'd be OK with adding a `return' from while loops: after all `while' loops are naturally imperative, so such a `return' would not make things less imperative. Stefan