A fresh new minor release of ABS: always be shipping! 🚢
Interactive REPL through the @cli module
The @cli.repl()
mode allows to run interactive REPLs based on the commands registered within the CLI:
cli = require('@cli')
res = {"count": 0}
@cli.cmd("count", "prints a counter", {})
f counter(arguments, flags) {
echo(res.count)
}
@cli.cmd("incr", "Increment our counter", {})
f incr(arguments, flags) {
res.count += 1
return "ok"
}
@cli.cmd("incr_by", "Increment our counter", {})
f incr_by(arguments, flags) {
echo("Increment by how much?")
n = stdin().number()
res.count += n
return "ok"
}
cli.repl()
You can see it in action:
$ ./cli
help
Available commands:
* count - prints a counter
* help - print this help message
* incr - Increment our counter
* incr_by - Increment our counter
count
0
incr
ok
incr
ok
count
2
incr_by
Increment by how much?
-10
ok
count
-8
Memoizing through @util.memoize
A new @util
native module was introduced to allow memoization of functions:
memo = require('@util').memoize
@memo(60)
f long_task(x, y) {
sleep(1000)
return "done"
}
echo(long_task(1, 1)) # waits 1s
echo(long_task(1, 1)) # immediate
echo(long_task(1, 1)) # immediate
sleep(61000) # sleep for a min...
echo(long_task(1, 1)) # waits 1s
echo(long_task(1, 2)) # waits 1s
New function: unix_ms
unix_ms()
returns the current Unix epoch, in milliseconds.
unix_ms() # 1594049453157
See ya! 👋