Jef! Posted December 12, 2017 Share Posted December 12, 2017 I just wasted quite some time figuring out why my code was not working as expected (using CAD 2015). Just not sure what to make of it. Let's play. (setq aa "bar") (setq x "aa") Based on (princ aa) returning bar"bar" (return bar + echo "bar", right?) With that (eval (read x)) returns> "bar" (returns nothing, just echo?), and (type(eval (read x))) returns> STR (progn (princ "type: ") (princ (type (eval (read x)))) (princ " & value: ") (princ (eval (read x))) (princ) ) returns> type: STR & value: bar It was what I was expecting using vl-princ-to-string as a "fail safe princ" but (progn (princ "type: ") (vl-princ-to-string (type (eval (read x)))) (princ " & value: ") (vl-princ-to-string (eval (read x))) (princ) ) returns> type: & value: (vl-princ-to-string (eval (read x))) returns> "bar" (just the echo?) (princ (eval (read x))) returns> bar"bar" (returns + echo) testing further (vl-princ-to-string (eval (read x)))(princ) (returns nothing as the princ supress the echo) (princ (eval (read x)))(princ) returns> bar (returns without echo) I was starting to think eval just echo and returns nothing, but as (type (eval (read x))) tells me that it is a STR, how come vl-princ-to-string not able to "deal" with it? What am I missing? funfunfun. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 12, 2017 Share Posted December 12, 2017 I'm not quite sure what you're asking, but note that the vl-princ/prin1-to-string functions just return a string representation of the supplied argument (as if it had been supplied to princ/prin1) but do not print it to the command-line. Quote Link to comment Share on other sites More sharing options...
Jef! Posted December 13, 2017 Author Share Posted December 13, 2017 If the vl-princ/prin1-to-string functions just return a string representation of the supplied argument (as if it had been supplied to princ/prin1), my question was why in this example the 2 vl-princ-to-string returns nothing, while swapping them by princ works and show that the supplied (eval (read x)) is a string and its value (progn (setq aa "bar") (setq x "aa") (princ "type: ") (vl-princ-to-string (type (eval (read x)))) [b]< doesn't return anything[/b] (princ " & value: ") (vl-princ-to-string (eval (read x))) [b]< doesn't return anything[/b] (princ) ) with princ the example returns this > type: STR & value: bar with vl-princ-to-string the example returns this > type: & value: The help only says "Returns the string representation of LISP data as if it were output by the princ function", which I didn't understand as "but do not print it to the command-line". With that in mind, it now is understandable. Thanks for un-breaking my brain Lee! For others who would find this by keywords: Basically, if you want to monitor a variable or any data on the fly without having to be bothered by different data types, use (princ (vl-princ-to-string *variable-or-expression-to-monitor*)) Cheers Jef! Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted December 13, 2017 Share Posted December 13, 2017 I use (print ...) for that purpose. 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.