String into variable?

Discussion in 'AutoCAD' started by Sage Cowsert, Jun 11, 2004.

  1. Sage Cowsert

    Sage Cowsert Guest

    Given that this function sets the value TEST to a real number of 0.5.

    (setq TEST 0.5)

    I'd like to be able to push the symbol (word?) TEST and the variable to a
    function. and have it do exactly as above. I was looking at send it in this
    format.

    (NEWFUNCTION 0.5 TEST)

    It doesn't matter to me if TEST is the a string or list or whatever. I just
    want to send it to a function and have it set. I'm thinking something along
    the lines of

    (defun NEWFUNCTION (VALUE VARIABLE /)
    (setq (read VARIABLE) NEWVALUE)
    )


    Now this doesn't work but that's what I imagine. Thoughts?

    Thanks. Sage
     
    Sage Cowsert, Jun 11, 2004
    #1
  2. Sage Cowsert

    Doug Broad Guest

    Sage,
    These things can easily be done without a wrapper function
    as the contents of these functions show. The set function
    is used rather than setq.
    You were close:

    ;;arguments (value string)
    (defun setstring (string value)
    (set (read string) value)
    )

    ;;arguments (value symbol)
    (defun setsym (symbol value)
    (set symbol value))
     
    Doug Broad, Jun 11, 2004
    #2
  3. Sage Cowsert

    Sage Cowsert Guest

    That does it! Thanks. :)


     
    Sage Cowsert, Jun 11, 2004
    #3
  4. Sage Cowsert

    ECCAD Guest

    Doug,
    (setstring.. works good.
    (setsym..errors ? Why ?

    Command: (setq string "TEST")
    "TEST"

    Command: (setq value 0.5)
    0.5

    Command: (setstring string value)
    0.5

    Command: !test
    0.5

    Command: !symbol
    "TEST"

    Command: !value
    0.5

    Command: (setsym symbol value)

    Error: bad argument type: symbolp "TEST"
    Error: Break...

    Nevermind, got it..
    Command: (setsym 'symbol value)
    0.5

    Bob
     
    ECCAD, Jun 12, 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.