Author Topic: Why with princ  (Read 1777 times)

0 Members and 1 Guest are viewing this topic.

Adesu

  • Guest
Why with princ
« on: December 12, 2007, 04:24:33 AM »
What happend with princ function in that code, if you use sample 1 is OK but with sample 2 it can not use.

sample 1
Code: [Select]
; idea from Josh
(defun comma (a / b d e f g)
   (setq b (fix a))
   (setq d (itoa b))
   (setq e (strlen d))
   (setq f "")
   (setq g "")
   (while
      (> e 3)
      (setq f (strcat "," (substr d (- e 2)) f))
      (setq d (substr d 1 (- e 3)))
      (setq e (- e 3))
      ) ; while
   (setq f (strcat d f g))
   ) ; defun

(comma 123498)

sample 2
Code: [Select]
; idea from Josh
(defun comma (a / b d e f g)
   (setq b (fix a))
   (setq d (itoa b))
   (setq e (strlen d))
   (setq f "")
   (setq g "")
   (while
      (> e 3)
      (setq f (strcat "," (substr d (- e 2)) f))
      (setq d (substr d 1 (- e 3)))
      (setq e (- e 3))
      ) ; while
   (setq f (strcat d f g))
   (princ)
   ) ; defun

(comma 123498)

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Why with princ
« Reply #1 on: December 12, 2007, 07:09:53 AM »
If you mean that the 2nd example doesn't return anything, that is the entention of the princ function.  If want your sub to return a value then you cannot use (princ) at the very end of the function.
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

daron

  • Guest
Re: Why with princ
« Reply #2 on: December 12, 2007, 09:23:37 AM »
or, you must use (princ f)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Why with princ
« Reply #3 on: December 12, 2007, 09:30:15 AM »
You will see in many routine this line
Code: [Select]
(princ) ; exit quietly
The point is that (princ) returns nothing and therefor makes no noise. 8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Adesu

  • Guest
Re: Why with princ
« Reply #4 on: December 12, 2007, 06:29:40 PM »
Thanks to alls for your comment.