Replacing an item in a list

Discussion in 'AutoCAD' started by Marcel Janmaat, Dec 15, 2004.

  1. Marcel Janmaat

    Doug Broad Guest

    Hi Marco,
    I'm not surprised. Just spent a few minutes on it and
    found all sorts of issues with the conversion process.
    Tony is right. Safearrays are great if the data is being
    created and managed as an array and needs no
    conversion. Conversions of LISP lists to safearrays
    are not simple tasks and most of the time are not
    worth doing anyway.

    Regards,
    Doug
     
    Doug Broad, Dec 21, 2004
    #41
  2. For the maniacs, a kludgy but faster solution for doing
    vectors in Visual LISP involves using generated symbols:

    (defun makesym (prefix x)
    (read (strcat prefix "->" (itoa x)))
    )

    Assign a value to an element (sparse vectors allowed):

    (defun put-element (vector index value)
    (set (makesym (vl-symbol-name vector) index) value)
    )


    Reference element:

    (defun get-element (vector index)
    (eval (makesym (vl-symbol-name vector) index))
    )

    Command: (put-element 'myvector 2 "Value of element 2")
    "Value of element 2"

    Command: (get-element 'myvector 2)
    "Value of element 2"

    While it sure is a mega-kludge, it would beat the pants off of
    any solution involving the use of lists.
     
    Tony Tanzillo, Dec 21, 2004
    #42
  3. This might be slightly faster using vl-symbol-value instead of eval.

    --
     
    Martti Halminen, Dec 22, 2004
    #43
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.