(defun rand (min max)
(+ (random (1+ (- max min))) min))
(defun cpair (a b)
(unless (eql a b) (list (cons a b) (cons b a))))
(defun cgraph(n min max)
(apply #'append (loop repeat n collect (cpair (rand min max) (rand min max)))))
(defun collect-car (what list)
(remove-if-not (lambda (x) (eql (car x) what)) list))
(defun graph-connected (node list)
(let ((visited nil))
(labels ((traverse (node) unless (member node visited) (push node visited) (mapc (lambda (tnode) (traverse (cdr tnode))) (collect-car node list)))))
(traverse node)) visited))
(defun graph-find (nodes list)
(let ((tnode nil))
(labels ((node-find (nodes)
(let* ((connected (graph-connected (car nodes) list))
(unconnected (set-difference nodes connected)))
(push connected tnode) (when unconnected (graph-find unconnected)))))
(graph-find nodes)) tnode))
(defun graph-connect (nodes)
(when (cdr nodes) (append (cpair (caar nodes) (caadr nodes)) (graph-connect (cdr nodes)))))
(defun graph-connect-all (nodes list)
(append (graph-connect (graph-find nodes list)) list))
무슨 언어야? 함수형 언어 같은데
common lisp 아님?
defun 보니까 lisp 같은데
공통 목록 처리 언어 입니다. (구글 번역기->영어)
요즘 핫한 lisp 변종들은 대부분 lisp-1 형이라 함수/변수 네임스페이스가 같아서 함수 정의할때랑 변수 정의할때 키워드가 같음. common lisp 같이 함수/변수 네임스페이스 다른 lisp-2 형은 함수정의할때랑 변수정의할때랑 키워드가 다르지...그러니 보통 defun 같이 함수정의한다를 마빡에 붙여놓은 키워드라면 아마 common lisp.
하스켈은 하다 접었고, 클로저는 자바를 몰라서 ...