From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id E7842BC6D for ; Wed, 3 Oct 2007 00:24:15 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CADxiAkfBAkMt/2dsb2JhbAA X-IronPort-AV: E=Sophos;i="4.21,221,1188770400"; d="scan'208";a="2037647" Received: from vega.fmf.uni-lj.si (HELO postar.fmf.uni-lj.si) ([193.2.67.45]) by mail1-smtp-roc.national.inria.fr with ESMTP; 03 Oct 2007 00:24:15 +0200 Received: from localhost (unknown [192.168.5.1]) by postar.fmf.uni-lj.si (Postfix) with ESMTP id 38860181368 for ; Wed, 3 Oct 2007 00:24:15 +0200 (CEST) X-Virus-Scanned: amavisd-new at spam.fmf.uni-lj.si Received: from postar.fmf.uni-lj.si ([192.168.5.5]) by localhost (spam.fmf.uni-lj.si [192.168.5.1]) (amavisd-new, port 10024) with ESMTP id d51Oi1nLwDqw for ; Wed, 3 Oct 2007 00:24:14 +0200 (CEST) Received: from [192.168.1.101] (BSN-77-148-136.static.dsl.siol.net [193.77.148.136]) (Authenticated sender: bauer) by postar.fmf.uni-lj.si (Postfix) with ESMTP id C4983179FF8 for ; Wed, 3 Oct 2007 00:24:14 +0200 (CEST) Message-ID: <4702C50D.6040606@fmf.uni-lj.si> Date: Wed, 03 Oct 2007 00:24:13 +0200 From: Andrej Bauer Reply-To: Andrej.Bauer@andrej.com User-Agent: Thunderbird 1.5.0.13 (X11/20070824) MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Which control structure? References: <470290BC.8020604@fmf.uni-lj.si> In-Reply-To: <470290BC.8020604@fmf.uni-lj.si> Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; andrej:01 andrej:01 delimited:01 val:01 val:01 sml:01 caml-list:01 let:03 let:03 ugly:04 computing:05 anybody:07 structure:07 fun:08 bauer:09 If anybody cares, I can do what I want in SML/NJ using a particularly ugly combination of callcc and store, see below. Is there a sane way to achieve the same thing? I suspect I want delimited continuations, but I am not sure. ----- open SMLofNJ.Cont ; (* A perverse way of computing (p false, p true) by invoking p only once. *) fun two p = let val c = ref NONE (* here we store the continuation *) val a = ref NONE (* here we store p false *) val b = ref NONE (* here we store p true *) in (* store p true into a, and save the continuation *) a := SOME (p (callcc (fn k => (c := SOME k; true)))) ; (* see if we're hapenning the first or the second time *) if !b = NONE then ( (* first time around *) b := !a ; (* store p false into b *) (* reinvoke to compute p true *) let val SOME k = !c in throw k false end) else (* second time around *) let val SOME x = !a val SOME y = !b in (x, y) end end ----- Andrej