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=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 28D0CBC6B for ; Wed, 27 Jun 2007 22:17:23 +0200 (CEST) Received: from sccmmhc92.asp.att.net (sccmmhc92.asp.att.net [204.127.203.212]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l5RKHMCK007863 for ; Wed, 27 Jun 2007 22:17:22 +0200 Received: from [192.168.0.104] (12-208-242-210.client.mchsi.com[12.208.242.210]) by sccmmhc92.asp.att.net (sccmmhc92) with SMTP id <20070627201720m9200d93o6e>; Wed, 27 Jun 2007 20:17:21 +0000 In-Reply-To: <4682AD06.9080008@janestcapital.com> References: <200706271314.35134.jon@ffconsultancy.com> <46828488.3000006@SmokejumperIT.com> <200706271548.l5RFmiS04436@virtutech.se> <200706271906.07626.jon@ffconsultancy.com> <4682AD06.9080008@janestcapital.com> Mime-Version: 1.0 (Apple Message framework v752.3) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <2F62C393-2EE0-470F-9781-E85B855201B6@valdosta.edu> Cc: caml-list@yquem.inria.fr Content-Transfer-Encoding: 7bit From: Jonathan Bryant Subject: Re: [Caml-list] The Implicit Accumulator: a design pattern using optional arguments Date: Wed, 27 Jun 2007 16:17:09 -0400 To: Brian Hurt X-Mailer: Apple Mail (2.752.3) X-Miltered: at concorde with ID 4682C5D2.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; regexps:01 scanf:01 scanf:01 foo:01 baz:01 foo:01 compiler:01 baz:01 2007,:98 $1,:98 wrote:01 matched:01 caml-list:01 int:01 int:01 On Jun 27, 2007, at 2:31 PM, Brian Hurt wrote: > Actually, what I'd like is a more powerful regular expression engine- This is off the top of my head, but I've always thought it would be nice to have built-in regexps using a Scanf style. Instead of using $1, $2 (or \1, \2, depending on your language), have each parenthesized argument be passed to a function, and the whole thing is a function of a string parameter. If a scanf conversion is used, that is the type passed to the function, otherwise it's simply passed as a string. Something like: # let re = /(foo|bar|baz)/ (fun x -> match x with | "foo" -> ... etc ... );; re : string -> 'a = # let simple_phone_number = /(%d)-(%d)-(%d)/ (fun x y z -> (x,y,z) );; simple_phone_number : string -> (int * int * int) = I don't know how hard this would be to implement. It would require some scanf style compiler magic, but it overcomes scanf's shortcoming that it doesn't allow character classes. It might even be possible for use in pattern matching: # let f str = match str with | /foo/ -> (* It's a foo *) | /bar/ -> (* It's a bar *) | /baz/ -> (* It's a baz *) | /(%d)-(%d)-(%d)/ -> (* It's a phone number *) | _ -> (* Not matched *) ;; f : string -> 'a = Any idea how hard this would be? --Jonathan