Skip to content

Commit d2c935a

Browse files
committed
refactor: Replace slurp and spit with read and write
1 parent 3e5bcca commit d2c935a

10 files changed

Lines changed: 26 additions & 26 deletions

File tree

blog/2024-04-16.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ https://sched.co/1aBPY):
376376
--- !data
377377
378378
- &data !
379-
yaml/load: slurp('data.yaml')
379+
yaml/load: read('data.yaml')
380380
381381
- &map1
382382
key: value

doc/cheat.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ greet 'Bob':
103103
### Chain calls
104104

105105
```
106-
say: slurp("/usr/share/dict/words")
106+
say: read("/usr/share/dict/words")
107107
.lines():shuffle.take(3).join(".")
108108
# => specialty.mutation's.Kisangani
109109
```

doc/core.mdys

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ YS Std:
247247
```mdys:quick-ref
248248
print printf println pr prn
249249
print-str println-str pr-str prn-str
250-
newline flush slurp spit
250+
newline flush read write
251251
with-out-str with-open with-in-str
252252
```
253253

sample/benchmark-yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,6 @@ defn test-ys(yaml):
126126

127127
# Test YS loading with Java's SnakeYAML Engine:
128128
defn test-ys-yaml(yaml):
129-
test yaml: "ys -e 'yaml/load: slurp(IN)'"
129+
test yaml: "ys -e 'yaml/load: read(IN)'"
130130

131131
# vim: lisp ft=yaml sw=2:

util/brew-update

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defn update-brew(version):
1717
when res.exit:N.?:
1818
die: "git clone of '$brew-url' failed\n$(res.err)"
1919

20-
text =: slurp('homebrew-yamlscript/template/ys.rb')
20+
text =: read('homebrew-yamlscript/template/ys.rb')
2121
.replace('VERSION' version)
2222
text =:
2323
reduce-kv _ text releases:
@@ -26,17 +26,17 @@ defn update-brew(version):
2626
text: .replace(key sha256)
2727

2828
say: "Updating homebrew-yamlscript/ys.rb"
29-
spit 'homebrew-yamlscript/ys.rb':
29+
write 'homebrew-yamlscript/ys.rb':
3030
text.replace('CLASS' 'Ys')
3131

3232
vrsn =: version.replace('.')
3333
say: "Updating homebrew-yamlscript/ys@version.rb"
34-
spit "homebrew-yamlscript/ys@$version.rb":
34+
write "homebrew-yamlscript/ys@$version.rb":
3535
text.replace('CLASS' "YsAT$vrsn")
3636

3737
say: "Updating homebrew-yamlscript/ReadMe.md"
38-
spit "homebrew-yamlscript/ReadMe.md":
39-
slurp("homebrew-yamlscript/template/ReadMe.md")
38+
write "homebrew-yamlscript/ReadMe.md":
39+
read("homebrew-yamlscript/template/ReadMe.md")
4040
.replace('VERSION' version)
4141

4242
status =: sh('git -C homebrew-yamlscript status --short --ignored').out

util/copy-md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
DNE =: "<!-- DO NOT EDIT — THIS FILE WAS GENERATED -->\n\n"
44

55
defn main(input-file):
6-
print: input-file:slurp
6+
print: input-file:read
77
.replace(
88
/^(---\n(?s:.*?)\n---\n)\n*/
99
"$1\n$DNE")

util/mdys

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ defn process(input-file):
3434

3535
fenced-re =: /(?sm)(?:^```mdys:\S+\n.*?\n```\n)/
3636
defn load-mdys(file):
37-
text =: file:fs-abs:slurp
37+
text =: file:fs-abs:read
3838
texts =: text.split(fenced-re)
3939
fenced =: text.re-seq(fenced-re) || []
4040
fenced =: fenced:V.conj('')

util/release-yamlscript

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ defn step-3(ctx):
9595
changes =:
9696
make-changes-entry: ctx
9797

98-
spit 'release-changes.txt': changes
98+
write 'release-changes.txt': changes
9999

100100
prompt: "Press Enter to edit the 'Changes' file."
101101
editor =: ENV.EDITOR || 'vi'
102102
run: "$editor release-changes.txt"
103103
prompt: 'Press Enter to continue or Ctrl-C to abort.'
104104

105-
validate-yaml: slurp('release-changes.txt')
105+
validate-yaml: read('release-changes.txt')
106106

107107
when verbose:
108108
# Show git changes since last release:
@@ -120,19 +120,19 @@ defn step-4(ctx):
120120

121121
# Update Changes if tests pass:
122122
when-not dryrun:
123-
changes =: slurp('release-changes.txt')
123+
changes =: read('release-changes.txt')
124124

125125
file-prepend 'Changes': |
126126
- version: $(ctx.new)
127127
date: $(ctx.date-time)
128128
changes:
129129
$(changes:str/trimr)
130130

131-
validate-yaml: slurp('Changes')
131+
validate-yaml: read('Changes')
132132

133133
changes =: changes.replace(/(?m)^ -/ '*')
134134

135-
spit 'release-changes.txt': changes
135+
write 'release-changes.txt': changes
136136

137137

138138
#------------------------------------------------------------------------------
@@ -274,8 +274,8 @@ defn prompt(msg):
274274
trim: read-line()
275275

276276
defn file-prepend(file text):
277-
spit file:
278-
str: text slurp(file)
277+
write file:
278+
str: text read(file)
279279

280280
defn make-changes-entry(ctx):
281281
lines =:

util/version-bump

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ defn main():
1313
regx =: qr(regx)
1414
each f file:
1515
f =: "$ROOT/$f"
16-
text =: f:slurp
16+
text =: f:read
1717
m =: re-matcher(regx text)
1818
if re-find(m):
1919
do:
@@ -22,7 +22,7 @@ defn main():
2222
if all:
2323
str/replace
2424
str/replace-first
25-
spit f:
25+
write f:
2626
replace:
2727
text regx
2828
str/re-quote-replacement("$m1$vers$m2")

ys/test/cli-usage.t

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,19 @@ test::
189189
- cmnd:: "ys -Y '.0.name' $DIR/animals.json"
190190
want: Meowsy
191191
- cmnd: ys -Y '.0.name'
192-
stdi:: slurp("$DIR/animals.json")
192+
stdi:: read("$DIR/animals.json")
193193
want: Meowsy
194194
- cmnd: ys -Y '.0.name' -
195-
stdi:: slurp("$DIR/animals.json")
195+
stdi:: read("$DIR/animals.json")
196196
want: Meowsy
197197
- cmnd: ys -Y '.0.name' -
198-
stdi:: slurp("$DIR/animals.json")
198+
stdi:: read("$DIR/animals.json")
199199
want: Meowsy
200200
- cmnd: ys -Ye '.0.name' -
201-
stdi:: slurp("$DIR/animals.json")
201+
stdi:: read("$DIR/animals.json")
202202
want: Meowsy
203203
- cmnd: ys '.0' -
204-
stdi:: slurp("$DIR/animals.json")
204+
stdi:: read("$DIR/animals.json")
205205
want: |
206206
name: Meowsy
207207
species: cat
@@ -213,7 +213,7 @@ test::
213213
- ham
214214
- zucchini
215215
- cmnd: ys -Y
216-
stdi:: slurp("$DIR/animals.json")
216+
stdi:: read("$DIR/animals.json")
217217
have: |
218218
- name: Meowsy
219219
species: cat

0 commit comments

Comments
 (0)