caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] let rec
@ 2003-01-15 19:15 Vitaly Lugovsky
  2003-01-15 19:27 ` james woodyatt
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Vitaly Lugovsky @ 2003-01-15 19:15 UTC (permalink / raw)
  To: caml-list


 For a closure-driven "compilers" I have to use for
a recursion something like this:

    let xprs = ref (fun _ -> Lnil) in
    let f (il,al,ht) =
      let il2 = Array.make (n2+1) Lnil in
      acopy il il2;
      Array.iteri (fun i x -> il2.(all.(i)) <- x) al;
      !xprs (il2,anul,ht)
    in xprs :=
      (Hashtbl.replace ht name (CTfun(f)); (* Insert f into the env2
                                              environment *)
       compile_exprs env2 exprs);
    f

 It's not so funny. Why I can't write it using let rec:

    let rec f (il,al,ht) =
      let il2 = Array.make (n2+1) Lnil in
      acopy il il2;
      Array.iteri (fun i x -> il2.(all.(i)) <- x) al;
      xprs (il2,anul,ht)
    and xprs =
      (Hashtbl.replace ht name (CTfun(f));
       compile_exprs env2 exprs) in
    f

 Sure, let rec construction should be much less restrictive.

 And, another one question: does ocaml compiler really eliminates
unused variables from the closure environment?

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2003-01-18 16:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-15 19:15 [Caml-list] let rec Vitaly Lugovsky
2003-01-15 19:27 ` james woodyatt
2003-01-15 19:54   ` Vitaly Lugovsky
2003-01-15 19:53 ` Max Kirillov
2003-01-16 14:38 ` Mike Potanin
2003-01-18 12:08   ` Damien Doligez
2003-01-18 15:31     ` Mike Potanin
2003-01-18 19:22     ` Vitaly Lugovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).