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 Dolist Construct

(dolist (n '(1 2 3 4 5 6 7 8 9))
   (format t "~% Number: ~d Square: ~d" n (* n n))
)

Lisp Dotimes Construct

(dotimes (n 11)
   (print n) (prin1 (* n n))
)

Lisp Do Construct

(do ((x 0 (+ 2 x))
   (y 20 ( - y 2)))
   ((= x y)(- x y))
   (format t "~% x = ~d  y = ~d" x y)
)

Lisp Loop For Construct Example3

(loop for x from 1 to 20
   if(evenp x)
   do (print x)
)

Lisp Loop For Construct Example2

(loop for a from 10 to 20
   do (print a)
)

Lisp Loop For Construct Example1

(loop for x in '(tom dick harry)
   do (format t " ~s" x)
)

Lisp Loop Construct

(setq a 10)
(loop 
   (setq a (+ a 1))
   (write a)
   (terpri)
   (when (> a 17) (return a))
)

Lisp Gracefully Exiting from Block

(defun demo-function (flag)
   (print 'entering-outer-block)
   
   (block outer-block
      (print 'entering-inner-block)
      (print (block inner-block
      
         (if flag
            (return-from outer-block 3)
            (return-from inner-block 5)
         )
         
         (print 'This-wil--not-be-printed))
      )
      
      (print 'left-inner-block)
      (print 'leaving-outer-block)
   t)
)
(demo-function t)
(terpri)
(demo-function nil)

Lisp Case Construct

(setq day 4)
(case day
(1 (format t "~% Monday"))
(2 (format t "~% Tuesday"))
(3 (format t "~% Wednesday"))
(4 (format t "~% Thursday"))
(5 (format t "~% Friday"))
(6 (format t "~% Saturday"))
(7 (format t "~% Sunday")))

Lisp When Construct

(setq a 100)
(when (> a 20)
   (format t "~% a is greater than 20"))
(format t "~% value of a is ~d " a)

Advertisements
Loading...

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