juicyorange Posted June 6, 2019 Share Posted June 6, 2019 Hey all, I am having an issue where I grab an element from a list and set it to a var and the var is a "SYM" data type. I am trying to test for that data type and then convert it into a string. However, my current test: (if (= (type PtNo) "SYM") (setq PtNo (vl-symbol-name PtNo)) ;;end if ) Doesn't return true. Any and all insights into this are welcome. Quote Link to comment Share on other sites More sharing options...
dlanorh Posted June 6, 2019 Share Posted June 6, 2019 It works for me with minimum testing. What string are you expecting (vl-symbol-name PtNo) to return? Quote Link to comment Share on other sites More sharing options...
juicyorange Posted June 6, 2019 Author Share Posted June 6, 2019 (edited) Sorry, I should be more clear. When I test for "SYM" it isn't returning true when it actually is a data type "SYM", it just skips over the "then" part of the if function. Here's the full code: NOTE: I am still working on proof of concept, I'll be doing all of the error trapping when I can get it to work the way I need it to. I also haven't cleaned it up yet. ;; This lisp routine xxx (vl-load-com) (defun c:ImportCSV (/ csvfile Opencsvfile csvdataline readline ctr n readlinestring readlinelist xval yval zval ptno descr coord coordtext test) ;-----------------------------------------------------------------------; ;; error handler (defun *error* (msg) (princ "\nError: ") (princ msg) (princ) ) ;-----------------------------------------------------------------------; (setq csvfile (getfiled "Select CSV File" "C:/Users/Jesse/Desktop/" "csv" 10 ) ;;end setq ) (setvar "CMDECHO" 0) (setq OpenCsvFile (open csvfile "r")) (while (setq CsvDataLine (read-line OpenCsvFile) ReadLine CSVDataLine ) (setq ctr 0) ;;delete " (while (if (setq n (vl-string-search "\"" Readline 0)) (setq Readline (vl-string-subst " " "\"" Readline ctr) ctr n ) ;;end if ) ;;end while ) (setq ctr 0) ;;delete spaces (while (if (setq n (vl-string-search " " Readline 0)) (setq Readline (vl-string-subst "" " " Readline ctr) ctr n ) ;;end if ) ;;end while ) (setq ctr 0) ;;replace commas with spaces (while (if (setq n (vl-string-search "," Readline 0)) (setq Readline (vl-string-subst " " "," Readline ctr) ctr n ) ;;end if ) ;;end while ) (setq ReadLineString (strcat "(" Readline ")") ReadLineList (read ReadLineString) XVal (cadr ReadLineList) YVal (caddr ReadLineList) ZVal (cadddr ReadLineList) PtNo (car ReadLineList) Coord (list XVal YVal ZVal) ) (setq test (type PtNo)) (if (= (type PtNo) "SYM") (setq PtNo (vl-symbol-name PtNo)) ;;end if ) (setq test (type PtNo)) (if ( = (length ReadLineList) 5) (progn (setq Descr (nth 4 ReadLineList) Descr (vl-symbol-name Descr) ) (command "_.point" Coord "_.text" Coord ".1" "" PtNo "_.text" Coord ".1" "" Descr ) (setq txtbx (entlast)) (command "_.move" txtbx "" "0,0" "0,-0.12") ;;end progn ) (command "_.point" Coord "_.text" Coord ".1" "" PtNo ) ;;end if ) ;;end while ) (close OpenCSVFile) (setvar "PDMODE" 35) (setvar "PDSIZE" 0.2) (setvar "CMDECHO" 1) ;;End Defun ) Edited June 6, 2019 by juicyorange Quote Link to comment Share on other sites More sharing options...
ronjonp Posted June 6, 2019 Share Posted June 6, 2019 (edited) If you're reading a CSV and looking at the (type) it will always return 'STR ? Maybe you're trying to see if the text = "SYM" ? If so then this should work: (if (= ptno "SYM") (setq ptno (vl-symbol-name ptno)) ;;end if ) Edited June 6, 2019 by ronjonp Quote Link to comment Share on other sites More sharing options...
juicyorange Posted June 6, 2019 Author Share Posted June 6, 2019 Per the attached debug screenshot, you can see when i test for the type of the PtNo var I get "SYM" Quote Link to comment Share on other sites More sharing options...
ronjonp Posted June 6, 2019 Share Posted June 6, 2019 (edited) Hmmm .. then all you have to do is change your syntax: (= 'sym (type ptno)) I did not read all your code to see this part that converts to numbers and a symbol: (setq ReadLineString (strcat "(" Readline ")") ReadLineList (read ReadLineString) Edited June 6, 2019 by ronjonp Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 6, 2019 Share Posted June 6, 2019 The type function returns a symbol, not a string (regardless of the data type held by a variable), therefore you need to compare the value returned by the type function with a symbol, not a string as in your current code. Observe the following: _$ (setq a "string") "string" _$ (type a) STR _$ (type (type a)) SYM _$ (setq a 'b) B _$ (type a) SYM _$ (type (type a)) SYM _$ (= 'sym (type a)) T Quote Link to comment Share on other sites More sharing options...
juicyorange Posted June 6, 2019 Author Share Posted June 6, 2019 (edited) that worked swimmingly! thanks ronjonp! Edited June 6, 2019 by juicyorange Quote Link to comment Share on other sites More sharing options...
juicyorange Posted June 6, 2019 Author Share Posted June 6, 2019 28 minutes ago, Lee Mac said: The type function returns a symbol, not a string (regardless of the data type held by a variable), therefore you need to compare the value returned by the type function with a symbol, not a string as in your current code. Observe the following: _$ (setq a "string") "string" _$ (type a) STR _$ (type (type a)) SYM _$ (setq a 'b) B _$ (type a) SYM _$ (type (type a)) SYM _$ (= 'sym (type a)) T Thanks for the explanation, this makes more sense now! Quote Link to comment Share on other sites More sharing options...
ronjonp Posted June 7, 2019 Share Posted June 7, 2019 On 6/6/2019 at 3:58 PM, juicyorange said: that worked swimmingly! thanks ronjonp! Glad to help Quote Link to comment Share on other sites More sharing options...
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.