Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Lisp Mapping Functions Example1

(write (mapcar '1+  '(23 34 45 56 67 78 89)))

Lisp Lambda Functions

(write ((lambda (a b c x)
   (+ (* a (* x x)) (* b x) c))
   4 2 9 3)
)

Lisp Returning Values Function Example

(defun myfunc (num)
   (return-from myfunc 10)
   write num
)
(write (myfunc 20))

Lisp Returning Values Function Example2

(defun myfunc (num)
   (return-from myfunc 10)
   num
)
(write (myfunc 20))

Lisp Returning Values Function Example1

(defun add-all(a b c d)
   (+ a b c d)
)
(setq sum (add-all 10 20 30 40))
(write sum)
(terpri)
(write (add-all 23.4 56.7 34.9 10.0))

Lisp Keyword Parameters

(defun show-members (&key a b c d ) (write (list a b c d)))
(show-members :a 1 :c 2 :d 3)
(terpri)
(show-members :a 'p :b 'q :c 'r :d 's)
(terpri)
(show-members :a 'p :d 'q)
(terpri)
(show-members :a 1 :b 2)

Lisp Rest Parameters

(defun show-members (a b &rest values) (write (list a b values)))
(show-members 1 2 3)
(terpri)
(show-members 'a 'b 'c 'd)
(terpri)
(show-members 'a 'b)
(terpri)
(show-members 1 2 3 4)
(terpri)
(show-members 1 2 3 4 5 6 7 8 9)

Lisp Optional Parameters

(defun show-members (a b &optional c d) (write (list a b c d)))
(show-members 1 2 3)
(terpri)
(show-members 'a 'b 'c 'd)
(terpri)
(show-members 'a 'b)
(terpri)
(show-members 1 2 3 4)

Lisp Defining Function Example2

(defun area-circle(rad)
   "Calculates area of a circle with given radius"
   (terpri)
   (format t "Radius: ~5f" rad)
   (format t "~%Area: ~10f" (* 3.141592 rad rad))
)
(area-circle 10)

Lisp Defining Function Example1

(defun averagenum (n1 n2 n3 n4)
   (/ ( + n1 n2 n3 n4) 4)
)
(write(averagenum 10 20 30 40))

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.