lua-users home
lua-l archive

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


2012/2/15 steve donovan <steve.j.donovan@gmail.com>:
> Hi all,
>
> Inspired by Jay's challenge to keep it simple & stupid, I've come up
> with thirty-odd functions that cover a lot of the general boilerplate
> code we end up writing. 'Microlight' because it's the trimmed-down
> younger brother of Penlight, about 500 lines in total, of which 160
> are doc comments.
>
> https://gist.github.com/1834789
>
> And the extracted docs are at
>
> http://stevedonovan.github.com/microlight/
>
> I was aiming at about 25 functions (which felt like a good number) but
> naturally these things develop a momentum of their own; so I'm open to
> dropping some to get something that fits nicely in the average head.
>
> There is no 'shallow copy', but it's easy to make such a function.
> extend(t,other) _extends_ an existing list-like table, and
> update(t,other) _updates_ a map-like table with new key-value pairs.
> So
>
> icopy = bind1(extend,{})
> tcopy = bind1(update,{})
>
> There's also compose(), so that printf = compose(io.write,string.format).
>
> There is a reasonably robust table dumper, but it's not pretty;
> however it detects cycles and has a maximum-limit cut-off.
>
> Not exhaustively tested - mostly culled from Penlight itself, which is
> fairly well tested.  The aim in any case is to make an _executable
> proposal_ for a group of straightforward functions.  It's particularly
> hard to name things, so I need some help there.
>
> (I threw in a reasonably brain-dead class implementation, just for luck)
>
> steve d.
>

It's must a great module of lua!

I have some suggest.

first, may be we can split this module into some sub module. I mean,
ml.string/ml.table/ml.functional etc. it would be better. I think we
can using Python's struct to split ml module. makes using ml just like
using Python in lua.

then, maybe we can "export" ml's library into global, we can use ml with:

local ml = require 'ml'
-- using ml.table

or
local ml_table= require 'ml.table'
-- using ml_table

or
require 'ml.table'.export(_ENV)
-- using table

maybe we can list a function list to implement, we can open a ml
project in github.

after all, some of ml function are better implement in C API. maybe we
can offer ml.lua and ml.c, given C and lua implement of ml.

Is that worth? we can discuss a function list in ml, and I have time
to implement then in C. some of things I though:

ml.string:
  escape
* unescape
  expand
  readfile
* writefile
  split
* join (maybe named ijoin, join(sep, ...))

ml.path:
  exists
  splitpath
  splitext
* join (just like string.join, but using default path sep)
  simplify (remove /./, process /../ and change different directory
sep to the same, etc.)
* relpath (return abspath of a relate path)
* abspath (using curdir and relpath)

ml.table:
  tostring
  dump
  map
  filter
  reduce
  find
  index
  sub
  update
  extend
  set
  keys
  values
  subset
  equal
  intersect
  collect
* sort_pairs (sort a table, and return a iterator of sorted table)

ml.vararg:
  map (imap)
  filter (ifilter)
* reduce
* pack
* unpack
* append
* replace
* insert
* remove
* range

ml.functional:
  protect (was, safe)
* newtry (just like ones in luasocket)
  newthrow (a new function that will throws, was, throw)
* bind (it will implemented in C very easy)
  bind1
  compose
  callable

ml.class:
   (class itself is callable)
   isinstance (is-a)
   isinherit (is-a)
   isa (isinstance or isinerit)
   type (return the type of class)

class can be multiple inheritance, that we can cache
class-search-result into current class.

is this list complete yet?