Commonn Lisp 언어는 S-신택스라고 불리우는 구문 즉,

       (함수명 파라미터1 파라미터2 ... 파라미터n)

 인 형태의 구문을 사용한다. 예를 들어 뺄셈을 할 때에도

      (- 2 3 5 7)

라는 구문은 수학식 2 - 3 - 5 - 7 을 계산한 결과를 얻는다.



* CLisp  용 소스 파일: first-sample-2.lsp
#!/usr/bin/env clisp

;; 파일명: first-sample-2.lsp


(defun lg(x):
    (/ (log x) (log 2)) )
   
(defun log10(x):
    (/ (log x) (log 10)) )
   
(format t "이 소스는 CLisp 를 이용하여 실행됨!~%")
(format t "----------------~%")
(format t "수학식 계산하기:~%")
(format t "----------------~%")
(format t "pi + e = (+ pi (exp 1)) = ~A~%" (+ pi (exp 1)))
(format t "pi * e = (* pi (exp 1)) = ~A~%" (* pi (exp 1)))
(format t "sqrt(pi) + sqrt(e) = (+ (sqrt pi) (sqrt (exp 1))) = ~A~%" (+ (sqrt pi) (sqrt (exp 1))))
(format t "sqrt(pi + e) = (sqrt (+ pi (exp 1))) = ~A~%" (sqrt (+ pi (exp 1))))
(format t "sqrt(pi) - sqrt(e) = (- (sqrt pi) (sqrt (exp 1))) = ~A~%" (- (sqrt pi) (sqrt (exp 1))))
(format t "sqrt(pi - e) = ~A~%" (sqrt (- pi (exp 1))))
(format t "sin(pi) = (sin pi) = ~A~%" (sin pi))
(format t "cos(pi) = (cos pi = ~A~%" (cos pi))
(format t "tan(pi) = (tan pi) = ~A~%" (tan pi))
(format t "ln(e) = (log (exp 1)) = ~A~%" (log (exp 1)))
(format t "(lg 2) = (log2 2) = ~A~%" (lg 2))
(format t "(log10 (/ 1.0 10)) = ~A~%" (log10 (/ 1.0 10)))
(format t "pow(2, 10) = (expt 2 10) = ~A~%" (expt 2 10))
(format t "pow(2, 100) = (expt 2 10) = ~A~%" (expt 2 100))
(format t "pow(2, 1000) = (expt 2 1000) = ~A~%" (expt 2 1000))
(format t "len(str(pow(2, 1000))) = ~A = ~A~%" "(length (format nil \"~A\" (expt 2 100000)))" (length (format nil "~A" (expt 2 100000))))


 


* 실행 결과:


이 소스는 CLisp 를 이용하여 실행됨!
----------------
수학식 계산하기:
----------------
pi + e = (+ pi (exp 1)) = 5.8598742
pi * e = (* pi (exp 1)) = 8.539734
sqrt(pi) + sqrt(e) = (+ (sqrt pi) (sqrt (exp 1))) = 3.421175
sqrt(pi + e) = (sqrt (+ pi (exp 1))) = 2.4207177
sqrt(pi) - sqrt(e) = (- (sqrt pi) (sqrt (exp 1))) = 0.123732634
sqrt(pi - e) = 0.6506235
sin(pi) = (sin pi) = -5.0165576136843360246L-20
cos(pi) = (cos pi = -1.0L0
tan(pi) = (tan pi) = 5.0165576136843360246L-20
ln(e) = (log (exp 1)) = 0.99999994
(lg 2) = (log2 2) = 1.0
(log10 (/ 1.0 10)) = -1.0
pow(2, 10) = (expt 2 10) = 1024
pow(2, 100) = (expt 2 10) = 1267650600228229401496703205376
pow(2, 1000) = (expt 2 1000) = 1071508607186267320948425049060001810561404811705
53360744375038837035105112493612249319837881569585812759467291755314682518714528
56923140435984577574698574803934567774824230985421074605062371141877954182153046
47498358194126739876755916554394607706291457119647768654216766042983165262438683
7205668069376
len(str(pow(2, 1000))) = (length (format nil "~A" (expt 2 100000))) = 30103


 

 

Posted by Scripter
,