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 C5F5FBC6B for ; Wed, 27 Jun 2007 17:09:01 +0200 (CEST) Received: from smtp21.orange.fr (smtp21.orange.fr [80.12.242.47]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l5RF91xn030427 for ; Wed, 27 Jun 2007 17:09:01 +0200 Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf2112.orange.fr (SMTP Server) with ESMTP id 4A2561C0009C for ; Wed, 27 Jun 2007 17:09:01 +0200 (CEST) Received: from [192.168.1.162] (ALagny-153-1-98-23.w90-3.abo.wanadoo.fr [90.3.145.23]) by mwinf2112.orange.fr (SMTP Server) with ESMTP id 23B931C00084 for ; Wed, 27 Jun 2007 17:09:01 +0200 (CEST) X-ME-UUID: 20070627150901146.23B931C00084@mwinf2112.orange.fr Mime-Version: 1.0 (Apple Message framework v752.2) In-Reply-To: <200706271453.06045.jon@ffconsultancy.com> References: <200706271314.35134.jon@ffconsultancy.com> <1A1D6F56-B3DB-4552-969C-9859482175AC@lrde.epita.fr> <200706271453.06045.jon@ffconsultancy.com> Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed Message-Id: <33C17DC1-4890-4997-A8B5-17E9C1940A5A@lrde.epita.fr> Content-Transfer-Encoding: quoted-printable From: =?ISO-8859-1?Q?Qu=F4c_Peyrot?= Subject: Re: [Caml-list] The Implicit Accumulator: a design pattern using optional arguments Date: Wed, 27 Jun 2007 17:09:00 +0200 To: caml-list@yquem.inria.fr X-Mailer: Apple Mail (2.752.2) X-Miltered: at concorde with ID 46827D8D.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; lrde:01 compiler:01 memoize:01 hashtbl:01 hashtbl:01 val:01 2007,:98 equality:01 parsing:01 wrote:01 caml-list:01 strings:01 strings:01 ast:02 string:02 On Jun 27, 2007, at 3:53 PM, Jon Harrop wrote: [...] > I was going to mention symbol tables to Raj B for his Python JIT =20 > compiler but > 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 =20 > interpreter (so > many tricks, so little time). This function looks totally =20 > pointless, like a > no-op, but if you pipe your identifiers through it (e.g. when =20 > building the > AST during parsing) then all structurally-equal strings are the =20 > same physical > string. If you're careful, this lets you use physical equality for =20 > string > comparison and that is a lot faster. It's a really nice trick indeed. --=20 Best Regards, Qu=F4c