From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 832DCBB81 for ; Wed, 28 Dec 2005 10:36:08 +0100 (CET) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.201]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jBS9a60U001118 for ; Wed, 28 Dec 2005 10:36:07 +0100 Received: by wproxy.gmail.com with SMTP id i24so424260wra for ; Wed, 28 Dec 2005 01:36:06 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=ElutCBw7nyMpQw80BBVCdHUYaIx7PtOhVBQhexgXRP9k0oGo7MAjaU90dRCnLUvuIgpYjCGc+g31cd3J9Rk7VLvSK+JVZn6UV5zne7JOEfKJRiaa9ccd21aApy/f3GTlYg+ceOHarVNX/GBPshos5e6a0wYgUZY1t5BzeBoE+gI= Received: by 10.64.21.10 with SMTP id 10mr2154242qbu; Wed, 28 Dec 2005 01:36:06 -0800 (PST) Received: by 10.65.22.19 with HTTP; Wed, 28 Dec 2005 01:36:06 -0800 (PST) Message-ID: Date: Wed, 28 Dec 2005 22:36:06 +1300 From: Jonathan Roewen To: Stephen Brackin Subject: Re: [Caml-list] Ask-if-continue wrapper? Cc: caml-list@yquem.inria.fr In-Reply-To: <0IS700AHX9M9TKT2@vms042.mailsrvcs.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <0IS700AHX9M9TKT2@vms042.mailsrvcs.net> X-Miltered: at nez-perce with ID 43B25C86.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 threads:01 val:01 val:01 rec:01 ocaml:01 inputs:01 inputs:01 denotes:01 o'reilly:01 caml-list:01 beginner's:01 beginners:01 bug:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_BY_IP autolearn=disabled version=3.0.3 Sounds like you'd need continuations to do it nicely/properly. I have no idea if it's possible to support continuations in ocaml. But why not use a couple of threads? Something like: let continueq f args timeout timeout_val =3D let result =3D ref timeout_val in let on_done =3D ref (fun () -> ()) in (* hack cause I dunno how to get around the order of declarations *) let do_computation () =3D result :=3D f args; !on_done () in let comp_t =3D Thread.create do_computation () in let rec do_timeout t =3D if t <=3D 0 then Thread.kill comp_t else begin Thread.delay (float_of_int t); print_string "set timeout: "; do_timeout (read_int ()); end in let timeout_t =3D Thread.create do_timeout timeout in on_done :=3D (fun () -> Thread.kill timeout_t); Thread.join timeout_t; !result;; Very ugly, but should do what you want. I have to add that one of the thread implementations for ocaml doesn't implement Thread.kill -- I can't remember which -- which would break this horribly :-| Jonathan On 12/28/05, Stephen Brackin wrote: > > > I'd like an OCaml function, which I'll call continueq, with the property > that for any function f with argument(s) fargs, > > continueq f fargs tsecs defaultval > > starts evaluating f on fargs and lets this evaluation proceed for up to > tsecs seconds. If the computation of (f fargs) completes in this time, th= en > it returns the result of that computation. Otherwise, it asks the user ho= w > many seconds to let the computation of (f fargs) proceed. If the user inp= uts > a value less than or equal to 0, then it returns defaultval. If the user > inputs a value tsecs' greater than 0, then it evaluates > > continueq f' fargs' tsecs' defaultval > > where (f' fargs') denotes the computation state of (f fargs) at the time = it > was interrupted. > > I want to give the user the option of continuing without having to repeat > earlier calculations. This is similar to the checkpoint utility ckpt, and > similar to the "timeout" function described in the O'Reilly "'Developing > Applications with Objective Caml" reference book, but not quite the same = as > either. Will someone please tell me how to do it? > > Steve > > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: > http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > >