;; File:  Mkfun.lsp - Demonstrate how to define a "mkfun" function

;; make life a bit easier...

(setq fn "C:/Temp/mkfun/mkfun.lsp")
(defun L () (cls) (load fn))  (defun x () (exit))
(dribble "C:/Temp/mkfun/out.txt")

;; now, get down to work...

(terpri)
(defun add1 (n) (+ n 1))                   ;; a simple +1 function
(defun add2 (n) (+ n 2))                   ;; a simple +2 function
(format T "(add1 5) is ~S ~%" (add1 5))    ;; demonstrate add1
(format T "(add2 5) is ~S ~%" (add2 5))    ;; demonstrate add2
(terpri)

;; mkfun allows us to create addN functions
(defun mkfun (fcnName amount) "creates a function using defun"
    (setq fcnDef (list 'defun fcnName '(n) (list '+ 'n amount)))
    (format T "fcnDef = ~S ~%~%" fcnDef)
    (eval fcnDef)
)

(mkfun 'add3 3)                            ;; use mkfun to define a +3 function
(mkfun 'add7 7)                            ;; use mkfun to define a +7 function
(format T "(add3 5) is ~S ~%" (add3 5))    ;; demonstrate add3
(format T "(add7 7) is ~S ~%" (add7 7))    ;; demonstrate add7

(dribble)

;; =====================================
;; Output from the above:
;;
;; (add1 5) is 6 
;; (add2 5) is 7 
;;
;; fcnDef = (DEFUN ADD3 (N) (+ N 3)) 
;;
;; fcnDef = (DEFUN ADD7 (N) (+ N 7)) 
;;
;; (add3 5) is 8 
;; (add7 7) is 14 
;; =====================================
