(princ "\nPoint #2") I don't understand why it is printed twice.

(princ "\nPoint #2") I don't understand why it is printed twice.

Anonymous
Not applicable
1,214 Views
4 Replies
Message 1 of 5

(princ "\nPoint #2") I don't understand why it is printed twice.

Anonymous
Not applicable

Hi, guys!

Please help me to understand the logic of (princ)

This is the program I have

 

+++++++++++
(defun c:PrintTest()
;(setq p2 3)
; (princ)

(princ "\nPoint #2") ;(princ p2)

;(princ (strcat "\nPoint #2 " (rtos (car p2) 2) "," (rtos (cadr p2) 2) "," (rtos (last p2) 2)))

)

+++++++++++++++

 

I pasted it "as is" without removing comments.

 

++++++++++++
When I run program, I get the following result:

 

Command: PRINTTEST
Point #2"\nPoint #2

++++++++++++

 

I don't understand why it is printed twice.

 

Thanks!

0 Likes
Accepted solutions (1)
1,215 Views
4 Replies
Replies (4)
Message 2 of 5

ВeekeeCZ
Consultant
Consultant

Since you have replied here I guess you do understand now.

 

In case you're not see the help.

 

Especially this part: ...

 

Return Values

Type: Integer, Real, String, List, Symbol, File, Ename (entity name), T, or nil

The value of the evaluated expr. If called with no arguments, princ returns a null symbol.

 

The red part is why it is twice. The blue one why we put (princ) at the and to avoid previous.

Message 3 of 5

Anonymous
Not applicable

Thanks for reply! 

Now, I know how to fix this situation,

but I don't understand why it works

 

The first (princ "\nPoint #2") returns vallue,

the second (princ) returns null

 

So, I don't understand why second null prevent returning value of the the first princ?

Thanks!

0 Likes
Message 4 of 5

ВeekeeCZ
Consultant
Consultant
Accepted solution

@Anonymous wrote:

Thanks for reply! 

Now, I know how to fix this situation,

but I don't understand why it works

 

The first (princ "\nPoint #2") returns vallue,

the second (princ) returns null

 

So, I don't understand why second null prevent returning value of the the first princ?

Thanks!


It's not. In command line you can see just last one. 

 

Try to write into command line this:

(setq a 1)

then !a to get value of a

Then (setq b 1)(princ)

try !b

So see help what setq returns. If you put (princ) right behind... you'll see nothing. But it's still there. You can catch it with 

(setq d (setq c 2))(princ)

then if you type !d it returns same value as !c which is 2.

 

Message 5 of 5

Anonymous
Not applicable

It's not. In command line you can see just last one. 

 

Yes, this explain the issue!
thanks!

0 Likes