assigning values to list elements

Discussion in 'AutoCAD' started by biot023, Aug 20, 2004.

  1. biot023

    biot023 Guest

    Hallo - I have some (v. newbie) code that I want to swap the values in two points - it doesn't work, but it might give you an idea of what I'm trying to achieve:
    (progn
    (setq temp (car (assoc 10 ldata)))
    (setq (car (assoc 10 ldata)) (car (assoc 11 ldata)))
    (setq (car (assoc 11 ldata)) temp)
    )

    Obviously I am not allowed to use setq the way I try to in line 3 (error: bad variable name)!
    How can I access the value at (car ( assoc 10 ldata))?
    Thanks for any help,
    doug
     
    biot023, Aug 20, 2004
    #1
  2. Quickly on my way out the door (so probably incomplete):

    Assuming you already have saved ldata.

    You want cdr rather than car. (car (assoc 10 <whatever>)) will give you the
    10. (cdr (assoc 10 <whatever>)) will give you the value paired with it.

    Kent Cooper, AIA


    points - it doesn't work, but it might give you an idea of what I'm trying
    to achieve:
     
    Kent Cooper, AIA, Aug 20, 2004
    #2
  3. biot023 a écrit :


    try

    (subst (cons 10 (cdr (assoc 11 ldata))) (assoc 10 ldata) ldata)

    and same for 11

    good luck ;-)
     
    Bruno.lintermans, Aug 20, 2004
    #3
  4. biot023

    Jim Claypool Guest

    (progn
    (setq temp10 (cdr (assoc 10 ldata)))
    (setq temp11 (cdr (assoc 11 ldata)))
    (setq ldata (subst (cons 10 temp11) (assoc 10 ldata) ldata))
    (setq ldata (subst (cons 11 temp10) (assoc 11 ldata) ldata))
    (entmod ldata)
    )

    points - it doesn't work, but it might give you an idea of what I'm trying
    to achieve:
     
    Jim Claypool, Aug 20, 2004
    #4
  5. biot023

    biot023 Guest

    Thanks very much for those replies - the car/cdr thing could have been a real stickler, and the code from Jim works a treat!
    Thanks again,
    doug.
     
    biot023, Aug 23, 2004
    #5
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.