0 Members and 1 Guest are viewing this topic.
(setq my-list '(("Two-Site layout.dwg" "Two - PLOT LIMIT.dwg") ("Three-Site layout.dwg") nil "one -Site layout.dwg" "one -PLOT LIMIT.dwg" nil (("Sub-2 -Site layout.dwg" "Sub-1 -Site layout.dwg") "Four -Site layout.dwg") ))
(ALE_List_Flatten my-list)=>> ("Two-Site layout.dwg" "Two - PLOT LIMIT.dwg" "Three-Site layout.dwg" "one -Site layout.dwg" "one -PLOT LIMIT.dwg" "Sub-2 -Site layout.dwg" "Sub-1 -Site layout.dwg" "Four -Site layout.dwg" )
; Marc'Antonio Alessi - http://xoomer.virgilio.it/alessi; Function: ALE_List_Flatten - 11/03/2006;; Version 1.02 - 15/03/2006;; Description: Return a flat list from any kind of list;; Arguments: In_Lst = list;; Return Values: List or nil if In_Lst is nil;; Notes: remove all occurences of nil from result;; Example:; (setq alist '(0 (1 . 2) (3 nil 3) (5 (3 (6 (1 2) 3) 3 7))));; (ALE_List_Flatten alist); Returns: (0 1 2 3 3 5 3 6 1 2 3 3 7);(defun ALE_List_Flatten (In_Lst / OutLst) (reverse (ALE_List_Flatten_Aux In_Lst)));(defun ALE_List_Flatten_Aux (In_Lst) (foreach ForElm In_Lst (if (atom ForElm) (if ForElm (setq OutLst (cons ForElm OutLst)) OutLst) (if (listp (cdr ForElm)) (ALE_List_Flatten_Aux ForElm) (setq OutLst (cons (cdr ForElm) (cons (car ForElm) OutLst))) ) ) ));; Notes: keep all occurences of nil:; Returns: (0 1 2 3 nil 3 5 3 6 1 2 3 3 7);(defun ALE_List_Flatten_Aux (In_Lst) (foreach ForElm In_Lst (if (atom ForElm) (setq OutLst (cons ForElm OutLst)) (if (listp (cdr ForElm)) (ALE_List_Flatten_Aux ForElm) (setq OutLst (cons (cdr ForElm) (cons (car ForElm) OutLst))) ) ) ));; Marc'Antonio Alessi - http://xoomer.virgilio.it/alessi;; Function: ALE_List_Flatten_NR; Version 1.00 - 15/03/2006 ;; Description: Return a flat list from any kind of list; Not recursive - slower;; Arguments: In_Lst = list;; Notes: keep all occurences of nil;(defun ALE_List_Flatten_NR (In_Lst / TmpVal TmpCar TmpCdr OutLst) (while In_Lst (if (atom (setq TmpVal (car In_Lst))) (setq OutLst (cons TmpVal OutLst) In_Lst (cdr In_Lst)) (if (listp (setq TmpCar (car TmpVal) TmpCdr (cdr TmpVal))) (if TmpCdr (setq In_Lst (cons TmpCar (cons TmpCdr (cdr In_Lst)))) (setq In_Lst (cons TmpCar (cdr In_Lst))) ) (setq OutLst (cons TmpCdr (cons TmpCar OutLst)) In_Lst (cdr In_Lst) ) ) ) ) (reverse OutLst));; Marc'Antonio Alessi - http://xoomer.virgilio.it/alessi;; Function: ALE_List_Flatten_N2; Version 1.00 - 15/03/2006 ;; Description: Return a flat list from any kind of list; Not recursive - slower;; Arguments: In_Lst = list;; Notes: remove all occurences of nil from result;(defun ALE_List_Flatten_N2 (In_Lst / TmpVal TmpCar TmpCdr OutLst) (while In_Lst (if (atom (setq TmpVal (car In_Lst))) (progn (setq In_Lst (cdr In_Lst)) (and TmpVal (setq OutLst (cons TmpVal OutLst))) ) (if (listp (setq TmpCar (car TmpVal) TmpCdr (cdr TmpVal))) (if TmpCdr (setq In_Lst (cons TmpCar (cons TmpCdr (cdr In_Lst)))) (setq In_Lst (cons TmpCar (cdr In_Lst))) ) (setq OutLst (cons TmpCdr (cons TmpCar OutLst)) In_Lst (cdr In_Lst) ) ) ) ) (reverse OutLst))
;;;++++++++++++ Explode Any List Steve Johnson +++++++++++++++++++++(defun exlist (LST / expl new) (defun expl (SUBLST) (foreach one SUBLST (if (atom one) (setq new (cons one new)) (if (listp (cdr one)) (expl one) (setq new (cons (cdr one) (cons (car one) new))))))) (expl (list LST)) (reverse new))