Jump to content

vl-print-to-string bugged or me missing something?


Jef!

Recommended Posts

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. :P

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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! :D

 

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!

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...