Function: org-babel-ref-index-list
org-babel-ref-index-list is a byte-compiled function defined in
ob-ref.el.gz.
Signature
(org-babel-ref-index-list INDEX LIS)
Documentation
Return the subset of LIS indexed by INDEX.
Indices are 0 based and negative indices count from the end of LIS, so 0 references the first element of LIS and -1 references the last. If INDEX is separated by ","s then each "portion" is assumed to index into the next deepest nesting or dimension.
A valid "portion" can consist of either an integer index, two integers separated by a ":" in which case the entire range is returned, or an empty string or "*" both of which are interpreted to mean the entire range and as such are equivalent to "0:-1".
Source Code
;; Defined in /usr/src/emacs/lisp/org/ob-ref.el.gz
(defun org-babel-ref-index-list (index lis)
"Return the subset of LIS indexed by INDEX.
Indices are 0 based and negative indices count from the end of
LIS, so 0 references the first element of LIS and -1 references
the last. If INDEX is separated by \",\"s then each \"portion\"
is assumed to index into the next deepest nesting or dimension.
A valid \"portion\" can consist of either an integer index, two
integers separated by a \":\" in which case the entire range is
returned, or an empty string or \"*\" both of which are
interpreted to mean the entire range and as such are equivalent
to \"0:-1\"."
(if (and (> (length index) 0) (string-match "^\\([^,]*\\),?" index))
(let* ((ind-re "\\(\\([-[:digit:]]+\\):\\([-[:digit:]]+\\)\\|\\*\\)")
(lgth (length lis))
(portion (match-string 1 index))
(remainder (substring index (match-end 0)))
(wrap (lambda (num) (if (< num 0) (+ lgth num) num)))
(open (lambda (ls) (if (and (listp ls) (= (length ls) 1)) (car ls) ls))))
(funcall
open
(mapcar
(lambda (sub-lis)
(if (listp sub-lis)
(org-babel-ref-index-list remainder sub-lis)
sub-lis))
(if (or (= 0 (length portion)) (string-match ind-re portion))
(mapcar
(lambda (n) (nth n lis))
(apply 'org-number-sequence
(if (and (> (length portion) 0) (match-string 2 portion))
(list
(funcall wrap (string-to-number (match-string 2 portion)))
(funcall wrap (string-to-number (match-string 3 portion))))
(list (funcall wrap 0) (funcall wrap -1)))))
(list (nth (funcall wrap (string-to-number portion)) lis))))))
lis))