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 GAA21462; Sat, 14 Jul 2001 06:16:09 +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 GAA21484 for ; Sat, 14 Jul 2001 06:16:08 +0200 (MET DST) Received: from str12.sobor.org (adsl-63-198-183-99.dsl.snfc21.pacbell.net [63.198.183.99]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f6E4G7D00612; Sat, 14 Jul 2001 06:16:07 +0200 (MET DST) Received: from quasar.ipa.nw.ru (anza.sobor.org [192.168.123.51]) by str12.sobor.org (Postfix) with ESMTP id EF13EAC6D9; Fri, 13 Jul 2001 21:02:59 -0700 (PDT) Message-ID: <3B4FC748.F9E14008@quasar.ipa.nw.ru> Date: Fri, 13 Jul 2001 21:15:04 -0700 From: "Alexander V. Voinov" Organization: Fear of the Lord is the beginning of wisdom X-Mailer: Mozilla 4.75 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 To: Daniel de Rauglaudre Cc: "caml-list@inria.fr" Subject: Re: [Caml-list] Generation of streams is slow References: <3B4F70D7.82E58A91@quasar.ipa.nw.ru> <20010714042701.A24266@verdot.inria.fr> <3B4FB39D.10D1F6D5@quasar.ipa.nw.ru> <20010714060417.A25766@verdot.inria.fr> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi Daniel, Daniel de Rauglaudre wrote: > > Yes, the difference is substantial, but it gets longer and longer anyway > > with more elements parsed (for a slightly more complex program, which > > parses the stream as it is generated) and crashes at some point. > > I did not test, but looking at your code, I see that neither parse_stream > nor parse_stream' is tail recursive! It is not a question of parsers, now: > your recurive calls are never the last action. > > Perhaps this version would work (not tested): > > let rec parse_stream list s = > match s with parser > [< 'i; s' >] -> begin > if i mod 1000 = 0 then begin > printf "picked element %d\n" i; > flush stdout > end; > parse_stream (i :: list) s' > end > | [< >] -> (printf "end\n"; flush stdout; List.rev list) I see, Prolog habits are hard to leave. But this solution doesn't look as "natural" as mine, and requires additional time to reverse the result. I try to acquire hints for the everyday use, of lists and other abstract sequences in this case. Not just a particular problem to solve. Alexander ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr