8000 Added substr function. by skx · Pull Request #88 · skx/yal · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Added substr function. #88

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

Merged
merged 1 commit into from
Nov 12, 2022
Merged
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
19 changes: 19 additions & 0 deletions stdlib/stdlib/string-substr.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
;;; string-substr.lisp - Fetch substrings from a string

;; String handling is good to have, and here we implement substr in the
;; naive way:
;;
;; Split the string into a list, and take parts of it using "take" and
;; "drop".
;;


(set! substr (fn* (str start &len)
"Return a substring of the given string, by starting index.

The length of the substring is optional."
(if (> start (strlen str)) ; out of bounds?
""
(if (nil? len) ; start at the given offset
(join (drop start (explode str)))
(join (take (car len) (drop start (explode str))))))))
0