[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [StrongED] Roman numerals
On 15 Aug 2017 Gavin Wraith <gavin@xxxxxxxxxxxxxxx> wrote:
> Found it. This strongED script evaluates a Roman numeral
> given as the first word of a textfile, if you have
> RiscLua 6.3. Open the textfile in StrongED and drag
> a textfile containing the following onto its Apply
> icon.
> #! lua
> -- Roman Numerals
> local add = \ (x, y) => x + y end
> local P, Cf, Cc in require "lpeg"
> local symbs = { I = 1, V = 5, X = 10, L = 50,
> C = 100, D = 500, M = 1000, IV = 4, IX = 9,
> XL = 40, XC = 90, CD = 400, CM = 900 }
> for s, n in pairs (symbs) do
> _ENV[s:lower ( )] = P (s) * Cc (n)
> end -- for
> local MS = m^0
> local CS = ( d * c^(-4) + cd + cm + c^(-4) )^(-1)
> local XS = ( l * x^(-4) + xl + xc + x^(-4) )^(-1)
> local IS = ( v * i^(-4) + ix + iv + i^(-4) )^(-1)
> local roman = MS * CS * XS * IS
> local pat = Cf (Cc (0) * roman, add)
> local input, read in io
> input (arg[1])
> local s = read "*a"
> input ( )
> local result = pat:match (s: upper ( ))
> print (result or "?")
Thanks again, Gavin. A shorter error message this time!
/SCSI.$/Utilities/!rlua6/lua6 <StrongED$Script_Script>:4:
unexpected symbol near '"lpeg"
My RiscLua is< I think, 6.0. Should I get the latest one?
Best wishes,
Peter.
--
Peter Young (zfc Pt) and family
Prestbury, Cheltenham, Glos. GL52, England
http://pnyoung.orpheusweb.co.uk
pnyoung@xxxxxxxxxxxx
--=20
To unsubscribe send a mail to StrongED+unsubscribe@xxxxxxxxxxx
List archives at http://www.Torrens.org/RO/StrongED/index.html