Turn setq into string?

Sage Cowsert

Usenet Archive
Joined
Jul 25, 2003
Messages
44
Reaction score
0
I posted this in a different thread. It really should be in its own. Ok how now how do I do this?

(setq Bob "is cool")

to read > "Bob is cool"

?? (strcat (read bob) bob) ??
 
(setq Bob "is cool")
to read > "Bob is cool"

?? (strcat (read bob) bob) ??

Try...

(strcat (vl-symbol-name 'bob) " is cool")

HTH,

Devin
 
Or perhaps this is more approprate for what I think you might be doing...

(read (strcat (vl-symbol-name (quote bob)) " is cool"))

The above returns the symbol name 'bob is cool'. Except you can't have spaces in symbol names.

If you have a symbol name assigned to the variable 'bob' then leave out the quote...

(setq bob "I am")
(read (strcat (vl-symbol-name bob) " cool"))

returns the symbol name 'I am cool'. Again, no spaces in symbol names.

Devin
 
Hi Devin.
Just curious. What you have posted
is interesting but how would either be
better than what I posted or have a
more general application. Perhaps
if he wanted a nested solution where
(setq name "bob")
(setq bob "is cool")
(strcat name " " (eval (read name)))

would make more sense.

Being able to do a thing is different than
knowing whether a thing should be done
or is helpful to do. ;-)

Wouldn't lists, especially association lists,
be more appropriate than such code?

Regards,
Doug
 
Devin's code is what I'm looking for. I'm using this code to store info into a dictionary. So I'd like the setq's name stored with the setq'd value. This is what I came up with.

(defun DT_STANDARDS_DICTPUT (VALUE /)
(vlax-ldata-put "STANDARDS" (vl-symbol-name (quote VALUE)) VALUE)
)

Given that

(setq CPCS_TEXTSIZE 0.25)

(DT_STANDARDS_DICTPUT CPCS_TEXTSIZE)

I can now store "CPCS_TEXTSIZE" with the value of 0.25. Before I was entering this as

(DT_STANDARDS_DICTPUT "CPCS_TEXTSIZE" CPCS_TEXTSIZE)

Which you can see was just entering the same thing twice, extra work. I'm just looking for a better mouse trap. :)

Thanks guys for the help.
 
Pardon me but (vl-symbol-name (quote value)) will
always return "value". Look at my last post for a
better way.
 
Sage,

You'll need to use quote to pass the variable name thru...

instead of > (DT_STANDARDS_DICTPUT CPCS_TEXTSIZE)

use (DT_STANDARDS_DICTPUT (quote CPCS_TEXTSIZE))

Devin
 
Here are two ways to do something similar to
what you want depending on your input preferences:

(defun test (sym)
(list
sym
(eval (read sym))))

(defun test2 (qsym)
(list
(vl-symbol-name qsym)
(eval qsym)))

(test "bob")
or
(test2 'bob)
 
I'm glad you guys are around. The value thing got by me. :) Ok here's what i've come up with.

(defun DT_STANDARDS_DICTPUT (VALUE /)
(vlax-ldata-put "STANDARDS" (vl-symbol-name VALUE) (eval VALUE))
)

Given that

(setq CPCS_TEXTSIZE 0.25)

(DT_STANDARDS_DICTPUT 'CPCS_TEXTSIZE)
 
Hi Doug,

My actual code is a little off, I should have written...

(setq bob (quote Iam))
(read (strcat (vl-symbol-name bob) " cool"))

Although he's not using the way I thought he might be, there is a use for working with symbol names instead of strings, perhaps for efficiency... For example, if you want to access a variable's value and set a value to it later...

(setq var 0.125)
(defun func (symbol / )
(princ "\npre value:")(princ (vl-symbol-value symbol))
(set symbol 0.25)
(princ "\npost value:")(princ (vl-symbol-value symbol))
)

(func 'var)
returns...
"pre value: 0.125"
"post value: 0.25"

Of course, like I think you were suggesting, you could just use a string and read it into a symbol name as well. But it makes things a little easier and cleaner to pass the variable itself with a qoute then converted into a string.

But I know there are useful uses for both ways. For instance, if you have a list of tile names in a dialog box and you want to assign a default to each one based on what the user entered last, you could use the tile string names as the variable names for their own default values. And then later populate the dialog with the defaults stored in the variable names. So I don't think it matters so much, just what the current application is.

Devin
 
Then you don't need to use quote in the function itself, just to pass the variable thru.
ie:

(defun DT_STANDARDS_DICTPUT (VALUE /)
(vlax-ldata-put "STANDARDS" (vl-symbol-name VALUE) (vl-symbol-value VALUE))
)

Given that

(setq CPCS_TEXTSIZE 0.25)

(DT_STANDARDS_DICTPUT 'CPCS_TEXTSIZE):<< notice the quote
 
Doug,

(vl-symbol-value)
might be a better approach then using eval. It's kinda like hitting thumb tack with a sledge hammer ;)

Devin
 
Good point. Pick my excuse ;-)
(defun excuses (which)
(cond
(
(cdr (assoc which
'((1 ."Eval is less typing.")
(2 . "I've always done it that way.")
(3 . "Ya can't teach an ole Dawg new tricks.)))))
(t "Eh. What'yda say?"))
 

Latest threads

Back
Top