[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Thought experiment: what would you remove from Lua
- From: dyngeccetor8 <dyngeccetor8@...>
- Date: Wed, 1 Aug 2018 19:28:33 +0300
> On 1 August 2018 at 09:55, dyngeccetor8 <dyngeccetor8@disroot.org> wrote:
>
>> * string.reverse() (anyone used it?)
On 08/01/2018 08:25 AM, Vaughan McAlley wrote:
> I was using it when "deleting" a string—going through the string
> backwards and simulating appropriate keystrokes to delete that
> character. Then I changed to going backwards through the string by
> UTF-8 codepoint, so had to think of something else.
>
> Vaughan
On 08/01/2018 09:00 AM, Dirk Laurie wrote:
> **_`The quick brown fox jumps over the lazy dog`_**
>
> I assemble the starting markdown sequence from the font information
> and then the ending is done by string.reverse.
On 08/01/2018 02:12 PM, Albert Chan wrote:
> My script calc.lua used it to search for last ";"
>
> Calc a=3; b=7; c=10; b*b - 4*a*c
>
> => lua calc.lua "a=3; b=7; c=10; b*b - 4*a*c"
> => -71
>
> t= s:reverse():find(';', 2, 'plain') -- locate last ;
>
> if t then -- multi-statements detected
> s = "function()" .. s:sub(1, -t) ..
> " return " .. s:sub(-t+1) ..
> " end)()"
> end
> print( loadstring("return " .. s)() ) -- evaluate
Wow! String reversing function is surprisingly practical!
And I like this code snippet from Albert Chan: short, simple
and useful. Clever usage of negative offsets.
My vision on string manipulations improved. Thank you guys!
-- Martin