Browse thread
How important are circular lists/recursive objects?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Bruno De Fraine <Bruno.De.Fraine@v...> |
| Subject: | Re: [Caml-list] How important are circular lists/recursive objects? |
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