Skip to content

Instantly share code, notes, and snippets.

@cameyo42
Created July 4, 2022 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cameyo42/13fb05eb49769e5f64913b624507c14e to your computer and use it in GitHub Desktop.
Save cameyo42/13fb05eb49769e5f64913b624507c14e to your computer and use it in GitHub Desktop.
Function as list
;; function as list
(define (index-list lst)
"Creates indexes of list elements"
(ref-all nil lst (fn (x) true)))
; Example:
(setq alst '(1 (2 (3)) 4 (5 (6))))
(index-list alst)
;; ((0) (1) (1 0) (1 1) (1 1 0) (2) (3) (3 0) (3 1) (3 1 0))
(setq idx (index-list alst))
(dolist (el idx) (println el { - } (alst el)))
;; (0) - 1
;; (1) - (2 (3))
;; (1 0) - 2
;; (1 1) - (3)
;; (1 1 0) - 3
;; (2) - 4
;; (3) - (5 (6))
;; (3 0) - 5
;; (3 1) - (6)
;; (3 1 0) - 6
; function = list
index-list
;; (lambda (lst) "Creates indexes of list elements"
;; (ref-all nil lst (lambda (x) true)))
(setq indexes (index-list index-list))
;; ((0) (0 0) (1) (2) (2 0) (2 1) (2 2) (2 3) (2 3 0) (2 3 0 0) (2 3 1))
(dolist (el indexes) (println el { - } (nth el index-list)))
;; (0) - (lst)
;; (0 0) - lst
;; (1) - Creates indexes of list elements
;; (2) - (ref-all nil lst (lambda (x) true))
;; (2 0) - ref-all
;; (2 1) - nil
;; (2 2) - lst
;; (2 3) - (lambda (x) true)
;; (2 3 0) - (x)
;; (2 3 0 0) - x
;; (2 3 1) - true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment