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 9A354BB9C for ; Wed, 23 Nov 2005 22:30:17 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jANLUG26019485 for ; Wed, 23 Nov 2005 22:30:17 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA10971 for ; Wed, 23 Nov 2005 22:30:16 +0100 (MET) Received: from ash25e.internode.on.net (ash25e.internode.on.net [203.16.214.182]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jANLUEoW006204; Wed, 23 Nov 2005 22:30:15 +0100 Received: from rosella (ppp45-3.lns2.syd6.internode.on.net [59.167.45.3]) by ash25e.internode.on.net (8.12.9/8.12.6) with ESMTP id jANLU4m1043799; Thu, 24 Nov 2005 08:00:05 +1030 (CST) (envelope-from skaller@users.sourceforge.net) Subject: Re: [Caml-list] Request for complete pattern matching From: skaller To: Martin Jambon Cc: Luc Maranget , Christophe Raffalli , sejourne_kevin , caml-list In-Reply-To: References: <43839F1A.2080909@univ-savoie.fr> <43842069.3070700@yahoo.fr> <43848103.9060504@univ-savoie.fr> <20051123183134.GB6446@yquem.inria.fr> Content-Type: text/plain Date: Thu, 24 Nov 2005 08:30:04 +1100 Message-Id: <1132781404.25948.78.camel@rosella> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 4384DF68.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 4384DF66.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 endline:01 endline:01 regexps:01 ocaml:01 regexps:01 'when':01 wrote:01 sourceforge:01 matched:01 functions:01 expression:01 jambon:01 patterns:02 match:02 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=none autolearn=disabled version=3.0.3 On Wed, 2005-11-23 at 12:56 -0800, Martin Jambon wrote: > (* toto.ml *) > try > while true do > match read_line () with > / upper / | / _* "." eos / -> print_endline "looks like a sentence" > | "." | / ("bye"~ space*)+ / -> print_endline "Bye!"; exit 0 > | _ -> print_endline "???" > done > with End_of_file -> () > > Notes: > - the stuff between slashes are regexps > - "." and the last _ are regular OCaml patterns > - regexps are replaced by an identifier which is matched after the > arrow using library functions, then it is decided whether to jump to the > next case or to execute the user-given expression. Why can't this be done with 'when' clause? EG: | ... predicate ... -> ... replace by | ... variable .. when predicate(variable) This would seem to fail only in that 'predicate' code cannot refer to another predicate, since the variable name is not known. The 'break' implementation, however, may be overtly more efficient (save duplicating predicate evaluations). -- John Skaller Felix, successor to C++: http://felix.sf.net