소스 파일명: testIf.lisp
- #!/usr/bin/env clisp
- #|
- Filename: testIf.lisp
- Purpose: Example using the conditional control structure syntax
- (if cond block1 block2)
- Execute: clisp testIf.lisp [number]
- |#
- ;; 사용법을 보여주는 함수
- (defun printUsing()
- (format t "Using: clisp testIf.lisp [number]~%")
- (format t "This determines whether the number is positive or not.~%") )
- ;; 스트링을 부동소수점수로 변환하는 함수
- (defun parse-number (v)
- (with-input-from-string (s v) (read s)))
- ;; 명령행 인자의 개수가 1이 아니면 사용법을 보여준다.
- (if (< (length ext:*args*) 1)
- (printUsing) )
- (if (< (length ext:*args*) 1)
- (quit) )
- ; 명령행 인자의 스트링을 가져와서
- ; 배정밀도 부동소수점수로 변환하여
- ; 변수 val에 저장한다.
- (setf val (parse-number (nth 0 ext:*args*)) )
- ; 변수 val에 저장된 값이 양수인지 음수인지 0인지를
- ; 판단하는 (if cond block1 block2) 조건문
- (if (> val 0.0)
- (format t "~F is a positive number.~%" val)
- (if (< val 0.0)
- (format t "~F is a negative number.~%" val)
- (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.
'프로그래밍 > Common Lisp' 카테고리의 다른 글
80컬럼 컨솔에 19단표 출력하기 예제 for Common Lisp (0) | 2013.08.29 |
---|---|
(최대공약수 구하기) while... 반복문 예제 for Common Lisp (0) | 2013.08.29 |
명령행 인자 처리 예제 for Common Lisp (0) | 2013.08.29 |
구구단 출력 예제 for Common Lisp (0) | 2013.08.29 |
Hello 예제 for Common Lisp (2) | 2013.08.29 |