#1
|
|||
|
|||
variable formulation
I have these variable ones
(setf tmp1 "/image") (setf tmp2 "/pic") (setf num-p 1) (setf tmp-tot (format nil "tmp~A" num-p)) Why the result of the variable tmp-tot is not the value of the variable one "tmp1" but it is string it "tmp1"? I wanted like result of tmp-tot the value of the variable one tmp1 .... it is possible? P.S: The solution would be easy (setf tmp-tot tmp1) But cosi I cannot must depend also on the variable one num-1 Why if the variable one (setf num-p 2) the final value of tmp-tot it must be equal to the value of the variable one tmp2 (/pic). Last edited by andrea; 01-24-2005 at 07:07 AM. |
#2
|
||||
|
||||
Re: variable formulation
Hi Andrea,
The following line will do the trick: Code:
(setf tmp-tot (eval(read-from-string(format nil "tmp~A" num-p)))) Last eval will read the value of the symbol. Hope this helps, John
__________________
High performance CAD workstations Please visit us at https://www.cadware.nl |
#3
|
||||
|
||||
Re: variable formulation
Don't get me wrong, I'm not trying to pick on you - but I'd really recommend to buy a book on LISP and read it, or at least work through a tutorial. If you don't understand why the format statement behaves like it does, you can probably save yourself a *LOT* of time by learning the basics first. You'll find links to free online and commercial LISP books at http://www.clausbrod.de/Osdm/OsdmFaqLinks .
(format nil "tmp~A" num-p) takes the value (!) of num-p (which is 1) and converts it according to the conversion specifier ~A, i.e. it converts it into its string representation. Which is why format's result is "tmp1". See also the documentation on format at http://www.lisp.org/HyperSpec/Body/fun_format.html#format . If you need an indirection, you could create an array of LISP strings (via make-array, see http://www.lisp.org/HyperSpec/Body/fun_make-array.html for details) and use num-p as an index into it. If you know that the list of values is small, you could simply use a LISP list: Code:
(setf vals '("/image" "/pic")) (setf num-p 1) ;; first entry = 0, second entry = 1 (setf tmp-tot (nth num-p vals)) Claus
__________________
CoCreate Modeling FAQ: http://www.clausbrod.de/CoCreateModeling/ Last edited by clausb; 01-24-2005 at 09:41 PM. |
#4
|
|||
|
|||
Re: variable formulation
Thanks John van Doorn are perfect.....
|
#5
|
||||
|
||||
Re: variable formulation
Andrea,
Glad I could help, but I have to agree with Claus, that the provided solution is not a good practice. So if I where you, I would seriously consider Claus advice John
__________________
High performance CAD workstations Please visit us at https://www.cadware.nl |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | Search this Thread |
Display Modes | Rate This Thread |
|
|