mirror of
https://github.com/carp-lang/Carp.git
synced 2024-11-05 04:44:12 +03:00
9848e8fb34
- don’t do function copying in benchmarking - fix the array_update benchmark - add Filepath.file-from-path - add tests for the `Filepath` module - reformat a lot of documentation
19 lines
718 B
Plaintext
19 lines
718 B
Plaintext
(defmodule Filepath
|
|
|
|
(use Array)
|
|
|
|
(doc dir-from-path "removes the file name part of a path to a file, similar to the `basename` utility in Shell scripting.")
|
|
(defn dir-from-path [path]
|
|
(let [segments (split-by path &[\/])
|
|
n (dec (length &segments))
|
|
without-last (prefix-array &segments n)]
|
|
(concat &(copy-map &(fn [s] (str* s "/")) &without-last))))
|
|
|
|
(doc file-from-path "removes the base name part of a path to a file, similar to the `filename` utility in Shell scripting.")
|
|
(defn file-from-path [path]
|
|
(let [segments (split-by path &[\/])]
|
|
; this is actually safe here, because split by will return an array of
|
|
; length > 0
|
|
(unsafe-last &segments)))
|
|
)
|