소스 파일명: testIf.lisp

  1. #!/usr/bin/env clisp
  2. #|
  3.    Filename: testIf.lisp
  4.    Purpose:  Example using the conditional control structure syntax
  5.                  (if cond block1 block2)
  6.    Execute: clisp testIf.lisp [number]
  7. |#
  8. ;; 사용법을 보여주는 함수
  9. (defun printUsing()
  10.    (format t "Using: clisp testIf.lisp [number]~%")
  11.    (format t "This determines whether the number is positive or not.~%") )
  12. ;; 스트링을 부동소수점수로 변환하는 함수
  13. (defun parse-number (v)
  14.      (with-input-from-string (s v) (read s)))
  15. ;; 명령행 인자의 개수가 1이 아니면 사용법을 보여준다.
  16. (if (< (length ext:*args*) 1)
  17.     (printUsing) )
  18. (if (< (length ext:*args*) 1)
  19.     (quit) )
  20. ; 명령행 인자의 스트링을 가져와서
  21. ; 배정밀도 부동소수점수로 변환하여
  22. ; 변수 val에 저장한다.
  23. (setf val (parse-number (nth 0 ext:*args*)) )
  24. ; 변수 val에 저장된 값이 양수인지 음수인지 0인지를
  25. ; 판단하는 (if cond block1 block2) 조건문
  26. (if (> val 0.0)
  27.     (format t "~F is a positive number.~%" val)
  28.     (if (< val 0.0)
  29.         (format t "~F is a negative number.~%" val)
  30.         (format t "~F is zero." val)))


 

실행> clisp testIf.lisp
Using: clisp testIf.lisp [number]
This determines whether the number is positive or not.

실행> clisp testIf.lisp 1.02
1.02 is a positive number.

실행> clisp testIf.lisp -1.02
-1.02 is a negative number.

실행> clisp testIf.lisp 0
0.0 is zero.




Posted by Scripter
,