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 concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 12D75BC6B for ; Wed, 27 Jun 2007 15:58:55 +0200 (CEST) Received: from pih-relay06.plus.net (pih-relay06.plus.net [212.159.14.133]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l5RDwsUU006349 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Wed, 27 Jun 2007 15:58:54 +0200 Received: from [80.229.56.224] (helo=beast.local) by pih-relay06.plus.net with esmtp (Exim) id 1I3Y2n-0005aC-CX for caml-list@yquem.inria.fr; Wed, 27 Jun 2007 14:58:53 +0100 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] The Implicit Accumulator: a design pattern using optional arguments Date: Wed, 27 Jun 2007 14:53:05 +0100 User-Agent: KMail/1.9.7 References: <200706271314.35134.jon@ffconsultancy.com> <1A1D6F56-B3DB-4552-969C-9859482175AC@lrde.epita.fr> In-Reply-To: <1A1D6F56-B3DB-4552-969C-9859482175AC@lrde.epita.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200706271453.06045.jon@ffconsultancy.com> X-Miltered: at concorde with ID 46826D1E.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 compiler:01 memoize:01 hashtbl:01 hashtbl:01 val:01 memoizing:01 ocaml:01 2007,:98 frog:98 equality:01 parsing:01 wrote:01 wrote:01 caml-list:01 On Wednesday 27 June 2007 14:18:07 Qu=F4c Peyrot wrote: > On Jun 27, 2007, at 2:14 PM, Jon Harrop wrote: > > Provided performance is unimportant... > > Could you be more specifics about the performance hit? Actually, no. I have no quantitative results but I remember that it is=20 significant. > I was quite happy with this solution, but maybe there is something > more elegant to do? Nice. :-) > (I'm still in the process of learning good optimization patterns in > ocaml which preserve readability) I was going to mention symbol tables to Raj B for his Python JIT compiler b= ut=20 he hasn't gotten back to me yet. Basically, you memoize strings: # let symbol =3D let m =3D Hashtbl.create 1 in fun string -> try Hashtbl.find m string with Not_found -> Hashtbl.add m string string; string;; val symbol : '_a -> '_a =3D This is another trick I learned whilst writing my Mathematica interpreter (= so=20 many tricks, so little time). This function looks totally pointless, like a= =20 no-op, but if you pipe your identifiers through it (e.g. when building the= =20 AST during parsing) then all structurally-equal strings are the same physic= al=20 string. If you're careful, this lets you use physical equality for string=20 comparison and that is a lot faster. You might do something similar by memoizing temporary strings of different= =20 lengths. =2D-=20 Dr Jon D Harrop, Flying Frog Consultancy Ltd. The OCaml Journal http://www.ffconsultancy.com/products/ocaml_journal/?e