Lisp

マージソート習作

(defun divide-two (&optional (list) (f-list nil)) (if (< (length f-list) (length list)) (divide-two (cdr list) (append f-list (list (car list)))) (cons f-list list))) (defun do-simple-insert (list num) (if (not list) (setf list (list num))…

基数ソート習作

(defun set-array (&optional (list) (num) (array (make-array '(10) :initial-element nil))) (if (not list) array (let ((key (truncate (mod (/ (car list) (expt 10 num)) 10)))) (setf (svref array key) (append (svref array key) (list (car list)…

バケットソート習作

(defun max-elements (&optional (list) (elm 0)) (if (not list) elm (max-elements (cdr list) (if (> elm (car list)) elm (car list))))) (defun vector-to-list (&optional (array) (num 0)) (if (< num (length array)) (let ((anum (svref array num)…

シェルソート習作

(setq h 3) (defun make-new-list (&optional (list) (num) (n 0) (t-list nil)) (cond ((not (cdr list)) (if (= num n) (append t-list (list (car list))) t-list)) ((= num n) (make-new-list (cdr list) (+ num h) (1+ n) (append t-list (list (car li…

単純選択ソート習作

(defun do-simple-select (&optional (list) (num nil)) (let ((tmp (car list))) (cond ((not num) (do-simple-select (cdr list) tmp)) ((not tmp) (cons nil num)) ((not (cdr list)) (if (> num tmp) (cons (list num) tmp) (cons (list tmp) num))) (t …

ふと思ったのだが

in Perl my ($a, $b) = (1, 2); みたいなことをLispでもできないのかな。 (setf '(a b) '(1 2)) なんてできちゃいそうな気もするけど(初心者というかバカ丸出し)

単純挿入ソート習作

(defun do-simple-insert (list num) (if (not list) (setf list (list num)) (if (< (car list) num) (setf (cdr list) (do-simple-insert (cdr list) num)) (setf list (cons num list)))) list) (defun simple-insert-sort (list) (let ((ret-list)) (dol…

バブルソート習作

(defun do-bubble (list) (if (cdr list) (let ((t1 (car list)) (t2 (car (cdr list)))) (if (> t1 t2) (setf (car list) t2 (car (cdr list)) t1)) (setf (cdr list) (do-bubble (cdr list))))) list) (defun bubble-sort (list) (let ((ret-list)) (dotim…

abstractfactory.lisp (defclass hotpot () ((soup :accessor hotpot-soup :initform nil) (protein :accessor hotpot-main :initform nil) (vegetables :accessor hotpot-vegetables :initform nil) (other-ingredients :accessor hotpot-other-ingredients…

prototype.lisp (defclass cloneable () ((name :accessor name-of-type :initarg :name))) (defmethod create-clone ((clone cloneable)) clone) (defclass paper (cloneable) ()) (defclass proto-keeper () ((map :initform (make-hash-table :test #'equ…

singleton.lisp (defclass register-note () ((r-note :allocation :class :initform nil))) (defmethod get-instance ((rn register-note)) (unless (slot-value rn 'r-note) (setf (slot-value rn 'r-note) (make-instance 'register-note))) (slot-value …

今日も

factorymethod.lisp(TemplateMethodパターンも込み) (defclass cuttable () ((hanzai))) (defmethod get-cuttable-type ((ctbl cuttable)) (slot-value ctbl 'hanzai)) (defclass wood (cuttable) ((hanzai :initform '木版))) (defclass potato (cuttable) …

やってみた

iterator.lisp (defclass iterator () ((list :initarg :list))) (defmethod is-next ((itr iterator)) (if (car (slot-value itr 'list)) t)) (defmethod next ((itr iterator)) (let ((ret (car (slot-value itr 'list)))) (setf (slot-value itr 'list) (…

掃き出し法(discharge calculation)

いい加減このタグ作るか。 (setf dim (list 3 4)) (setq ROW 3) (setq COLUMN 4) (defun my_proc (from count to) (setq dnum (aref from count count)) (dotimes (num COLUMN) (setf (aref from count num) (/ (aref from count num) dnum) (aref to num) (…

再び

今度はガウス・ジョルダン法。 (setf list_all (make-array '(3 4) :initial-contents '((2.0 1.0 3.0 10.0) (-1.0 2.0 1.0 5.0) (3.0 -2.0 -1.0 -1.0)))) (setf tmpList (make-array 4 :initial-element nil)) (defun my_proc (count) (let ((dnum (aref li…

のお勉強

とある用で作ったCのソースをLispにトレースしてみた。Lispでも、書き方如何によってはCで書くのと変わりないものができてしまうので、なるべくアルゴリズムを壊さず、かつ関数プログラミングっぽさが出るように心がけてみた。因みに、プログラムはニュート…

英語とLISPの勉強を兼ねて

これを少しずつ読んでいくことにした。Lisp 1.5 Programmer's Manualposted with amazlet on 06.09.14John McCarthy Mit Pr (1962/08/15)売り上げランキング: 282,487Amazon.co.jp で詳細を見る 本自体は図書館で見つけたんだけど、SICPの例があるのでネット…