blob: d613deadcccb89fe0d89d4a799695d204cfa6568 (
plain) (
blame)
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
|
# MIT License, Copyright (c) 2022 Marvin Borner
:import std/Char C
:import std/Number .
:import std/Number/Binary B
:input std/List
# returns true if two strings are the same
eq? eq? B.eq?
…=?… eq?
:test ("ab" =? "ab") (true)
:test ("ab" =? "aa") (false)
# returns true if character is part of a string
in? in? B.eq?
…∈… in?
ni? \in?
…∋… ni?
:test ('b' ∈ "ab") (true)
:test ('c' ∈ "ab") (false)
:test ("ab" ∋ 'b') (true)
:test ("ab" ∋ 'c') (false)
# converts a string of digits into a number
number! from-digits ∘ (map C.number!)
:test ((number! "123") =? (+123)) (true)
# splits string by newline character
lines z [[rec]]
rec build (break (B.eq? '\n') 0)
build [∅?(~0) (^0 : empty) (^0 : (2 ~(~0)))]
:test (lines "ab\ncd") ("ab" : ("cd" : empty))
# concats list of strings with newline character
unlines concat-map (\(…;…) '\n')
:test (unlines ("ab" : ("cd" : empty))) ("ab\ncd\n")
|