RSS Feed

Lisp Project of the Day

temporal-functions

You can support this project by donating at:

Donate using PatreonDonate using Liberapay

Or see the list of project sponsors.

temporal-functionsdatetimeutils

Documentation🥺
Docstrings🥺
Tests 🥺
Examples🤨
RepositoryActivity🥺
CI 🥺

This is a small library by @thebaggers allows you to define functions which work only specified amount of time. You can use it to define a named function or to create a lambda.

This will print a greeting only 10 seconds since definition:

POFTHEDAY> (temporal-functions:defun-t foo ()
             (temporal-functions:before (temporal-functions:seconds 10)
               (print "Hello Lisp World!")))

POFTHEDAY> (foo)
"Hello Lisp World!" 
"Hello Lisp World!"

POFTHEDAY> (foo)
"Hello Lisp World!" 
"Hello Lisp World!"

POFTHEDAY> (foo)
NIL

POFTHEDAY> (temporal-functions:expiredp (foo))
T

It is possible to create a function which starts doing something after the specified amount of time:

POFTHEDAY> (temporal-functions:tlambda ()
             (temporal-functions:after (temporal-functions:seconds 10)
               (print "Now I'm working!")))
#<CLOSURE (LAMBDA ()) {1001D5183B}>

POFTHEDAY> (funcall *)
NIL

POFTHEDAY> (funcall **)

"Now I'm working!" 
"Now I'm working!"

There are also other constructions like then, repeat, each, until and once. But I wasn't able to figure out the right way to use them. It would be wonderful if @thebaggers update the documentation!


Brought to you by 40Ants under Creative Commons License