This repository has been archived by the owner on Jan 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
053string.wart
74 lines (59 loc) · 1.59 KB
/
053string.wart
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
defcall string (s idx ... ends)
withs (idx (range_start idx len.s)
end (if no.ends
(idx + 1)
~car.ends
len.s
:else
(range_bounce car.ends len.s)))
(string_range s idx end)
defset string ((s idx ... ends) val)
`(withs ($idx (range_start ,idx (len ,s))
$end ,(if no.ends
`($idx + 1)
`(if (not ,car.ends)
(len ,s)
(range_bounce ,car.ends (len ,s)))))
(string_splice ,s $idx $end (or ,val "")))
defcoerce string symbol
string_to_sym
def (string ... args)
making stdout (outstring)
each arg args
if arg
pr.arg
outstring_buffer.stdout
defcoerce symbol string
string
def (join head ... tail) :case (or string?.head sym?.head)
(string head @tail)
def (+ head ... tail) :case (or string?.head sym?.head)
(string head @tail)
def (pos fragment str n) :case string?.str
default n :to 0
if (len.str - n >= len.fragment)
if (fragment = (str n (n + len.fragment)))
n
(pos fragment str n+1)
def (empty? s) :case string?.s
(s = "")
defcoerce string list
string_to_list
defcoerce list string
(fn(_)
(string @_))
def (rev s) :case string?.s
(as string (rev (as list s)))
defcoerce nil string
(fn() "")
def (< a b ... rest) :case (and string?.a no.rest)
(string_lesser a b)
def (digit? c)
(and string?.c
(len.c = 1)
("0" <= c <= "9"))
def (letter? c)
(and string?.c
(len.c = 1)
(or ("A" <= c <= "Z")
("a" <= c <= "z")))