From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 0D46BBC0A for ; Tue, 3 Apr 2007 15:32:02 +0200 (CEST) Received: from dorado.vub.ac.be (smtp.vub.ac.be [134.184.129.10]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l33DW1Gx008129 for ; Tue, 3 Apr 2007 15:32:01 +0200 Received: from exchange.etro.vub.ac.be (etro10.vub.ac.be [134.184.2.10]) by dorado.vub.ac.be (Postfix) with ESMTP id 4CCDA3FD for ; Tue, 3 Apr 2007 15:31:59 +0200 (CEST) Received: from ssel.vub.ac.be ([10.0.4.37]) by exchange.etro.vub.ac.be with Microsoft SMTPSVC(6.0.3790.1830); Tue, 3 Apr 2007 15:31:59 +0200 Received: from localhost (localhost.localdomain [127.0.0.1]) by ssel.vub.ac.be (Postfix) with ESMTP id 1A4F02469294; Tue, 3 Apr 2007 15:31:59 +0200 (CEST) X-Virus-Scanned: amavisd-new at ssel.vub.ac.be Received: from ssel.vub.ac.be ([127.0.0.1]) by localhost (ssel.vub.ac.be [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PjSq0-7rAPdS; Tue, 3 Apr 2007 15:31:53 +0200 (CEST) Received: from [192.168.2.2] (cable-213-132-154-211.upc.chello.be [213.132.154.211]) by ssel.vub.ac.be (Postfix) with ESMTP id 93E332469290; Tue, 3 Apr 2007 15:31:53 +0200 (CEST) In-Reply-To: <200704031309.08302.jon@ffconsultancy.com> References: <4611FBAB.1020508@fmf.uni-lj.si> <200704031309.08302.jon@ffconsultancy.com> Mime-Version: 1.0 (Apple Message framework v752.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <2F51D421-AFAD-42F4-8DE5-E6416EC03CAB@vub.ac.be> Cc: caml-list Content-Transfer-Encoding: 7bit From: Bruno De Fraine Subject: Re: [Caml-list] How important are circular lists/recursive objects? Date: Tue, 3 Apr 2007 15:31:51 +0200 To: Jon Harrop X-Mailer: Apple Mail (2.752.2) X-OriginalArrivalTime: 03 Apr 2007 13:31:59.0202 (UTC) FILETIME=[74994420:01C775F4] X-Miltered: at concorde with ID 46125751.002 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; recursive:01 vars:01 vars:01 foo:01 foo:01 universiteit:01 vub:98 2007,:98 vub:98 wrote:01 rec:01 rec:01 caml-list:01 define:01 objects:02 Hello Jon, On 03 Apr 2007, at 14:09, Jon Harrop wrote: > Specifically, in the "eval" function: > > | ELetRec(var, arg, body, rest) -> > let rec vars = (var, VClosure(arg, vars, body)) :: vars in > eval vars rest Actually, I think this critical piece of code is incorrect. As such, the new "vars" is shadowing the old value of "vars", while it seems you still want to refer to this old value in one place. I.e.: | ELetRec(var, arg, body, rest) -> let rec new_vars = (var, VClosure(arg, new_vars, body)) :: vars in eval new_vars rest If I define eval like this, it will still correctly evaluate your fibonacci example, but it will no longer loop infinitely on an example like "let foo x = x + 1 in let bar y = (foo y) + 1 in bar 3". Regards, Bruno -- Bruno De Fraine Vrije Universiteit Brussel Faculty of Applied Sciences, INFO - SSEL Room 4K208, Pleinlaan 2, B-1050 Brussels tel: +32 (0)2 629 29 75 fax: +32 (0)2 629 28 70 e-mail: Bruno.De.Fraine@vub.ac.be