-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path18-8-20-- string-join
113 lines (66 loc) · 1.53 KB
/
18-8-20-- string-join
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#lang racket
(define add3
(λ (a)
(λ (b)
(λ (c)
(+ a b c)))))
(((add3 1) 3) 5)
(define table1-λ1 (add3 1))
(define table2-λ2 (table1-λ1 3))
(define put-it-all-together-λ3 (table2-λ2 5))
put-it-all-together-λ3
(define add
(λ (c b)
(+ c b)))
(define sub
(λ (c b)
(- c b)))
(define integer
(λ (c)
(λ (cmd b)
(if (eq? cmd "add")
(+ b c )
(if (eq? cmd "sub")
(- b c )
"no command found"
)))))
(define integerrr
(λ (a)
(define addd
(λ (b)
(+ a b)))
(define subb
(λ (b)
(- a b)))
(λ (cmd arg)
(if (eq? cmd "addd")
(addd arg)
(if (eq? cmd "subb")
(subb arg)
"not found")))))
(define string-join
(lambda (ls delim)
(define out (open-output-string))
"Join list of strings together by delim into one string."
(let loop ((ls ls))
(if (null? (cdr ls))
(begin
(display (car ls) out)
(get-output-string out))
(begin
(display (car ls) out)
(display delim out)
(loop (cdr ls)))))))
(define name
(λ (a)
(define firsty-lasty
(λ (a b)
(string-append a b)))
(λ (cmd b)
(if (eq? cmd "combine")
(firsty-lasty a b)
"don't combine"))))
(define names (name "john"))
(names "combine" "doe")
(define int2 (integer 2))
(int2 "add" 3)