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 QAA18363; Fri, 8 Oct 2004 16:21:39 +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 QAA18352 for ; Fri, 8 Oct 2004 16:21:38 +0200 (MET DST) Received: from smtp005.mail.ukl.yahoo.com (smtp005.mail.ukl.yahoo.com [217.12.11.36]) by nez-perce.inria.fr (8.13.0/8.13.0) with SMTP id i98ELbic024698 for ; Fri, 8 Oct 2004 16:21:37 +0200 Received: from unknown (HELO yahoo.fr) (sejourne?kevin@83.114.100.23 with plain) by smtp005.mail.ukl.yahoo.com with SMTP; 8 Oct 2004 14:21:37 -0000 Message-ID: <4166A395.70301@yahoo.fr> Date: Fri, 08 Oct 2004 16:26:29 +0200 From: sejourne_kevin User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040528 Debian/1.6-7 X-Accept-Language: fr-fr MIME-Version: 1.0 To: Luca Pascali CC: caml-list@inria.fr Subject: Re: [Caml-list] Recursive lists References: <41669437.3010201@yahoo.it> In-Reply-To: <41669437.3010201@yahoo.it> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Miltered: at nez-perce with ID 4166A271.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 buffer:01 she:98 rec:01 rec:01 exists:01 overflow:02 overflow:02 stack:02 wrote:03 recursive:03 recursive:03 obj:03 obj:03 library:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Luca Pascali wrote: > Hi everyone. > > I have a little question about the recursive lists. > In an application I needed to use a list composed by some elements > (placed in the head of the list) and recursive element, like > > let rec_list = > let rec l2 = 100 :: l2 in > [1;2;3;4;5] @ l2 > > in order to have the last elements periodically repeated. > In a list like this, I found that the map function goes in stack > overflow. It seems that it is not aware of the recursive characteristics > of the input list. > I had to write a version of the map function to support this in my > software (I have to finalize something before posting it). > > My questions are: > Can some functions of the List library support the use of the recursive > lists? > I mean: can some scanning functions such as map, for_all, exists, mem, > filter, and so on understand if they are working on recursive lists and > act correctly without going in buffer overflow or infinite loops? > Did anyone already have a similar needing? And in which way did he/she > work? > > Thanks in advance to anyone > > Luca > > (** Take a list and connect the end on the beginning Copyright : Kévin ;) *) let cycle l = let rl= ref l in let rec go_fin = function [] -> invalid_arg "cycle:[] can't be !" | [x] as f -> Obj.set_field (Obj.repr f) 1 (Obj.repr !rl);l | x::reste-> go_fin reste in go_fin l ;; I haven't test GC issu. ------------------- 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