summaryrefslogtreecommitdiffstats
path: root/utils.txr
blob: 5cdc15a3bb15c4dc830e22908f8f34cb6b18b141 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
@(define n (a))@(local n)@{n /\d+/}@(bind a @(int-str n))@(end)
@(define m (a))@(local m)@{m /\w+/}@(bind a @(month-num m))@(end)
@#
@(next :string self-path)
@(some)
@*nil/@self.@nil
@(or)
@*nil/@self
@(or)
@self.@nil
@(or)
@self
@(end)
@#
@(do
   (defun debug (arg . args)
     [apply format ^(, *stdlog* ,arg ,*args)])

   (defun hrtime (time)
     (cond
       ((< time 60)
        (format nil "~ss" time))
       ((< time 3600)
        (format nil "~s.~sm" (trunc time 60)
                (trunc (* (mod time 60) 10) 60)))
       ((< time 86400)
        (format nil "~s.~sh"
                (trunc time 3600)
                (trunc (* (mod time 3600) 10) 3600)))
       (t
        (format nil "~s.~sd"
                (trunc time 86400)
                (trunc (* (mod time 86400) 10) 86400)))))

   (defun month-num (month)
     (cdr (assoc (downcase-str month)
                 '(("jan" . 1) ("feb" . 2) ("mar" . 3) ("apr" . 4)
                   ("may" . 5) ("jun" . 6) ("jul" . 7) ("aug" . 8)
                   ("sep" . 9) ("oct" . 10) ("nov" . 11) ("dec" . 12))))))