list handling

Discussion in 'AutoCAD' started by Doug Broad, Dec 13, 2004.

  1. Doug Broad

    Doug Broad Guest

    Marcel,
    Its impossible to tell what your lists (sgl, bln, el1) originally contained
    but the following function will flatten any level of complexity to a single
    level list (a flat list)

    (defun flatlist (lst) ;;D. C. Broad, Jr.
    (cond
    ((null lst) nil)
    ((listp (car lst))
    (append (flatlist (car lst))
    (flatlist (cdr lst))))
    (t (cons (car lst) (flatlist (cdr lst))))))

    ;|Example execution:
    $ (flatlist '(((1 2 (3))(4 5))(((6))7)8))
    (1 2 3 4 5 6 7 8)
    |;

    _$
     
    Doug Broad, Dec 13, 2004
    #1
  2. Question,

    I have;
    (append sgl (list (list bln (cdr (assoc 1 el1)) (cddr (assoc (substr bln 1
    5) sgl)))))
    wich results in;
    (("B_PRS" "xxx" "1" "2" "3" "4") ("E_SKL" "xxx" "1" "2" "3" "4") ("E_WCD"
    "xxx" "1" "2" "3" "4") ("E_WCD0101" "blabla" ("0.00" "0.0" "00" "032")))

    But I want it to be; (without the parentheses)
    (("B_PRS" "xxx" "1" "2" "3" "4") ("E_SKL" "xxx" "1" "2" "3" "4") ("E_WCD"
    "xxx" "1" "2" "3" "4") ("E_WCD0101" "blabla" "0.00" "0.0" "00" "032"))

    Must be simple but I don't know how (yet)

    M
     
    Marcel Janmaat, Dec 13, 2004
    #2
  3. Doug Broad

    ECCAD Guest

    Try removing one "(List " and the very last ")"

    Bob
     
    ECCAD, Dec 13, 2004
    #3
  4. Doug Broad

    zeha Guest

    (apply 'append (mapcar 'append '(("B_PRS" "xxx" "1" "2" "3" "4") ("E_SKL" "xxx" "1" "2" "3" "4") ("E_WCD"
    "xxx" "1" "2" "3" "4") ("E_WCD0101" "blabla" ("0.00" "0.0" "00" "032")))))

    give

    ("B_PRS" "xxx" "1" "2" "3" "4" "E_SKL" "xxx" "1" "2" "3" "4" "E_WCD" "xxx" "1" "2" "3" "4" "E_WCD0101" "blabla" ("0.00" "0.0" "00" "032"))
     
    zeha, Dec 13, 2004
    #4
  5. Perfect Doug!
    Just what I needed.

    Thanx!

     
    Marcel Janmaat, Dec 13, 2004
    #5
  6. Doug Broad

    Doug Broad Guest

    Marcel,
    Great. You're welcom.
    Regards,
    Doug
     
    Doug Broad, Dec 13, 2004
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.