transfering a tekststing to an variable

Discussion in 'AutoCAD' started by Marcel Janmaat, Jan 4, 2005.

  1. Hello there,

    Maby I 'm being foolish here, but...

    If I have

    (setq a '("variable" "1" "This is a variable"))

    How can I transfer "variable" to variable like

    (setq variable ; meaning (car a) transferd to variable
    (cadr a)
    )

    Regards M
     
    Marcel Janmaat, Jan 4, 2005
    #1
  2. Marcel Janmaat

    Tom Smith Guest

    (set (read (car a)) (cadr a))
     
    Tom Smith, Jan 4, 2005
    #2
  3. Thanx! That was easy! Never had to use read before.
     
    Marcel Janmaat, Jan 4, 2005
    #3
  4. Marcel Janmaat

    Tom Smith Guest

    read is useful when you need to create a symbol name, as in a case like
    this.

    Also note the set instead of setq. Setq is a contraction of "set quote"
    where the first argument is ro be taken literally (quoted) as in (setq
    variable 1) which is the same as (set (quote variable) 1) or (set 'variable
    1).

    But in your case the first argument was something that needed to be
    evaluated -- (read (car a)) -- so you don't want to suppress evaluation by
    quoting it.
     
    Tom Smith, Jan 4, 2005
    #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.