DzRabeh Posted September 20 Posted September 20 I have probleme with use of set function error: Argument type incorrect: symbolp (NTH COUNT LIST_VARIABLES) Any help please? (defun c:sectionPOTEAU () ;; Import variables form file (setq name_file (getfiled "Select txt file..." "D:\\" "txt" 4) read_file (open name_file "r") pot_larg pot_haut pot_enrob pot_HA14 pot_longCoude pot_raduisCoude pot_enrob_HA07 pot_LWPOLY_WIDTH ;;declare variables list_variables '(pot_larg pot_haut pot_enrob pot_HA14 pot_longCoude pot_raduisCoude pot_enrob_HA07 pot_LWPOLY_WIDTH) ) (if read_file (progn (setq count 0) (while (setq text_line (atof (read-line read_file))) ;;read line & convert text to float (set '(nth count list_variables) text_line) ;; set variable value (setq count (1+ count)) ) ;;while ) ;;progn ) ;;if (close read_file) ) Quote
Lee Mac Posted September 22 Posted September 22 (edited) The issue here is that the nth expression is quoted and is therefore unevaluated before being passed to the set function; set requires a symbol argument as the first argument and therefore cannot assign the value value to a list. You will also run into problems when reaching the end of the file, as read-line will return nil and (atof nil) will return an error. The line at which you 'declare variables' is also incorrect and only syntactically correct because you have an even number of variables; this line is essentially assigning the value of every other variable to every other symbol. Edited September 22 by Lee Mac Quote
Lee Mac Posted September 22 Posted September 22 I might suggest something like the following (untested); (defun c:sectionPOTEAU ( / des fnm lst str ) (cond ( (not (setq fnm (getfiled "Select Text File" "D:\\" "txt" 16)))) ( (not (setq des (open fnm "r"))) (princ "\nUnable to open file.") ) ( t (setq lst '(pot_larg pot_haut pot_enrob pot_HA14 pot_longCoude pot_raduisCoude pot_enrob_HA07 pot_LWPOLY_WIDTH)) (while (and (setq sym (car lst)) (setq str (read-line des)) ) (set sym (atof str)) (setq lst (cdr lst)) ) (close des) ) ) (princ) ) Though, you'll want to ensure that the symbols in the list are declared local elsewhere in your application else they will reside in the document namespace and hence could clash/be overwritten by other applications. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.