Skip to content

Instantly share code, notes, and snippets.

@gogotanaka
Created January 15, 2016 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gogotanaka/12c7f92636f8eaa6ae7a to your computer and use it in GitHub Desktop.
Save gogotanaka/12c7f92636f8eaa6ae7a to your computer and use it in GitHub Desktop.
(load "blockdata.lsp")
(defun match-element (x y)
(or (eq x y) (eq y '?)))
(match-element 1 1)
(match-element 1 2)
(match-element 1 '?)
(defun match-triple (x pat)
(every #'match-element x pat))
(defun fetch (pat)
(remove-if-not #'(lambda (x) (match-triple x pat)) blockdata))
(fetch '(? supports b1))
(defun color-pattern (x) (list x '(color ?))
(defun supporters (b1)
(mapcar #'first (fetch (list '? supports b1))))
(defun desc1 (b1)
(fetch (list b1 '? '?)))
(defun desc2 (b1)
(mapcar #'cdr(desc1 b1)))
(defun description (b1)
(reduce #'append (desc2 b1)))
(defun supp-cube (b1)
(member 'cube
(mapcar #'(lambda (b) (third (first (fetch
(list b 'shape '?)))))
(supporters b1))))
(defun rev (x)
(cond ((null x) NIL)
(t (append (rev (cdr x)) (list (car x))))))
(defun betwwn-1-and-5 (e)
(and (> e 1) (< e 5)))
(defun pick (x)
(remove-if-not #'betwwn-1-and-5 x))
(defun roughly-equal (x k)
(find-if #'(lambda (e) (and (> e (- k 10))
(< e (+ k 10))))))
(defun drawline (n)
(cond ((= n 0) nil)
(t (format t "*")
(drawline (- n 1)))))
(defun sum-tree (x)
(cond ((numberp x) x)
((atom x) 0)
(t (+ (sum-tree (car x))
(sum-tree (cdr x))))))
(defun flat(x)
(cond ((null x) nil)
((atom x) (list x))
(t (append (flat (car x))
(flat (cdr x))))))
(match-triple '(b2 color red) '(b2 color ?))
(listp ())
; T
(consp ())
; NIL
(atom ())
; T
(atom '(1)) ; consp の逆
; NIL
(null 2) ; not と同じ
equ
(cdr '(a . b))
; b
(setq b '(#1=10 #1#)) ; => #1=(a b c . #1#)
(eq (car b) (car (cdr b)))
; (B)
(defconstant *a* 1)
(boundp '*a*)
クロージャ(クロージャー、英語: closure)、関数閉包はプログラミング言語における関数オブジェクトの一種。
いくつかの言語ではラムダ式や無名関数で実現している。引数以外の変数を実行時の環境ではなく、自身が定義された環境(静的スコープ)において解決することを特徴とする。関数とそれを評価する環境のペアであるともいえる。
(let (x)
(defun my-confidential-key-get () x)
(defun my-confidential-key-set (val) (setq x val)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment