add join function to stdlib

Signed-off-by: Ava Affine <ava@sunnypup.io>
This commit is contained in:
Ava Apples Affine 2024-06-01 08:55:53 -07:00
parent 386d0900a9
commit 3d0d8d8215
4 changed files with 18 additions and 2 deletions

View file

@ -16,7 +16,7 @@
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;; AVA'S LAPTOP PROMPT
;; AVAS LAPTOP PROMPT
;; This file contains a shell prompt configuration that outputs current dir
;; username, and percentages for all batteries on the system.
;; -> requires CFG_FLESH_POSIX=true and userlib.

View file

@ -114,6 +114,12 @@
(add-path new-path)
(contains? (get-paths) new-path))))
('join operates as expected'
(quote
(let ((l ("1" 2 (3))))
(eq? (join l ".")
"1.2.(3)"))))
;; add more test cases here
))

View file

@ -146,3 +146,13 @@ adds a directory to PATH'
(rem (cdr path-iter)))
(echo pat)
(set (q path-iter) (pop rem))))))
(def join
'concatenates list elements into a string, while
interspersing a provided delimiter in between elements'
(list delim)
(reduce (lambda (res elem)
(if (eq? (strlen res) 0)
(string elem)
(concat res delim elem)))
list))