From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA14116; Thu, 23 Oct 2003 21:32:27 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 VAA28733 for ; Thu, 23 Oct 2003 21:32:26 +0200 (MET DST) Received: from herd.plethora.net (herd.plethora.net [205.166.146.1]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h9NJWP103620 for ; Thu, 23 Oct 2003 21:32:25 +0200 (MET DST) Received: from bhurt.plethora.net (bhurt.plethora.net [205.166.146.49]) by herd.plethora.net (8.11.6/8.10.1) with ESMTP id h9NJW0C04842; Thu, 23 Oct 2003 14:32:00 -0500 (CDT) Date: Thu, 23 Oct 2003 14:32:03 -0500 (CDT) From: Brian Hurt X-X-Sender: bhurt@localhost.localdomain To: Flavio Leonardo Cavalcanti de Moura cc: caml-list@inria.fr Subject: Re: [Caml-list] actualize a string In-Reply-To: <20031023152601.U5169-100000@mx1.mat.unb.br> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 actualize:99 reductions:01 actualize:99 clue:01 ocaml:01 assert:02 match:02 string:03 string:03 wrote:03 oct:03 types:03 iter:03 let:04 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, 23 Oct 2003, Flavio Leonardo Cavalcanti de Moura wrote: > I am trying to build a procedure such that some reductions are > performed while a list (of redex) is not empty. The problem is that a > new list is needed at each step otherwise it will loop for ever. The > actual code is > > let normal exp = > let l = exp :: [] in > while (matchingApp exp [] []) <> [] do > exp := (appreduction exp (hd (matchingApp exp [] []))); > exp :: l done; l;; > > After the 'while' I would like to actualize the expression 'exp' with the > string (appreduction exp (hd (matchingApp exp [] []))). The problem is > that with := it does not work. How can I do that? I couldn't find anything > in the ocaml manual. I'm not 100% sure what you're trying to do here. Applying a function to every member of a list is easy- look at List.iter and List.fold_left. fold_left is especially useful for "accumulating" a result over the list. I think what you want to do is: let normal exp = let f l x = match l with | [] -> assert false | h :: t -> (appreduction h x) :: t in List.fold_left f [ exp ] (matchingApp exp [] []) ;; but I'm not sure. Give me a clue: what are the types of matchingApp and appreduction? Brian ------------------- 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