Skip to content
Newer
Older
100644 36 lines (27 sloc) 1.31 KB
2b32696 @krzysz00 First working code
authored Dec 11, 2010
1 ;; This file is part of clos-diff.
2
3 ;; clos-diff is free software: you can redistribute it and/or modify
4 ;; it under the terms of the GNU General Public License as published by
5 ;; the Free Software Foundation, either version 3 of the License, or
6 ;; (at your option) any later version.
7
8 ;; clos-diff is distributed in the hope that it will be useful,
9 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ;; GNU General Public License for more details.
12
13 ;; You should have received a copy of the GNU General Public License
14 ;; along with clos-diff in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
15
16 ;; Copyright (C) 2010 Krzysztof Drewniak <krzysdrewniak (at) gmail (dot) com>
17
18 (in-package :clos-diff)
19
20 (defun eval-diff (obj phrase)
21 (destructuring-bind (func arg1 arg2) phrase
22 (ecase func
23 (sv (setf (slot-value obj arg1) arg2))
24 (ii (setf (slot-value obj arg1) (allocate-instance arg2)))
25 (recur (setf (slot-value obj arg1)
26 (apply-diff arg2 (slot-value obj arg1)))))))
27
28 (defun apply-diff (diff &optional obj)
29 (let ((top (pop diff)))
30 (unless obj (setf obj (allocate-instance (first top))))
31 (unless (equal (type-of obj) (first top)) (error "Object type mismatch.")))
32 (loop for i in diff do
33 (eval-diff obj i))
34 obj)
35
Something went wrong with that request. Please try again.