replacing a line in a list

Discussion in 'AutoCAD' started by kemp, Apr 28, 2004.

  1. kemp

    kemp Guest

    I have a list formatted like this:

    (list foo '(("q" "2" "3" "4")("w" "2" "3" "4")("e" "2" "3" "4")("r" "2" "3"
    "4")))

    I want to replace one sub list based on the first item in the list. For
    example I have a new list ("z" "2" "3" "4") and I want to replace ("e" "2"
    "3" "4") with the new data in the same location to end up with this:

    (("q" "2" "3" "4")("w" "2" "3" "4")("z" "2" "3" "4")("r" "2" "3" "4"))

    Can someone tell me the logic to do this? I'm thinking it will require the
    use of ASSOC and CONS but there is probably a lot more to it than that. Also
    I'd prefer basic instructions over raw code so I can try to figure it all
    out. Thanks!

    kemp
     
    kemp, Apr 28, 2004
    #1
  2. kemp

    Rudy Tovar Guest

    Rudy Tovar, Apr 29, 2004
    #2
  3. kemp

    PG. Guest

    (setq foo '(("q" "2" "3" "4")("w" "2" "3" "4")("e" "2" "3" "4")("r" "2" "3"
    "4"))) ;; corrected

    (setq foo (subst '("z" "2" "3" "4") '("e" "2" "3" "4") foo)) ;; substituted

    -PG.
     
    PG., Apr 29, 2004
    #3
  4. kemp

    kemp Guest

    subst is exactly what I needed. Thanks to both of you Doug and Rudy! It
    works now :)

    kemp
     
    kemp, Apr 29, 2004
    #4
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.