Skip to content

Latest commit

 

History

History
200 lines (131 loc) · 4.21 KB

script.md

File metadata and controls

200 lines (131 loc) · 4.21 KB

 

home roadmap issues ©2022,2023 by tim menzies

DOI

script.lua

   
script.lua : an example script with help text and a test suite
(c)2022, Tim Menzies <timm@ieee.org>, BSD-2 

USAGE:   script.lua  [OPTIONS] [-g ACTION]

OPTIONS:
  -d  --dump  on crash, dump stack = false
  -g  --go    start-up action      = data
  -h  --help  show help            = false
  -s  --seed  random number seed   = 937162211

ACTIONS:
  -g  the	show settings
  -g  rand	generate, reset, regenerate same
  -g  sym	check syms
  -g  num	check nums

Classes

obj(s:str) ⇒ t

create a klass and a constructor

SYM

Summarize a stream of symbols.

SYM.new(i) ⇒ SYM

constructor

SYM.add(i, x) ⇒ nil

update counts of things seen so far

SYM.mid(i, x) ⇒ n

return the mode

SYM.div(i, x) ⇒ n

return the entropy

NUM

Summarizes a stream of numbers.

NUM.new(i) ⇒ NUM

constructor;

NUM.add(i, n:num) ⇒ NUM

add n, update lo,hi and stuff needed for standard deviation

NUM.mid(i, x) ⇒ n

return mean

NUM.div(i, x) ⇒ n

return standard deviation using Welford's algorithm http://t.ly/nn_W

Misc support functions

Numerics

rint(lo, hi) ⇒ n

a integer lo..hi-1

rand(lo, hi) ⇒ n

a float "x" lo<=x < x

Lists

Note the following conventions for map.

  • If a nil first argument is returned, that means :skip this result"
  • If a nil second argument is returned, that means place the result as position size+1 in output.
  • Else, the second argument is the key where we store function output.
map(t:tab, fun:fun) ⇒ t

map a function fun(v) over list (skip nil results)

kap(t:tab, fun:fun) ⇒ t

map function fun(k,v) over list (skip nil results)

sort(t:tab, fun:fun) ⇒ t

return t, sorted by fun (default= <)

keys(t:tab) ⇒ ss

return list of table keys, sorted

Strings

fmt(sControl:str, ...) ⇒ str

emulate printf

oo(t:tab) ⇒ t

print t then return it

o(t:tab, isKeys:{bool}) ⇒ s

convert t to a string. sort named keys.

coerce(s:str) ⇒ any

return int or float or bool or string from s

Main

settings(s:str) ⇒ t

parse help string to extract a table of options

cli(options:tab) ⇒ t

update key,vals in t from command-line flags

main fills in the settings, updates them from the command line, runs the start up actions (and before each run, it resets the random number seed and settongs); and, finally, returns the number of test crashed to the operating system.

main(options:tab, help, funs:{fun}) ⇒ nil

main program