From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/46991 Path: news.gmane.org!not-for-mail From: "Thomas A. Schmitz" Newsgroups: gmane.comp.tex.context Subject: Re: lua questions Date: Fri, 23 Jan 2009 14:04:31 +0100 Message-ID: <5BEDCB43-C327-46EA-AB92-480BA2A0F450@uni-bonn.de> References: <8FF223F7-EFDC-43BD-8765-CBB15A03DBAD@uni-bonn.de> <4979A64B.1080906@wxs.nl> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v930.3) Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"; DelSp="yes" Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1232716039 6083 80.91.229.12 (23 Jan 2009 13:07:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 23 Jan 2009 13:07:19 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Fri Jan 23 14:08:32 2009 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from ronja.vet.uu.nl ([131.211.172.88] helo=ronja.ntg.nl) by lo.gmane.org with esmtp (Exim 4.50) id 1LQLlv-0004wn-4q for gctc-ntg-context-518@m.gmane.org; Fri, 23 Jan 2009 14:08:31 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id CC6741FE54; Fri, 23 Jan 2009 14:07:10 +0100 (CET) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (smtp.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 22698-07; Fri, 23 Jan 2009 14:06:08 +0100 (CET) Original-Received: from ronja.vet.uu.nl (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 94DA41FE20; Fri, 23 Jan 2009 14:06:08 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 13F6D1FE20 for ; Fri, 23 Jan 2009 14:06:05 +0100 (CET) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (smtp.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 01859-02 for ; Fri, 23 Jan 2009 14:05:24 +0100 (CET) Original-Received: from filter3-til.mf.surf.net (filter3-til.mf.surf.net [194.171.167.219]) by ronja.ntg.nl (Postfix) with ESMTP id 7167F1FD47 for ; Fri, 23 Jan 2009 14:05:24 +0100 (CET) Original-Received: from mailout07.t-online.de (mailout07.t-online.de [194.25.134.83]) by filter3-til.mf.surf.net (8.13.8/8.13.8/Debian-3) with ESMTP id n0ND5MAj004806 for ; Fri, 23 Jan 2009 14:05:23 +0100 Original-Received: from fwd08.aul.t-online.de by mailout07.sul.t-online.de with smtp id 1LQLis-0002mU-00; Fri, 23 Jan 2009 14:05:22 +0100 Original-Received: from [192.168.0.2] (ZGqfjyZBwhIPrEUC1dz14abjgsxKXtmiQuSXrharI4yiJEnB8WBJJyfLcafbcYJQBj@[87.178.85.108]) by fwd08.aul.t-online.de with esmtp id 1LQLi3-1jXluC0; Fri, 23 Jan 2009 14:04:31 +0100 In-Reply-To: <4979A64B.1080906@wxs.nl> X-Mailer: Apple Mail (2.930.3) X-ID: ZGqfjyZBwhIPrEUC1dz14abjgsxKXtmiQuSXrharI4yiJEnB8WBJJyfLcafbcYJQBj@t-dialin.net X-TOI-MSGID: a029eeeb-bea0-44e9-b953-5cbefc55b329 X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=194.25.134.83; country=DE; region=05; city=Weiterstadt; latitude=49.9078; longitude=8.5953; http://maps.google.com/maps?q=49.9078,8.5953&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 169651520 - 3ecf223d43dc X-Scanned-By: CanIt (www . roaringpenguin . com) on 194.171.167.219 X-Virus-Scanned: amavisd-new at ntg.nl X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.11 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl X-Virus-Scanned: amavisd-new at ntg.nl Xref: news.gmane.org gmane.comp.tex.context:46991 Archived-At: On Jan 23, 2009, at 12:13 PM, Hans Hagen wrote: > > here is a variant that implements a function (and does not use the = > env trick) > > do > local add =3D function (x,y) return x+y end > local P,Ca,Cc=3D lpeg.P,lpeg.Ca,lpeg.Cc > local symbols =3D = > { I=3D1,V=3D5,X=3D10,L=3D50,C=3D100,D=3D500,M=3D1000,IV=3D4,IX=3D9,XL=3D4= 0,CD=3D400,CM=3D900} > local adders =3D { } > for s,n in pairs(symbols) do adders[s] =3D P(s)*Cc(n)/add end > local MS =3D adders.M^0 > local CS =3D (adders.D*adders.C^(-4)+adders.CD+adders.CM = > +adders.C^(-4))^(-1) > local XS =3D (adders.L*adders.X^(-4)+adders.XL+adders.X^(-4))^(-1) > local IS =3D (adders.V*adders.I^(-4)+adders.IX+adders.IV = > +adders.I^(-4))^(-1) > local p =3D Ca(Cc(0)*MS*CS*XS*IS) > function string:romantonumber() > return p:match(self:upper()) > end > end > > print(string.romantonumber("MMIX")) > print(string.romantonumber("MMIIIX")) > > > just run such script using > > mtxrun --script yourscript.lua > > as luatex (texlua) has the latest lpeg built in) > Brilliant! This one does work when I use it with luatex (not with my = system lua though, even though I have the latest released version of = lpeg 0.9 installed. Bizarre... > >> 2. How can I check if a string begins with a class of words "(Der | = >> Die |Das |The |An )" etc. and strip these words from the string? I = >> do it with a compiled regexp in python, but "Programming in lua" = >> has this to say: "Unlike some other systems, in Lua a modifier can = >> only be applied to a character class; there is no way to group = >> patterns under a modifier. For instance, there is no pattern that = >> matches an optional word (unless the word has only one letter). = >> Usually you can circumvent this limitation using some of the = >> advanced techniques that we will see later." I haven't found these = >> techniques yet. > > local stripped =3D { > "Der", "Die", "Das" > } > > local p =3D lpeg.P(false) > > for k, v in ipairs(stripped) do > p =3D p + lpeg.P(v) > end > > local w =3D p * " " > > local stripper =3D lpeg.Cs(((w/"") + lpeg.C(1))^0) > > lpeg.print(stripper) > > str =3D "Germans somehow always talk about Der Thomas and Der Hans" > > print(stripper:match(str)) > Brilliant again! I can run with that, looks great! And who doesn't = want a "local stripper" in his code? > >> 3. How can I compare strings with utf8 characters? My naive approach >> if string.find(record, "R=E9sum=E9") >> doesn't appear to work (while the same method does work if the = >> string has only ASCII characters). > > since lua is 8 bit clean utf should just work OK, then the problem must be somewhere else. I'll investigate. Thanks a lot, and best wishes Thomas ___________________________________________________________________________= ________ If your question is of interest to others as well, please add an entry to t= he Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-cont= ext webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________= ________