GPT隆盛の時代にLispを勉強する

思いつきで上記文章書いたけど、「拾う」「書く」という既存の言語にはない概念をdefmacroしてそれぞれの要素(人間、鉛筆、ノート) に適用させてた。

きちんと理解できているみたい。すごい

 

```lisp

;; シミュレーション世界の定義
(defvar *world* (list (list 'pencil '(0 0))
                      (list 'notebook '(1 1))
                      (list 'person '(0 1))))

;; マクロ定義
(defmacro with-object *1
     result))

;; 出来事のシミュレーション
(with-object (pencil 'pencil '(0 0))
  (with-object (person 'person '(0 1))
    (with-object (notebook 'notebook '(1 1))
      (setf pencil (list 'pencil nil))
      (setf person (list 'person '(0 0)))
      (setf notebook (list 'notebook '(1 0)))
      (with-object (pencil 'pencil '(0 0))
        (with-object (person 'person '(0 1))
          (pick-up pencil person)
          (with-object (notebook 'notebook '(1 1))
            (write-on-notebook person notebook "かきくけこ"))))))))

;; 出来事の定義
(defun pick-up (pencil person)
  (let *2
    (setf pencil nil)
    result))

(defun write-on-notebook (person notebook text)
  (with-open-file (stream "note.txt" :direction :output :if-exists :supersede)
    (format stream "~aがノートに「~a」と書いた。"
            '彼 text)))

```

*1:var class position) &body body)
  `(let* ((,var (find-if (lambda (obj) (and (eq (car obj) ',class)
                                             (equal (cadr obj) ',position)))
                         *world*)))
          (result (progn ,@body)))
     (setf (cadr ,var) (position result

*2:result pencil