Last active
December 14, 2015 03:19
-
-
Save Wilfred/5020622 to your computer and use it in GitHub Desktop.
A tentative slice implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun --slice (list from &optional to) | |
"Return copy of LIST, starting from index FROM to index TO. | |
FROM or TO may be negative" | |
;; to defaults to the end of the list | |
(setq to (or to (length list))) | |
;; handle negative indices | |
(when (< from 0) | |
(setq from (mod from (length list)))) | |
(when (< to 0) | |
(setq to (mod to (length list)))) | |
(-take (- to from) (-drop from list))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment