forked from sctb/lumen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.l
28 lines (24 loc) · 991 Bytes
/
util.l
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
(define-global format (string rest: objects)
(let (s (stream string)
xs (reverse objects)
msg "")
(with r nil
(while (nil? r)
(let c (read-char s)
(if (= c "%")
(cat! msg (case (set c (read-char s))
("%" "%")
(("s" "S") (str (drop objects)))
(("o" "d" "x" "X")
(parse-int (drop objects) (case c ("o" 8) ("d" 10) (("x" "X") 16))))
(("f" "g")
(parse-float (drop objects)))
(else
(error (cat "Unknown format specifier: " c)))))
(nil? c) (set r msg)
(cat! msg c)))))))
(define-global inhibit-message false)
(define-global current-message nil)
(define-global message (string rest: objects)
(unless (_G .inhibit-message)
(print (set (_G .current-message) (apply format string objects)))))