[파일명: testStringFindInList.lsp]------------------------------------------------
(defun my-find(arr s)
(let ((k -1)
(r -1))
(loop for i from 0 below (length arr) do
(setf k (search s (nth i arr)))
(if k (progn (setf r i) (return i)))
)
r
)
)
(defun printList(arr)
(format t "[")
(loop for i from 0 below (1- (length arr)) do
(format t "~A, " (nth i arr))
)
(if (plusp (length arr))
(format t "~A" (nth (1- (length arr)) arr))
)
(format t "]~%")
)
(setf words (list "하나" "둘" "셋" "넷" "다섯" "여섯"))
(format t "list: ")
(printList words)
(setf w (my-find words "셋"))
(if (>= w 0)
(progn
(format t "발견! ~%")
(format t "Next word of 셋 in list: ~A~%" (nth (1+ w) words))
)
)
(format t "Sorting...~%")
(sort words #'string<)
(format t "list: ")
(printList words)
(setf w (my-find words "셋"))
(if (>= w 0)
(progn
(format t "발견! ~%")
(format t "Next word of 셋 in list: ~A~%" (nth (1+ w) words))
)
)
------------------------------------------------
실행> clisp testStringFindInList.lsp
list: [하나, 둘, 셋, 넷, 다섯, 여섯]
발견! Next word of 셋 in list: 넷
Sorting...
list: [넷, 다섯, 둘, 셋, 여섯, 하나]
발견! Next word of 셋 in list: 여섯
'프로그래밍 > Common Lisp' 카테고리의 다른 글
조립제법(Horner의 방법) 예제 2 for Common Lisp (0) | 2013.09.07 |
---|---|
숫자 맞추기 게임 with Common Lisp (0) | 2013.09.07 |
스트링 배열 정렬(sorting)하기 with Common Lisp (0) | 2013.09.06 |
Pollard's rho method 소개: 정수의 인수분해(factorizing integers) with Common Lisp (0) | 2013.09.06 |
손으로 계산하는 긴자리 곱셈표 만들기 with Common Lisp (0) | 2013.09.06 |