From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Newsgroups: gmane.lisp.guile.devel Subject: Re: Difference letrec & environment binding Date: Wed, 13 Apr 2011 7:51:58 -0400 Message-ID: <20110413115158.C5DYL.47361.root@cdptpa-web28-z01> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1302695538 2196 80.91.229.12 (13 Apr 2011 11:52:18 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 13 Apr 2011 11:52:18 +0000 (UTC) To: guile-devel , Hans Aberg Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed Apr 13 13:52:14 2011 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Q9ycH-0002v5-2G for guile-devel@m.gmane.org; Wed, 13 Apr 2011 13:52:13 +0200 Original-Received: from localhost ([::1]:38905 helo=lists2.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q9ycE-000116-BD for guile-devel@m.gmane.org; Wed, 13 Apr 2011 07:52:10 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:47500) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q9ycB-00010v-Sg for guile-devel@gnu.org; Wed, 13 Apr 2011 07:52:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q9yc6-0000bB-06 for guile-devel@gnu.org; Wed, 13 Apr 2011 07:52:07 -0400 Original-Received: from cdptpa-omtalb.mail.rr.com ([75.180.132.121]:34956) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q9yc5-0000a9-Tq for guile-devel@gnu.org; Wed, 13 Apr 2011 07:52:01 -0400 Authentication-Results: cdptpa-omtalb.mail.rr.com smtp.user=dsmich@roadrunner.com; auth=pass (LOGIN) X-Authority-Analysis: v=1.1 cv=ToWar1fa9ljTHbeJIRNQycBnYxCRNi5M/11QAwRcJ6A= c=1 sm=0 a=JBLSUxNNqywA:10 a=zTVDa7HKqxcA:10 a=IkcTkHD0fZMA:10 a=URPmHnG1AAAA:8 a=Bl8a1fqFNbvowMwq8_MA:9 a=QEXdDO2ut3YA:10 a=ggs8CzkAohcA:10 a=9vbP7QtNB6XqBBokMM2/RQ==:117 X-Cloudmark-Score: 0 Original-Received: from [10.127.132.119] ([10.127.132.119:60668] helo=cdptpa-web28-z01) by cdptpa-oedge04.mail.rr.com (envelope-from ) (ecelerity 2.2.3.46 r()) with ESMTPA id A3/C8-29678-E5E85AD4; Wed, 13 Apr 2011 11:51:58 +0000 In-Reply-To: X-Priority: 3 (Normal) Sensitivity: Normal X-Originating-IP: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 75.180.132.121 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:12229 Archived-At: ---- Hans Aberg wrote: > What is the practical difference between the two ways of doing the same thing (letrec or an environment). Is letrec more efficient in the implementation of Guile? > > Hans > > > (letrec ( > (even? (lambda (n) > (if (zero? n) #t (odd? (- n 1))))) > (odd? (lambda (n) > (if (zero? n) #f (even? (- n 1)))))) > (even? 1000)) > > ((lambda () > (define even? (lambda (n) > (if (zero? n) #t (odd? (- n 1))))) > (define odd? (lambda (n) > (if (zero? n) #f (even? (- n 1))))) > (even? 1000))) > No difference at all. Those generate identical code. I believe the second form is transformed into the first during compilation. scheme@(guile-user)> ,x a Disassembly of #: 0 (assert-nargs-ee/locals 8) 2 (br :L204) ;; -> 25 at (unknown file):15:9 6 (local-ref 0) ;; `n' 8 (make-int8:0) ;; 0 at (unknown file):16:8 9 (ee?) 10 (br-if-not :L205) ;; -> 16 at (unknown file):16:4 14 (make-true) ;; #t 15 (return) 16 (local-ref 0) ;; `n' 18 (sub1) at (unknown file):16:27 19 (local-set 0) ;; `n' 21 (br :L206) ;; -> 29 at (unknown file):16:21 25 (br :L207) ;; -> 48 at (unknown file):17:8 29 (local-ref 0) ;; `n' 31 (make-int8:0) ;; 0 at (unknown file):18:8 32 (ee?) 33 (br-if-not :L208) ;; -> 39 at (unknown file):18:4 37 (make-false) 38 (return) 39 (local-ref 0) ;; `n' 41 (sub1) at (unknown file):18:28 42 (local-set 0) ;; `n' 44 (br :L209) ;; -> 6 at (unknown file):18:21 48 (make-int16 3 232) ;; 1000 51 (local-set 0) 53 (br :L209) ;; -> 6 at (unknown file):19:2 scheme@(guile-user)> ,x b Disassembly of #: 0 (assert-nargs-ee/locals 8) 2 (br :L216) ;; -> 25 at (unknown file):23:16 6 (local-ref 0) ;; `n' 8 (make-int8:0) ;; 0 at (unknown file):24:8 9 (ee?) 10 (br-if-not :L217) ;; -> 16 at (unknown file):24:4 14 (make-true) ;; #t 15 (return) 16 (local-ref 0) ;; `n' 18 (sub1) at (unknown file):24:27 19 (local-set 0) ;; `n' 21 (br :L218) ;; -> 29 at (unknown file):24:21 25 (br :L219) ;; -> 48 at (unknown file):25:15 29 (local-ref 0) ;; `n' 31 (make-int8:0) ;; 0 at (unknown file):26:8 32 (ee?) 33 (br-if-not :L220) ;; -> 39 at (unknown file):26:4 37 (make-false) 38 (return) 39 (local-ref 0) ;; `n' 41 (sub1) at (unknown file):26:28 42 (local-set 0) ;; `n' 44 (br :L221) ;; -> 6 at (unknown file):26:21 48 (make-int16 3 232) ;; 1000 51 (local-set 0) 53 (br :L221) ;; -> 6 at (unknown file):27:2 -Dale