lua-users home
lua-l archive

Re: Proposal: improvement of string.gsub()

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Monday 18 April 2005 4:55 am, Gavin Wraith wrote:
> Unfortunately this breaks referential transparency - a bad idea.
> The usual remedy for string manipulation is never to concatenate
> strings, but instead to use "stringles" - lists whose components
a similar solution is to change the underlying language implementation to 
something more appropriate. the STL includes a 'rope' template. the idea is 
similar to your 'stringles': a tree of strings. the main difference is that 
the language itself manages them. also, it's possible to use ref-counted 
copy-on-write string leaves, so that this code:
a="big string"
b=a.."suffix"
would reuse the 'big string'
in fact, when i first read about Lua, i saw in the doc that "unlike C strings, 
Lua strings are appropriate for big texts", and i hoped that meant it used 
ropes... but later i saw it wasn't so.
on a related issue: in LTN9, there's the advice not to build big strings by 
accumulation, instead it uses a stack and merges it down in a binary 
algorithm.
i ask: what about building an array with table.insert() and get the final 
string with table.concat()? isn't that faster/easier? maybe LTN9 is too 
old?
-- 
Javier

Attachment: pgpf1Yi6D6lIn.pgp
Description: PGP signature


AltStyle によって変換されたページ (->オリジナル) /