PDA

View Full Version : Lisp Question: mathematically create setq's


K.D. Wiegand
09-04-1998, 04:11 AM
I want to inquire list-length, of a created list. Then mathmatically create setq's <example> (setq L 1 (+ L 1)) Object: Create L1 L2 etc. til list-length is achieved Can it be done in some fasion?

Markus Kuehl
09-06-1998, 07:20 PM
Sorry, but I don't understand your question. What do you want to achieve exactly? Can you explain your problem a little bit more in detail?

Claus Brod
09-06-1998, 11:42 PM
Hi,<p> to inquire the length of a list, simply use "length":<p> <pre> (setf mylist '("foo" "bar" "42")) (setf len (length mylist)) </pre> I am not quite sure about the second part of your question. My understanding is that you want to create a list of N items (where N is determined by the length of a list created elsewhere), and each item is of the form "L<sequence number>". If so, the following code segment would do the trick:<p> <pre> (defparameter *mycounter* 0) (defun mycountfnc (x) (format nil "L~A" (setq *mycounter* (+ 1 *mycounter*))) (mapcar #'mycountfnc mylist) </pre> This code assumes that the list which determines the length of the output is <tt>mylist</tt>. It is not very elegant since it involves the use of a global variable <tt>*mycounter*</tt> which needs to be initialized before the <tt>mapcar</tt> call. The LISP gurus in the group will certainly find a much better way.<p> Hope this helps,<p> Claus

Claus Brod
09-07-1998, 08:32 PM
&gt;&nbsp; and each item is of the form "L".<p> Oh, the joys of HTML formatting. What I really wanted to write was:<p> ...and each item is of the form "L&lt;sequencenumber&gt;".

UweKlimmeck
08-04-1999, 01:47 AM
Hallo, it's a little bit late, but here is my "solution". I think you need N symbols like TEST1 TEST2 TESTN where N is the length of a List. (eval (read-from-string (format nil "(setq AUTO~A "~A")" 222 "Hallo" ) ) ) This make a symbol "AUTO222" with a value "Hallo" Looping this construction N-times with calculateted values, I think this helps.