Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

duplicate concat as a replacement for append #242

Merged
merged 3 commits into from
Sep 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bass/shipit
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
(let [bins (all-bins src tag)
archives (vals bins)
repros (reduce-kv (fn [acc k v] (cons (archive-repro k v) acc)) [] bins)
files (append archives repros)
files (concat archives repros)
sums (mkfile ./sha256sums.txt (sha256sums src files))]
(bass:smoke-test bins:linux-amd64)
(conj files sums)))
Expand Down
12 changes: 12 additions & 0 deletions pkg/bass/ground_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2008,6 +2008,18 @@ func TestGroundList(t *testing.T) {
bass.Int(6),
),
},
{
Name: "concat",
Bass: "(concat [1 2] [3 4 5] [6])",
Result: bass.NewList(
bass.Int(1),
bass.Int(2),
bass.Int(3),
bass.Int(4),
bass.Int(5),
bass.Int(6),
),
},
{
Name: "filter",
Bass: "(filter symbol? [1 :two 3 :four 5 :six])",
Expand Down
17 changes: 10 additions & 7 deletions std/root.bass
Original file line number Diff line number Diff line change
Expand Up @@ -214,23 +214,26 @@
[] z
[x & xs'] (foldl f (f z x) xs')))

(provide (append)
(defn append1 [xs ys]
(provide (concat)
(defn concat1 [xs ys]
(case xs
[] ys
[x & xs'] (cons x (append1 xs' ys))))
[x & xs'] (cons x (concat1 xs' ys))))

; joins all given lists into one list
;
; => (append [1] [2 3] [4 5 6])
(defn append xss
(foldl append1 [] xss)))
; => (concat [1] [2 3] [4 5 6])
(defn concat xss
(foldl concat1 [] xss)))

^{:deprecated "Use (concat) instead."}
(def append concat)

; returns only values from xs which satisfy the predicate
;
; => (filter symbol? [:abc 123 :def "456"])
(defn filter [predicate xs]
(apply append (map (fn [x] (if (predicate x) [x] [])) xs)))
(apply concat (map (fn [x] (if (predicate x) [x] [])) xs)))

; conjoins values onto the end of a list
;
Expand Down
2 changes: 1 addition & 1 deletion std/run.bass
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
(defn wrap-cmd [thunk cmd & args]
(-> thunk
(with-cmd cmd)
(with-args (append args (cons (thunk-cmd thunk)
(with-args (concat args (cons (thunk-cmd thunk)
(thunk-args thunk))))))

(provide [linux]
Expand Down