From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id D811BBB91 for ; Fri, 10 Dec 2004 13:13:10 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id iBACDALc027470 for ; Fri, 10 Dec 2004 13:13:10 +0100 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id NAA04410 for ; Fri, 10 Dec 2004 13:13:10 +0100 (MET) Received: from annexia.force9.co.uk (annexia.force9.co.uk [212.56.101.183]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id iBACD90U014653 for ; Fri, 10 Dec 2004 13:13:09 +0100 Received: from rich by annexia.force9.co.uk with local (Exim 3.36 #1 (Debian)) id 1Ccjdz-000819-00; Fri, 10 Dec 2004 12:13:07 +0000 Date: Fri, 10 Dec 2004 12:13:06 +0000 Cc: caml-list@inria.fr, "HENRIKSON, JEFFREY" Subject: Re: [Caml-list] environment idiom Message-ID: <20041210121306.GB29002@annexia.org> References: <9410EC84C0872141B27A2726613EF45D02A52E08@psmrdcex01.psm.pin.safeco.com> <41B97FD7.50309@andrej.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="f2QGlHpHGjS2mn6Y" Content-Disposition: inline In-Reply-To: <41B97FD7.50309@andrej.com> User-Agent: Mutt/1.5.6+20040722i From: Richard Jones X-Miltered: at concorde with ID 41B992D6.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 41B992D5.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 rec:01 derives:01 modular:01 parsing:01 parsing:01 user-agent:01 rec:01 compiler:01 lesson:98 writes:01 idiom:01 inefficient:01 functions:01 functions:01 X-Attachments: type="application/pgp-signature" name="signature.asc" X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.0 X-Spam-Level: --f2QGlHpHGjS2mn6Y Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable The specific data that Jeff wants to pass around are: cgi - The CGI environment r - The Apache request_rec (in fact, cgi#request =3D=3D request, but sometimes it's slightly more convenient to have it as a separate parameter) dbh - The database handle hostid - The host ID (COCANWIKI supports multiple virtual hosts) host - The "host object" which contains other host-related info user - The "user object" which contains info on the logged-in user In theory one can derive all of the above from just cgi and dbh, but it's very inefficient to do this because it would require making database requests. For practical and efficiency reasons COCANWIKI derives the hostid, host and user with just 2 database queries at the beginning of every HTTP request. COCANWIKI is fairly modular. For instance it has a library function to handle the parsing of the Wiki markup, prototyped (currently) as: Wikilib.xhtml_of_content : Dbi.connection -> int (*hostid*) -> string (*markup*) -> string (*XHTML*) The reason that this function needs a database handle and hostid is because parsing Wiki markup is sensitive to the content of the database. If someone writes [[Page]] we need to write different things depending on whether there is a page in the database called "Page". Jeff wants to extend xhtml_of_content in a way that also requires browser sniffing (ie. fetching the User-Agent header from the Apache request_rec object). So we need another parameter. But xhtml_of_content is far from being a monolithic function at the moment. It is, in fact, divided up into many many smaller functions which handle different parts of the parsing, and for various (wrong) reasons those are written as separate, not nested functions. The same problem of needing to pass around chains of extra "environment" arguments occurs all over in these libraries. Personally I really like Jeff's "anonymous object" trick, because the compiler works out for you which "environment" bits are needed by the library function, and you can just make the right object on the fly when calling the function. Rich. --=20 Richard Jones. http://www.annexia.org/ http://www.j-london.com/ >>> http://www.team-notepad.com/ - collaboration tools for teams <<< Merjis Ltd. http://www.merjis.com/ - improving website return on investment http://subjectlink.com/ - Lesson plans and source material for teachers --f2QGlHpHGjS2mn6Y Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFBuZLS4le1M6q9pzoRAmmzAJ9JotxjU6nB7gU/ZU/YZrLbZlI/4QCglTYb sW368K+PKIh4ZgJ+Rg4uB20= =TLFm -----END PGP SIGNATURE----- --f2QGlHpHGjS2mn6Y--