From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Welsh Duggan Newsgroups: gmane.emacs.devel Subject: Lexical let and setq Date: Fri, 13 Sep 2013 20:09:05 -0400 Message-ID: <878uz0e02m.fsf_-_@maru2.md5i.com> References: <871u51ll93.fsf@yandex.ru> <0b29ebee-8ed4-47e2-816b-910a013a0898@default> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1379117362 18759 80.91.229.3 (14 Sep 2013 00:09:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 14 Sep 2013 00:09:22 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Sep 14 02:09:26 2013 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 1VKdQT-0002xf-PL for ged-emacs-devel@m.gmane.org; Sat, 14 Sep 2013 02:09:25 +0200 Original-Received: from localhost ([::1]:51533 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VKdQT-0001kX-1h for ged-emacs-devel@m.gmane.org; Fri, 13 Sep 2013 20:09:25 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38477) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VKdQM-0001iw-KM for emacs-devel@gnu.org; Fri, 13 Sep 2013 20:09:23 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VKdQI-00065y-72 for emacs-devel@gnu.org; Fri, 13 Sep 2013 20:09:18 -0400 Original-Received: from md5i.com ([75.151.244.229]:50901 helo=maru2.md5i.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VKdQI-00065T-2Y for emacs-devel@gnu.org; Fri, 13 Sep 2013 20:09:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=md5i.com; s=dkim; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:References:Subject:Cc:To:From; bh=0aEv+F7PETYs+CEN6LhCGpXroMSY4vLfkNV2cEhbGG4=; b=Z5AkL0ih96+KJ0wEqJQlGanzaJsZaP/vjQYlaLQoEi8ei6JOQEUZnARaMMtyj8vhGbepgSsTpjY62QZq3GWGpi7fsgKWBYvd5OI6Aal3hg6do5Dro+NdcrcRuBMU9wc8; Original-Received: from md5i by maru2.md5i.com with local (Exim 4.80) (envelope-from ) id 1VKdQ9-0005qa-OJ; Fri, 13 Sep 2013 20:09:05 -0400 In-Reply-To: (Stefan Monnier's message of "Fri, 13 Sep 2013 00:37:25 -0400") User-Agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 75.151.244.229 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:163332 Archived-At: Stefan Monnier writes: [...] > I do hope to fix those issues by introducing other byte-codes which will > let us generate significantly more efficient code for those constructs, > but in 24.1, the priority was to get lexical-binding to work correctly, > performance being a secondary concern (tho for most idiomatic Elisp > code, the performance tends to be competitive). > > What people should know is that > > (let (x y z) > ...(setq x ...) > ...(setq z ...) > ...(setq y ...) > > is often a bad idea in Elisp, and even more so in lexical-binding code > (in some cases, if a variable is immutable it can be handled > significantly more efficiently, so the mere existence of a single `setq' > on a variable can sometimes slow other chunks of code: in many cases > `let' is cheaper than `setq'). The primary reason I have seen the (let (foo) (setq foo ...)) idiom is in looping code. The way I would normally try to avoid this idiom in most FP languages would be to use recursion (specifically tail recursion, if possible). I know some work was done on implementing efficient tail-recursion in the byte compiler. Has any of that made it onto the trunk yet? -- Michael Welsh Duggan (md5i@md5i.com)