Quantcast
Channel: Lisp - How to call a function within another function? - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by Dinesh Vilas Pawar for Lisp - How to call a function within another function?

$
0
0

As far as I know, you can not send function name as the parameter, but here I give you a technic which can act like similar.

I don't have Autocad install on my machine so I am unable to test this code. but you can remove if there is any small mistake or grab the concept so you can implement your own.

(defun c:Add ()    (setq a (getint "Enter a number to add 2 to it"))    (setq a (+ a 2)))(defun c:sub ()    (setq a (getint "Enter a number to substract from 2:"))    (setq a (-2 a)))(defun c:mul ()    (setq a (getint "Enter a number to multiply with 2:"))    (setq a (* a 2)));----This function use to call other function from function name;----Function name string is case sensitive;----As per need you can Add function name to this function(Defun callFunction(name)(setq output nil);here you can add nested if condition but for simplicity I use If alone(if (= name "C:Add")(setq output (C:Add)))(if (= name "C:sub")(setq output (C:sub)))(if (= name "C:mul")(setq output (C:mub)))output);----------Function end here(defun LOOPER (func)    ;repeats 'func' until user enters 'no'    (setq dummy "w")    (while dummy        (callFunction func) ;Change here        (setq order (getstring "\nContinue? (Y or N):"))        (if (or (= order "N") (= order "n")) (setq dummy nil))    ))

You like run this program like this:

(defun c:Adder ()    (LOOPER ("c:Add")))(defun c:substaker ()    (LOOPER ("c:sub")))(defun c:multiplyer ()    (LOOPER ("c:mul")))

Hope this helps:


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>