▒ Common Lips 소스:  testStringReverse.lsp

#!/usr/bin/env clisp

(defun my-string-reverse (s)
    (let* ((arr (concatenate 'list s))
           (arr2 (reverse arr)))
        (format nil "~{~A~^~}" arr2)
    )
)

(setf s "Hello, world!")
(setf s2 "안녕하세요?")


(format t "s = ~A~%" s)
(format t "(reverse s) = ~A~%" (reverse s))
(format t "(my-string-reverse s) = ~A~%" (my-string-reverse s))
(format t "s2 = ~A~%" s2)
(format t "(reverse s2) = ~A~%" (reverse s2))
(format t "(my-string-reverse s2) = ~A~%" (my-string-reverse s2))

;; --------------------------------------------------------------
;; 출력 결과(CLisp 에서  MS949 인코딩으로 소스를 저장한 경우):
;;    s = Hello, world!
;;    (reverse s) = !dlrow ,olleH
;;    (my-string-reverse s) = !dlrow ,olleH
;;    s2 = 안녕하세요?
;;    (reverse s2) = ?요세하녕안
;;    (my-string-reverse s2) = ?요세하녕안




위의 예제에서 보듯이 CP949 한글의 문자열을 거꾸로 하기가 CLisp의 경우에는 잘 동작함이 확인되었다.
이를 대화형 모드(inttractive mode) CLisp에서 다시 한번 확인해 보자.

[CLisp의 대화형 모드에서 실행한 경우]---------------------
명령 프롬프트> clisp
 i i i i i i i       ooooo    o        ooooooo   ooooo   ooooo
  I I I I I I I      8     8   8           8     8     o  8    8
  I  \ `+' /  I      8         8           8     8        8    8
   \  `-+-'  /       8         8           8      ooooo   8oooo
    `-__|__-'        8         8           8           8  8
        |            8     o   8           8     o     8  8
  ------+------       ooooo    8oooooo  ooo8ooo   ooooo   8

Welcome to GNU CLISP 2.49 (2010-07-07) <http://clisp.cons.org/>

Copyright (c) Bruno Haible, Michael Stoll 1992, 1993
Copyright (c) Bruno Haible, Marcus Daniels 1994-1997
Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998
Copyright (c) Bruno Haible, Sam Steingold 1999-2000
Copyright (c) Sam Steingold, Bruno Haible 2001-2010

Type :h and hit Enter for context help.

[1]> (setf s "Hello, world!")
"Hello, world!"
[2]> (setf s2 "안녕하세요?")
"안녕하세요?"
[3]> (defun my-string-reverse (s)
    (let* ((arr (concatenate 'list s))
           (arr2 (reverse arr)))
        (format nil "~{~A~^~}" arr2)
    )
)
MY-STRING-REVERSE

Break 1 [7]> (format t "s = ~A~%" s)
s = Hello, world!
NIL
Break 1 [7]> (format t "(reverse s) = ~A~%" (reverse s))
(reverse s) = !dlrow ,olleH
NIL
Break 1 [7]> (format t "(my-string-reverse s) = ~A~%" (my-string-reverse s))
(my-string-reverse s) = !dlrow ,olleH
NIL
Break 1 [7]> (format t "s2 = ~A~%" s2)
s2 = 안녕하세요?
NIL
Break 1 [7]> (format t "(reverse s2) = ~A~%" (reverse s2))
(reverse s2) = ?요세하녕안
NIL
<-string-reverse s2) = ~A~%" (my-string-reverse s2))
(my-string-reverse s2) = ?요세하녕안
NIL
Break 1 [7]> (quit)
Bye.
----------------------------------------




Posted by Scripter
,