Login
7 branches 0 tags
Ben (X13/Arch) Fixed handling of - symbol and added some more tests a0e416d 4 years ago 109 Commits
nujel / stdlib / time.nuj
; Time related λs

; Initialize the RNG
[random-seed [logxor [time] [time/millliseconds]]]

[def time/seconds [λ [timestamp]
	"Return the seconds part of TIMESTAMP, defaults to current time"
	[% [default timestamp [time]] 60]
]]

[def time/minutes [λ [timestamp]
	"Return the minutes part of TIMESTAMP, defaults to current time"
	[% [/ [default timestamp [time]] 60] 60]
]]

[def time/hours [λ [timestamp]
	"Return the hours part of TIMESTAMP, defaults to current time"
	[% [/ [default timestamp [time]] 3600] 24]
]]

[def profile [λ [@...body]
	[def form [cons 'do @...body]]
	[def start-time [time/milliseconds]]
	[def val [eval form]]
	[def end-time [time/milliseconds]]
	[display [cat "Evaluating " [str/write form] " to " [str/write val] " took " [- end-time start-time] " milliseconds."]]
]]