From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA24872 for caml-redistribution; Mon, 2 Jun 1997 23:20:27 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA22781 for ; Mon, 2 Jun 1997 18:23:45 +0200 (MET DST) Received: from blaze.accessone.com (blaze.accessone.com [198.68.191.19]) by nez-perce.inria.fr (8.8.5/8.7.3) with ESMTP id SAA13019 for ; Mon, 2 Jun 1997 18:23:36 +0200 (MET DST) Received: from mmuncher4 (kirk04-4.accessone.com [209.43.128.76]) by blaze.accessone.com (8.8.5/8.8.5) with ESMTP id JAA20114; Mon, 2 Jun 1997 09:20:33 -0700 (PDT) Message-Id: <199706021620.JAA20114@blaze.accessone.com> From: "Dwight VandenBerghe" To: "Pascal Zimmer" , Subject: Re: Instruction return Date: Mon, 2 Jun 1997 09:23:19 -0700 X-MSMail-Priority: Normal X-Priority: 3 X-Mailer: Microsoft Internet Mail 4.70.1161 MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: weis (I apologize for no French version) > let rech x v = > let n = vect_length v in > for i=0 to n-1 do > if v.(i) = x then return true > done; false;; This is one of the two main control problems with functional programming, IMHO. The solution I use is: exception Found_it let rech x v = try for i = 0 to pred (vect_length v) do if v.(i) = x then raise Found_it done; false with Found_it -> true You don't have to assign vect_length v to n; it is only evaluated once anyway. If iter is defined on the type of v, then you can also use let rech x v = try let f x1 = if x1 = x then raise Found_it in iter f v; false with Found_it -> true The other control problem is when you want the equivalent of: x = foo(a); bar(); return x; If you try let x = foo(a) in bar(); x then bar gets done first, instead of second. I use this instead: let f x = bar(); x in in f (foo a) I haven't found any other serious problems with Caml's logic flow. These two just take some getting used to. Dwight