별의 공부 블로그 🧑🏻‍💻
728x90
728x170
(defun read-a-number ()
   (do ((answer nil))
       (nil)      ; This is necessary to make Infinite Loop function.
     (format t "~&Please type a number: ")
     (setf answer (read))
     (if (numberp answer) (return answer)  

       (format t t "~&Sorry, ~S is not a number. Try again." answer))))

A Program which checks whether the input number is a number or not by using DO macro.

If the input number is not a number, the program prints "Sorry, ~ is not a number. Try Again. " "Please type a number: " repetitively until you input a number.

 

The point is that (nil) is used in the test part of DO macro.

 

It is interesting that this program can get your input element by puting (setf answer (read)).

728x90
그리드형(광고전용)

'Source Code > LISP (CL)' 카테고리의 다른 글

Block's World  (0) 2017.06.08
samesetp  (0) 2017.05.31
Tic Tac Toe Game  (0) 2017.05.30
입출력 (INPUT / OUTPUT)  (0) 2017.05.18
순환 (Recursion)  (0) 2017.05.16
⚠️AdBlock이 감지되었습니다. 원할한 페이지 표시를 위해 AdBlock을 꺼주세요.⚠️
starrykss
starrykss
별의 공부 블로그 🧑🏻‍💻


📖 Contents 📖