lua-users home
lua-l archive

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


On Fri, Dec 28, 2012 at 11:19 AM, steve donovan
<steve.j.donovan@gmail.com> wrote:
> Cool, so I'll consistently use that.

Right! Next RC, no underscores (except function_arg, looks silly) Zip
at [1], updated docs at [2].

writefile() is indeed another useful little function. Toyed with
adding yet another optional argument to readfile() which would be the
argument you would pass to io.read, so 128 would read only those
bytes, '*l' would only read the first line, and so forth. But perhaps
we are getting into swiss army chainsaw territory.

Phillip Janda's exercises in functional composition have been very
helpful. His 'transmogrify' function is now here as imapfilter (and
aliased as Array.mapfilter).  It's a good match to the way Lua likes
to work, with functions returning either something useful or nothing.

    > = imapfilter(tonumber,{'one',1,'f',23,2})
    {1,23,2}

These are all built on the horribly general mapextend; not sure
whether this should be publically exported.


Array has been designed for extension, and has a mappers method for
creating map shortcuts (they actually use imapfilter which is a better
default)

    Strings = class(Array)

    Strings:mappers {  -- NB: note the colon: class method
        upper = string.upper,
        match = string.match,
    }

    local s = Strings{'one','two','three'}

    assert(s:upper() == Strings{'ONE','TWO','THREE'})
    assert(s:match '.-e$' == Strings{'one','three'})
    assert(s:sub(1,2):upper() == Strings{'ONE','TWO'})

Note the covariance of the sub method....

I've included a little script 'compress.lua' which knocks ml.lua down
from 28K to 13K; I intend to add extra annotations so that an
intelligent squisher tool would only link in the code that you use. So
if you just want a string splitter, then that will only add 12 lines
or so to your squished script.  Hard to do with general code without
heavyweight analysis, so I'll shape Microlight around this need.

steve d.

[1] http://stevedonovan.github.com/files/microlight-1.1.zip
[2] http://stevedonovan.github.com/microlight/