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 QAA17614; Fri, 8 Oct 2004 16:05:54 +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 QAA17603 for ; Fri, 8 Oct 2004 16:05:53 +0200 (MET DST) Received: from mailhost.tni.fr (firewall.tni.fr [195.25.255.61]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id i98E5qJ9022726 for ; Fri, 8 Oct 2004 16:05:53 +0200 Received: from groscool.tni.fr ([195.25.255.61]) by mailhost.tni.fr (Netscape Messaging Server 3.62) with SMTP id 1669; Fri, 8 Oct 2004 16:05:59 +0200 Received: from 195.7.123.178 by groscool.tni.fr (InterScan E-Mail VirusWall NT); Fri, 08 Oct 2004 16:05:59 +0200 Message-ID: <41669EAA.7000509@tni-software.com> Date: Fri, 08 Oct 2004 16:05:30 +0200 From: =?ISO-8859-1?Q?S=E9bastien_Furic?= User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.3) Gecko/20040910 X-Accept-Language: en-us, en 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 41669EC0.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; furic:01 furic:01 caml-list:01 buffer:01 delivers:99 she:98 ocaml:01 caml:01 rec:01 rec:01 exists:01 lazy:02 lazy:02 overflow:02 overflow:02 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 > > You can use lazy lists to solve the problem. A lazy list delivers its elements on demand so you can manipulate infinite lists safely provided you don't print their whole contents for instance... See http://caml.inria.fr/archives/200304/msg00280.html to see how to implement them (they're not present in the OCaml distribution). Sébastien. ------------------- 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