-
Notifications
You must be signed in to change notification settings - Fork 2
/
replacements.lisp
76 lines (63 loc) · 2.8 KB
/
replacements.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
;---------------------------------------------
; REPLACEMENTS: This file contains flavors, methods, and codelets for
; replacements.
;---------------------------------------------
(in-package 'user)
(defflavor replacement
(obj1 obj2)
(workspace-structure)
:gettable-instance-variables
:settable-instance-variables
:initable-instance-variables)
;---------------------------------------------
(defun make-replacement (obj1 obj2 &aux new-replacement)
; Returns a new replacement.
(setq new-replacement (make-instance 'replacement :obj1 obj1 :obj2 obj2))
(if* %workspace-graphics% then (send new-replacement :init-graphics))
new-replacement)
;---------------------------------------------
(defun replacement-finder (&aux i-letter m-letter i-letter-category
m-letter-category change-relation
new-replacement)
; Chooses a letter at random in the initial-string. Sees if it is the
; changed letter. If so, then marks it as changed, and adds a description
; of the relation describing the change, if there is one. For now, this
; can only deal with letters changing into letters, not letters changing
; into groups or vice versa.
(block nil
(if* %verbose% then (format t "In replacement-finder~&"))
(setq i-letter (send *initial-string* :random-letter))
(if* %verbose%
then (format t "Chose ") (send i-letter :print))
(if* (send i-letter :replacement)
then (if* %verbose%
then (format t "Replacement for this letter already found. ")
(format t "Fizzling.~&"))
(return))
(setq m-letter (send *modified-string* :get-letter
(send i-letter :left-string-position)))
(if* %verbose%
then (format t "Found modified-string-letter: ~a:~a~&"
(send m-letter :pname)
(send m-letter :left-string-position)))
; Now see if m-letter's letter-category is different from i-letter's.
(setq i-letter-category
(send i-letter :get-descriptor plato-letter-category))
(setq m-letter-category
(send m-letter :get-descriptor plato-letter-category))
(if* (not (eq i-letter-category m-letter-category))
then (send i-letter :set-changed? t)
(setq change-relation
(get-label-node i-letter-category m-letter-category))
(if* change-relation
then (send m-letter :add-extrinsic-description
(make-extrinsic-description
change-relation plato-letter-category i-letter))
(if* %verbose%
then (format t "Found change-relation ~a~&"
(send change-relation :pname)))))
(setq new-replacement (make-replacement i-letter m-letter))
(send *workspace* :add-replacement new-replacement)
(send i-letter :set-replacement new-replacement)
(if* %workspace-graphics% then (send (send i-letter :replacement) :draw))))
;---------------------------------------------