lisp function value return

lisp function value return

GeryKnee
Advocate Advocate
2,381 Views
2 Replies
Message 1 of 3

lisp function value return

GeryKnee
Advocate
Advocate

 

Hello everyone,

Is there a way to get retained values from a function ??

In the folowing i wish to get the canged by fni value of Val1 


(defun fNotify (Value)
(princ (strcat "\n" (strcat "------> " (vl-princ-to-string Value))))
(princ "\n" )
(princ)
)

(defun fn1 (Val1 )
(setq Val1  123)
(fNotify Val1)  ;;;; ------> 123
)

(defun c:xx(/ Val1 )
(setq Val1  1 )  ------> 1
(fn1 Val1 )
(fNotify Val1 ) ------> 1 (not 123)
)

Thanks,

Gery

0 Likes
Accepted solutions (1)
2,382 Views
2 Replies
Replies (2)
Message 2 of 3

hak_vz
Advisor
Advisor
Accepted solution

 

 

; here Val1 is defined as global variable that can be availabla to any other
;function

(defun fn1 (Val1 )
(setq Val1  123)
(fNotify Val1)  ;;;; ------> 123
)


(defun c:xx(/ Val1 ) ; Val1 is defined as local variable to function
;anything after / is consider local variable
(setq Val1  1 )  ------> 1 ; you are setting this local value
(fn1 Val1 ) ; running function with local value
(fNotify Val1 ) ------> 1 (not 123) ; it calls local value that is set to 1 ; ;so it returns 1
)

 

 

 

(setq Val1 123) ;;; this is global variable

(defun fNotify (Value)
(princ (strcat "\n" (strcat "------> " (vl-princ-to-string Value))))
(princ "\n" )
(princ)
)

(defun fn1 ()
(setq Val1  123)
(fNotify Val1)
)

(defun c:xx()
(fn1 Val1 )
(fNotify Val1)
)

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 3 of 3

GeryKnee
Advocate
Advocate

thank you hak_vz

So I Have to write as following:

 


(defun c:xx( / Val1)
(defun fn1 () 
(setq Val1 123)  

(fn1)
(fNotify Val1) ;;;; the value of Val1  here is 123
)

 

 

thank you very much,

regards,

Gery.

0 Likes