-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompiled-handlers.lisp
More file actions
3711 lines (3701 loc) · 258 KB
/
compiled-handlers.lisp
File metadata and controls
3711 lines (3701 loc) · 258 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;compiled-handlers.lisp from: quicklisp/software/km-2-5-33 directory, hand edited to compile on old machines by mike.bobak@gmail
;http://www.cs.utexas.edu/users/mfkb/RKF/km.html
(unless (find-package :km) (make-package :km :use '(:common-lisp)))
(in-package :km)
;I dissasembled the newer 2-5-45 version, but it missed some off the package lines, put them back in, but will stick w/this older quicklisp ver for now
;;; File: compiled-handlers.lisp
;;; Author: MACHINE GENERATED FILE, generated by compiler.lisp (author Adam Farquahar)
;;; This file was generated by (write-compiled-handlers) in compiler.lisp.
;;; This partially flattens the code assigned to *km-handler-list*, which results in
;;; 10%-30% faster execution (10%-30%) at run-time. Loading of this file is optional,
;;; KM will be slower if it's not loaded. For the legible, unflattened source of this
;;; flattened code, see the file interpreter.lisp.
;;;
;;; NOTE: manually insert the line after compiled-km-handler-function for KM release:
;;;
;;; (defun compiled-km-handler-function (f-mode x)
;;; #+harlequin-pc-lisp (declare (optimize (debug 0))) ; patch for Lispworks from Francis Leboutte [1]
;;; (block km-handler
;;; ...
;;;
;;; ==================== START OF MACHINE-GENERATED FILE ====================
;Why couldn't we have gotten the code that generates this? W/o it I had to hand edit this:
; well it could have been automated, but not that many ..we'll see where this goes, might feed into some other updates/?
; there is a write-compiled-handlers but don't think is or should be called
;KM: km_2-5-45.lisp &quicklisp: :KM both can crap out on: compiled-handlers.lisp, so starting to rework the file;need2get around return-from block ..
; pulled out 34 handler blocks of code, and made seperate functions, it compiles, but need2test that ret vals all passed up properly
; This finally allows a version of KM to be used on an old 32bit PPC Linux box I have sitting around.
;I can get 'tax' of Thing, but when components/core classes are loaded via nlp/lcc.lisp then I see similar probs, so dbg here
;If need be can rename the main/original block, but shouldn't be a problem
;Started to try something w/the newer version, that funcall's the h-- fncs from a fnc called km-handler, probably wouldn't return to that block though
;Since the largest problem is it not compiling on the 32bit machine, &I don't absolutely need it on small machines yet, I might table this for a bit,
; &get back to getting more ont/vocabs in &trying concept id from text, &a bit more.
(setq *compile-handlers* t)
(defun h--the (x xl xr f-mode target) (block km-handler
(let ((xrl (first xr)) (xrr (rest xr)))
(or (when (consp xrr)
(let ((xrrl (first xrr)) (xrrr (rest xrr)))
(or (when (eql xrrl '|of|)
(when (consp xrrr)
(let ((xrrrl (first xrrr)) (xrrrr (rest xrrr)))
(when (eql xrrrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (fmode0 _target slot frameadd)
(declare (ignore _target))
(cond ((structured-slotp slot)
(follow-multidepth-path (km-int frameadd :fail-mode fmode0) slot '*
:fail-mode fmode0))
((pathp slot)
(let ((eval-slot (km-unique-int slot :fail-mode 'error)))
(km-int `(|the| ,eval-slot |of| ,frameadd) :fail-mode fmode0)))
(t
(let* ((fmode
(cond ((built-in-aggregation-slot slot) 'fail) (t fmode0)))
(frames
(cond ((every #'is-simple-km-term (val-to-vals frameadd))
(remove-dup-instances (val-to-vals frameadd)))
(t
(km-int frameadd
:fail-mode fmode
:check-for-looping nil)))))
(cond ((= *depth* 1)
(setq *last-question*
`(|the| ,slot |of| ,(vals-to-val frames)))))
(cond ((not (equal frames (val-to-vals frameadd)))
(remove-if-not #'is-km-term
(km-int
`(|the|
,slot
|of|
,(vals-to-val frames))
:fail-mode fmode)))
(t
(remove-if-not #'is-km-term
(km-multi-slotvals frames slot
:fail-mode fmode))))))))
f-mode target xrl xrrrl)
'(|the| ?slot |of| ?frameadd)))))))
(when (consp xrrr)
(let ((xrrrl (first xrrr)) (xrrrr (rest xrrr)))
(when (eql xrrrl '|of|)
(when (consp xrrrr)
(let ((xrrrrl (first xrrrr)) (xrrrrr (rest xrrrr)))
(when (eql xrrrrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (fmode0 target class slot frameadd)
(cond ((structured-slotp slot)
(follow-multidepth-path
(km-int frameadd
:fail-mode fmode0
:target target
:rewritep t)
slot class
:fail-mode fmode0))
((pathp slot)
(let ((eval-slot (km-unique-int slot :fail-mode 'error)))
(km-int `(|the| ,class ,eval-slot |of| ,frameadd)
:fail-mode fmode0
:target target
:rewritep t)))
(t
(let* ((fmode
(cond ((built-in-aggregation-slot slot) 'fail)
(t fmode0))))
(vals-in-class (km-int `(|the| ,slot |of| ,frameadd)
:fail-mode fmode
:target target
:rewritep t)
class)))))
f-mode target xrl xrrl xrrrrl)
'(|the| ?class ?slot |of| ?frameadd)))))))))
(when (eql xrrl '|with|)
(return-from km-handler
(values (funcall #'(lambda (fmode target frame slotsvals)
(declare (ignore fmode target))
(let ((answer (km-int `(|every| ,frame |with| ,@slotsvals))))
(cond ((null answer)
(report-error 'user-error "No values found for expression ~a!~%"
`(|the| ,frame |with| ,@slotsvals)))
((not (singletonp answer))
(report-error 'user-error
"Expected a single value for expression ~a, but found multiple values ~a!~%"
`(|the| ,frame |with| ,@slotsvals) answer))
(t answer))))
f-mode target xrl xrrr)
'(|the| ?frame |with| &rest)))))))
(when (eql xrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (fmode target frame)
(declare (ignore fmode target))
(let ((answer (km-int `(|every| ,frame))))
(cond ((null answer)
(report-error 'user-error "No values found for expression ~a!~%"
`(|the| ,frame)))
((not (singletonp answer))
(report-error 'user-error
"Expected a single value for expression ~a, but found multiple values ~a!~%"
`(|the| ,frame) answer))
(t answer))))
f-mode target xrl)
'(|the| ?frame))))))
))
(defun h--a (x xl xr f-mode target) (block km-handler
(let ((xrl (first xr)) (xrr (rest xr)))
(or (when (eql xrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (_fmode target class)
(declare (ignore _fmode))
(list (create-instance class nil :target target)))
f-mode target xrl)
'(|a| ?class))))
(when (consp xrr)
(let ((xrrl (first xrr)) (xrrr (rest xrr)))
(or (when (eql xrrl '|called|)
(when (consp xrrr)
(let ((xrrrl (first xrrr)) (xrrrr (rest xrrr)))
(or (when (eql xrrrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (_fmode target class tag)
(declare (ignore _fmode))
(km-setq '*are-some-tags* t)
(cond ((km-tagp tag)
(list (create-instance class `((|called| ,(val-to-vals tag)))
:target target)))
(t
(report-error 'user-error
"~a~% - The tag `~a' must be an atom or a constraint!"
`(|a| ,class |called| ,tag) tag))))
f-mode target xrl xrrrl)
'(|a| ?class |called| ?tag))))
(when (consp xrrrr)
(let ((xrrrrl (first xrrrr)) (xrrrrr (rest xrrrr)))
(when (eql xrrrrl '|with|)
(return-from km-handler
(values (funcall #'(lambda (_fmode target class tag slotsvals)
(declare (ignore _fmode))
(km-setq '*are-some-tags* t)
(cond ((not (km-tagp tag))
(report-error 'user-error
"~a~% - The tag `~a' must be an atom or a constraint!"
`(|a| ,class |called| ,tag |with|
,@slotsvals)
tag))
((are-slotsvals slotsvals)
(let ((instance
(create-instance class
(cons
`(|called| ,(val-to-vals tag))
(convert-comments-to-internal-form
slotsvals))
:target target)))
(cond ((am-in-prototype-mode)
(km-int '(|evaluate-paths|))))
(list instance)))))
f-mode target xrl xrrrl xrrrrr)
'(|a| ?class |called| ?tag |with| &rest))))))))))
(when (eql xrrl '|uniquely-called|)
(when (consp xrrr)
(let ((xrrrl (first xrrr)) (xrrrr (rest xrrr)))
(or (when (eql xrrrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (_fmode target class tag)
(declare (ignore _fmode))
(km-setq '*are-some-constraints* t)
(km-setq '*are-some-tags* t)
(cond ((km-tagp tag)
(list (create-instance class
`((|uniquely-called|
,(val-to-vals tag)))
:target target)))
(t
(report-error 'user-error
"~a~% - The tag `~a' must be an atom or a constraint!"
`(|a| ,class |uniquely-called| ,tag) tag))))
f-mode target xrl xrrrl)
'(|a| ?class |uniquely-called| ?tag))))
(when (consp xrrrr)
(let ((xrrrrl (first xrrrr)) (xrrrrr (rest xrrrr)))
(when (eql xrrrrl '|with|)
(return-from km-handler
(values (funcall #'(lambda (_fmode target class tag slotsvals)
(declare (ignore _fmode))
(km-setq '*are-some-constraints* t)
(km-setq '*are-some-tags* t)
(cond ((not (km-tagp tag))
(report-error 'user-error
"~a~% - The tag `~a' must be an atom or a constraint!"
`(|a| ,class |uniquely-called| ,tag |with|
,@slotsvals)
tag))
((are-slotsvals slotsvals)
(let ((instance
(create-instance class
(cons
`(|uniquely-called|
,(val-to-vals tag))
(convert-comments-to-internal-form
slotsvals))
:target target)))
(cond ((am-in-prototype-mode)
(km-int '(|evaluate-paths|))))
(list instance)))))
f-mode target xrl xrrrl xrrrrr)
'(|a| ?class |uniquely-called| ?tag |with| &rest))))))))))
(when (eql xrrl '|with|)
(return-from km-handler
(values (funcall #'(lambda (_fmode target class slotsvals)
(declare (ignore _fmode))
(cond ((are-slotsvals slotsvals)
(let ((instance
(create-instance class
(convert-comments-to-internal-form slotsvals)
:target target)))
(cond ((am-in-prototype-mode) (km-int '(|evaluate-paths|))))
(list instance)))))
f-mode target xrl xrrr)
'(|a| ?class |with| &rest)))))))))
))
(defun h--a-prototype (x xl xr f-mode target) (block km-handler
(let ((xrl (first xr)) (xrr (rest xr)))
(or (when (eql xrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (fmode target class)
(km-int `(|a-prototype| ,class |with|) :fail-mode fmode :target target :rewritep t))
f-mode target xrl)
'(|a-prototype| ?class))))
(when (consp xrr)
(let ((xrrl (first xrr)) (xrrr (rest xrr)))
(when (eql xrrl '|with|)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target class slotsvals)
(declare (ignore _fmode _target))
(cond ((am-in-local-situation)
(report-error 'user-error
"Can't enter prototype mode when in a Situation!~%"))
((am-in-local-theory)
(report-error 'user-error "Can't enter prototype mode when in a Theory!~%"))
((am-in-prototype-mode)
(report-error 'user-error
"~a~%Attempt to enter prototype mode while already in prototype mode (not allowed)!~%Perhaps you are missing an (end-prototype)?"
`(|a-prototype| ,class |with| ,@slotsvals)))
((are-slotsvals slotsvals)
(new-context)
(km-setq '*curr-prototype*
(create-instance class
`((|prototype-of| (,class))
,(cond (slotsvals
`(|prototype-scope|
((|the-class|
,class
|with|
,@slotsvals))))
(t `(|prototype-scope| (,class))))
,@slotsvals)
:prefix-string *proto-marker-string*
:bind-selfp nil))
(add-val *curr-prototype* '|prototype-participants| *curr-prototype*)
(km-setq '*are-some-prototypes* t)
(cond ((null slotsvals)
(add-to-prototype-definition *curr-prototype*
`(|a-prototoype| ,class)))
(t
(add-to-prototype-definition *curr-prototype*
`(|a-prototype| ,class |with| ,@slotsvals))))
(list *curr-prototype*))))
f-mode target xrl xrrr)
'(|a-prototype| ?class |with| &rest))))))))
))
(defun h--clone (x xl xr f-mode target) (block km-handler
(let ((xrl (first xr)) (xrr (rest xr)))
(when (eql xrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target expr)
(declare (ignore _fmode _target))
(let ((source (km-unique-int expr :fail-mode 'error)))
(cond (source (list (clone source))))))
f-mode target xrl)
'(|clone| ?expr)))))
))
(defun h--must-be-a (x xl xr f-mode target) (block km-handler
(let ((xrl (first xr)) (xrr (rest xr)))
(or (when (eql xrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target _class)
(declare (ignore _fmode _target _class))
(note-are-constraints)
nil)
f-mode target xrl)
'(|must-be-a| ?class))))
(when (consp xrr)
(let ((xrrl (first xrr)) (xrrr (rest xrr)))
(when (eql xrrl '|with|)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target _class slotsvals)
(declare (ignore _fmode _target _class))
(are-slotsvals slotsvals)
(note-are-constraints)
nil)
f-mode target xrl xrrr)
'(|must-be-a| ?class |with| &rest))))))))
))
(defun h--every (x xl xr f-mode target) (block km-handler
(let ((xrl (first xr)) (xrr (rest xr)))
(or (when (consp xrr)
(let ((xrrl (first xrr)) (xrrr (rest xrr)))
(or (when (eql xrrl '|has|)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target cexpr slotsvals)
(declare (ignore _fmode _target))
(let ((class (km-unique-int cexpr :fail-mode 'error)))
(cond ((not (kb-objectp class))
(report-error 'user-error
"~a~%~a isn't/doesn't evaluate to a class name.~%"
`(|every| ,cexpr |has| ,@slotsvals) cexpr))
((are-slotsvals slotsvals)
(let* ((slotsvals00
(cond (*record-sources*
(annotate-slotsvals slotsvals (make-source class)))
(t slotsvals)))
(slotsvals0 (convert-comments-to-internal-form slotsvals00)))
(add-slotsvals class slotsvals0
:facet 'member-properties
:install-inversesp nil))
(cond ((and (assoc '|assertions| slotsvals)
(not (member class *classes-using-assertions-slot*)))
(km-setq '*classes-using-assertions-slot*
(cons class *classes-using-assertions-slot*))))
(mapc #'un-done (all-instances class))
(list class)))))
f-mode target xrl xrrr)
'(|every| ?cexpr |has| &rest))))
(when (eql xrrl '|also-has|)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target cexpr slotsvals)
(declare (ignore _fmode _target))
(let ((class (km-unique-int cexpr :fail-mode 'error)))
(cond ((not (kb-objectp class))
(report-error 'user-error
"~a~%~a isn't/doesn't evaluate to a class name.~%"
`(|every| ,cexpr |also-has| ,@slotsvals) cexpr))
((are-slotsvals slotsvals)
(let* ((slotsvals00
(cond (*record-sources*
(annotate-slotsvals slotsvals (make-source class)))
(t slotsvals)))
(slotsvals0 (convert-comments-to-internal-form slotsvals00)))
(add-slotsvals class slotsvals0
:facet 'member-properties
:install-inversesp nil
:combine-values-by 'appending))
(cond ((and (assoc '|assertions| slotsvals)
(not (member class *classes-using-assertions-slot*)))
(km-setq '*classes-using-assertions-slot*
(cons class *classes-using-assertions-slot*))))
(mapc #'un-done (all-instances class))
(list class)))))
f-mode target xrl xrrr)
'(|every| ?cexpr |also-has| &rest))))
(when (eql xrrl '|now-has|)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target cexpr slotsvals)
(declare (ignore _fmode _target))
(let ((class (km-unique-int cexpr :fail-mode 'error)))
(cond ((not (kb-objectp class))
(report-error 'user-error
"~a~%~a isn't/doesn't evaluate to a class name.~%"
`(|every| ,cexpr |now-has| ,@slotsvals) cexpr))
((are-slotsvals slotsvals)
(let* ((slotsvals00
(cond (*record-sources*
(annotate-slotsvals slotsvals (make-source class)))
(t slotsvals)))
(slotsvals0 (convert-comments-to-internal-form slotsvals00)))
(add-slotsvals class slotsvals0
:facet 'member-properties
:install-inversesp nil
:combine-values-by 'overwriting))
(cond ((and (assoc '|assertions| slotsvals)
(not (member class *classes-using-assertions-slot*)))
(km-setq '*classes-using-assertions-slot*
(cons class *classes-using-assertions-slot*))))
(mapc #'un-done (all-instances class))
(list class)))))
f-mode target xrl xrrr)
'(|every| ?cexpr |now-has| &rest))))
(when (eql xrrl '|also-hasnt|)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target instance-expr slotsvals)
(declare (ignore _fmode _target))
(report-error 'user-error
"~a:~%Can't use also-hasnt with an \"every\" expression (can only use it with instances, not classes)~%"
`(|every| ,instance-expr |also-hasnt| ,@slotsvals)))
f-mode target xrl xrrr)
'(|every| ?instance-expr |also-hasnt| &rest))))
(when (eql xrrl '|with|)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target frame slotsvals)
(declare (ignore _fmode _target))
(cond ((are-slotsvals slotsvals)
(let ((existential-expr
(cond ((and (null slotsvals) (pathp frame))
(path-to-existential-expr frame))
(t `(|a| ,frame |with| ,@slotsvals)))))
(find-subsumees-on-object-stack existential-expr)))))
f-mode target xrl xrrr)
'(|every| ?frame |with| &rest))))
(when (eql xrrl '|has-definition|)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target cexpr slotsvals)
(declare (ignore _fmode _target))
(let ((class (km-unique-int cexpr :fail-mode 'error)))
(cond ((not (kb-objectp class))
(report-error 'user-error
"~a~%~a isn't/doesn't evaluate to a class name.~%"
`(|every| ,cexpr |has-definition| ,@slotsvals) cexpr))
((are-slotsvals slotsvals)
(let* ((slotsvals00
(cond (*record-sources*
(annotate-slotsvals slotsvals (make-source class)))
(t slotsvals)))
(slotsvals0 (convert-comments-to-internal-form slotsvals00))
(parents-of-defined-concept
(desource+decomment (vals-in (assoc '|instance-of| slotsvals0))
:delistifyp nil)))
(cond ((not (every #'kb-objectp parents-of-defined-concept))
(report-error 'user-error
"~a~%The `instance-of' slot-filler(s) in a has-definition must be atomic class name(s) only.~%"
`(|every| ,cexpr |has-definition|
,@slotsvals0)))
((null parents-of-defined-concept)
(report-error 'user-error
"~a~%You must specify an `instance-of' slot value for a has-definition, pointing to the parent class(es)!~%"
`(|every| ,cexpr |has-definition|
,@slotsvals0)))
(t
(add-slotsvals class slotsvals0
:facet 'member-definition
:install-inversesp nil)
(point-parents-to-defined-concept class
parents-of-defined-concept
'member-definition)
(km-setq '*are-some-definitions* t)
(mapc #'un-done (all-instances class))
(list class))))))))
f-mode target xrl xrrr)
'(|every| ?cexpr |has-definition| &rest))))
(when (eql xrrl '|now-has-definition|)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target cexpr slotsvals)
(declare (ignore _fmode _target))
(let ((class (km-unique-int cexpr :fail-mode 'error)))
(cond ((not (kb-objectp class))
(report-error 'user-error
"~a~%~a isn't/doesn't evaluate to a class name.~%"
`(|every| ,cexpr |now-has-definition| ,@slotsvals)
cexpr))
((are-slotsvals slotsvals)
(let* ((slotsvals00
(cond (*record-sources*
(annotate-slotsvals slotsvals (make-source class)))
(t slotsvals)))
(slotsvals0 (convert-comments-to-internal-form slotsvals00))
(parents-of-defined-concept
(desource+decomment (vals-in (assoc '|instance-of| slotsvals0))
:delistifyp nil)))
(cond ((not (every #'kb-objectp parents-of-defined-concept))
(report-error 'user-error
"~a~%The `instance-of' slot-filler(s) in a now-has-definition must be atomic class name(s) only.~%"
`(|every| ,cexpr |now-has-definition|
,@slotsvals0)))
((and (null parents-of-defined-concept) slotsvals0)
(report-error 'user-error
"~a~%You must specify an `instance-of' slot value for a now-has-definition, pointing to the parent class(es)!~%"
`(|every| ,cexpr |now-has-definition|
,@slotsvals0)))
(t
(let ((member-definition-parents
(get-vals class '|instance-of|
:facet 'member-definition)))
(cond (member-definition-parents
(unpoint-parents-to-defined-concept class
member-definition-parents 'member-definition))))
(mapc #'(lambda (situation)
(mapc #'(lambda (slotvals)
(let ((slot (slot-in slotvals)))
(put-vals
class
slot
nil
:facet
'member-definition
:situation
situation)))
(get-slotsvals class
:situation situation
:facet 'member-definition)))
(all-situations-and-theories))
(cond (parents-of-defined-concept
(add-slotsvals class slotsvals0
:facet 'member-definition
:install-inversesp nil)
(point-parents-to-defined-concept class
parents-of-defined-concept
'member-definition)
(km-setq '*are-some-definitions* t)
(mapc #'un-done (all-instances class))))
(list class))))))))
f-mode target xrl xrrr)
'(|every| ?cexpr |now-has-definition| &rest)))))))
(when (eql xrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (fmode target frame)
(km-int `(|every| ,frame |with|) :fail-mode fmode :target target :rewritep t))
f-mode target xrl)
'(|every| ?frame))))))
))
(defun h--xr (x xl xr f-mode target) (block km-handler
(let ((xrl (first xr)) (xrr (rest xr)))
(or (when (eql xrl '|has|)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target instance-expr slotsvals)
(declare (ignore _fmode _target))
(let ((instance (km-unique-int instance-expr :fail-mode 'error)))
(cond ((not (kb-objectp instance))
(report-error 'user-error "~a~%~a isn't/doesn't evaluate to a KB object name.~%"
`(,instance-expr |has| ,@slotsvals) instance-expr))
((are-slotsvals slotsvals)
(add-slotsvals instance (convert-comments-to-internal-form slotsvals))
(make-assertions instance slotsvals)
(un-done instance)
(classify instance :slots-that-changed (mapcar #'slot-in slotsvals))
(cond ((am-in-prototype-mode) (km-int '(|evaluate-paths|))))
(list instance)))))
f-mode target xl xrr)
'(?instance-expr |has| &rest))))
(when (eql xrl '|also-has|)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target instance-expr slotsvals)
(declare (ignore _fmode _target))
(let ((instance (km-unique-int instance-expr :fail-mode 'error)))
(cond ((not (kb-objectp instance))
(report-error 'user-error "~a~%~a isn't/doesn't evaluate to a KB object name.~%"
`(,instance-expr |also-has| ,@slotsvals) instance-expr))
((are-slotsvals slotsvals)
(add-slotsvals instance (convert-comments-to-internal-form slotsvals)
:combine-values-by 'appending)
(un-done instance)
(classify instance :slots-that-changed (mapcar #'slot-in slotsvals))
(cond ((am-in-prototype-mode) (km-int '(|evaluate-paths|))))
(list instance)))))
f-mode target xl xrr)
'(?instance-expr |also-has| &rest))))
(when (eql xrl '|also-hasnt|)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target instance-expr slotsvals)
(declare (ignore _fmode _target))
(let ((instance (km-unique-int instance-expr :fail-mode 'error)))
(cond ((not (kb-objectp instance))
(report-error 'user-error "~a~%~a isn't/doesn't evaluate to a KB object name.~%"
`(,instance-expr |also-has| ,@slotsvals) instance-expr))
((are-slotsvals slotsvals)
(mapc #'(lambda (slotvals)
(let ((slot (slot-in slotvals)) (vals (vals-in slotvals)))
(mapc #'(lambda (val) (delete-val instance slot val)) vals)))
slotsvals)
(un-done instance)
(list instance)))))
f-mode target xl xrr)
'(?instance-expr |also-hasnt| &rest))))
(when (eql xrl '|now-has|)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target instance-expr slotsvals)
(declare (ignore _fmode _target))
(let ((instance (km-unique-int instance-expr :fail-mode 'error)))
(cond ((not (kb-objectp instance))
(report-error 'user-error "~a~%~a isn't/doesn't evaluate to a KB object name.~%"
`(,instance-expr |now-has| ,@slotsvals) instance-expr))
((are-slotsvals slotsvals)
(add-slotsvals instance (convert-comments-to-internal-form slotsvals)
:combine-values-by 'overwriting)
(un-done instance)
(classify instance)
(list instance)))))
f-mode target xl xrr)
'(?instance-expr |now-has| &rest))))
(when (eql xrl '&&)
(return-from km-handler
(values (funcall #'(lambda (fmode target xs rest)
(declare (ignore fmode))
(lazy-unify-&-expr `(,xs && ,@rest) :fail-mode 'error :joiner '&& :target target))
f-mode target xl xrr)
'(?xs && &rest))))
(when (eql xrl '&)
(return-from km-handler
(values (funcall #'(lambda (fmode target x rest)
(declare (ignore fmode))
(lazy-unify-&-expr `(,x & ,@rest) :fail-mode 'error :joiner '& :target target))
f-mode target xl xrr)
'(?x & &rest))))
(when (eql xrl '===)
(return-from km-handler
(values (funcall #'(lambda (fmode target xs rest)
(declare (ignore fmode))
(lazy-unify-&-expr `(,xs === ,@rest) :fail-mode 'error :joiner '=== :target target))
f-mode target xl xrr)
'(?xs === &rest))))
(when (eql xrl '==)
(when (consp xrr)
(let ((xrrl (first xrr)) (xrrr (rest xrr)))
(when (eql xrrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (fmode target x y)
(declare (ignore fmode))
(lazy-unify-&-expr `(,x == ,y) :fail-mode 'error :joiner '== :target target))
f-mode target xl xrrl)
'(?x == ?y)))))))
(when (eql xrl '/==)
(when (consp xrr)
(let ((xrrl (first xrr)) (xrrr (rest xrr)))
(when (eql xrrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (fmode target x y)
(declare (ignore fmode target))
(let ((xv (km-unique-int x :fail-mode 'error))
(yv (km-unique-int y :fail-mode 'error)))
(cond ((equal xv yv)
(report-error 'user-error "(~a /== ~a): ~a and ~a are the same object!~%" x
y x y))
((kb-objectp xv) (km-int `(,xv |has| (/== (,yv))) :fail-mode 'error))
((kb-objectp yv) (km-int `(,yv |has| (/== (,xv))) :fail-mode 'error))
('(|t|)))))
f-mode target xl xrrl)
'(?x /== ?y)))))))
(when (eql xrl '&&!)
(return-from km-handler
(values (funcall #'(lambda (fmode target xs rest)
(declare (ignore fmode))
(lazy-unify-&-expr `(,xs &&! ,@rest) :fail-mode 'error :joiner '&&! :target target))
f-mode target xl xrr)
'(?xs &&! &rest))))
(when (eql xrl '&!)
(return-from km-handler
(values (funcall #'(lambda (fmode target x rest)
(declare (ignore fmode))
(lazy-unify-&-expr `(,x &! ,@rest) :fail-mode 'error :joiner '&! :target target))
f-mode target xl xrr)
'(?x &! &rest))))
(when (eql xrl '&?)
(when (consp xrr)
(let ((xrrl (first xrr)) (xrrr (rest xrr)))
(when (eql xrrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (_fmode target x y)
(declare (ignore _fmode target))
(cond ((null x) '(|t|))
((null y) '(|t|))
((existential-exprp y)
(let ((xf (km-unique-int x)))
(cond ((null xf) '(|t|)) ((unifiable-with-existential-expr xf y) '(|t|)))))
((existential-exprp x)
(let ((yf (km-unique-int y)))
(cond ((null yf) '(|t|)) ((unifiable-with-existential-expr yf x) '(|t|)))))
(t
(let ((xv (km-unique-int x)))
(cond ((null xv) '(|t|))
(t
(let ((yv (km-unique-int y)))
(cond ((null yv) '(|t|)) ((try-lazy-unify xv yv) '(|t|))))))))))
f-mode target xl xrrl)
'(?x &? ?y)))))))
(when (eql xrl '&+?)
(when (consp xrr)
(let ((xrrl (first xrr)) (xrrr (rest xrr)))
(when (eql xrrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (_fmode target x y)
(declare (ignore _fmode target))
(cond ((existential-exprp y)
(let ((xf (km-unique-int x)))
(cond ((null xf) '(|t|))
((unifiable-with-existential-expr xf y :classes-subsumep t)
'(|t|)))))
((existential-exprp x)
(let ((yf (km-unique-int y)))
(cond ((null yf) '(|t|))
((unifiable-with-existential-expr yf x :classes-subsumep t)
'(|t|)))))
(t
(let ((xv (km-unique-int x)))
(cond ((null xv) '(|t|))
(t
(let ((yv (km-unique-int y)))
(cond ((null yv) '(|t|))
((try-lazy-unify xv yv :classes-subsumep t) '(|t|))))))))))
f-mode target xl xrrl)
'(?x &+? ?y)))))))
(when (eql xrl '&+)
(when (consp xrr)
(let ((xrrl (first xrr)) (xrrr (rest xrr)))
(when (eql xrrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (fmode target x y)
(let ((unification
(lazy-unify-exprs x y :classes-subsumep t :fail-mode fmode :target target)))
(cond (unification (list unification))
((eq fmode 'error)
(report-error 'user-error "Unification (~a &+ ~a) failed!~%" x y)))))
f-mode target xl xrrl)
'(?x &+ ?y)))))))
(when (eql xrl '&+!)
(when (consp xrr)
(let ((xrrl (first xrr)) (xrrr (rest xrr)))
(when (eql xrrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (fmode target x y)
(cond ((km-int `(,x &+? ,y) :target target :fail-mode fmode)
(km-int `(,x &! ,y) :target target :fail-mode 'error))
((eq fmode 'error)
(report-error 'user-error "Unification (~a &+! ~a) failed!~%" x y))))
f-mode target xl xrrl)
'(?x &+! ?y)))))))
(when (eql xrl '=)
(when (consp xrr)
(let ((xrrl (first xrr)) (xrrr (rest xrr)))
(or (when (eql xrrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (fmode target x y)
(declare (ignore target))
(let ((xv (km-int x :fail-mode fmode)) (yv (km-int y :fail-mode fmode)))
(cond ((km-set-equal (dereference xv) yv) '(|t|)))))
f-mode target xl xrrl)
'(?x = ?y))))
(when (consp xrrr)
(let ((xrrrl (first xrrr)) (xrrrr (rest xrrr)))
(when (eql xrrrl '+/-)
(when (consp xrrrr)
(let ((xrrrrl (first xrrrr)) (xrrrrr (rest xrrrr)))
(or (when (eql xrrrrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target x y z)
(declare (ignore _fmode _target))
(let ((xval (km-unique-int x :fail-mode 'error))
(yval (km-unique-int y :fail-mode 'error))
(zval (km-unique-int z :fail-mode 'error)))
(cond ((and (numberp xval) (numberp yval) (numberp zval))
(cond ((<= (abs (- xval yval)) (abs zval)) '(|t|)))))))
f-mode target xl xrrl xrrrrl)
'(?x = ?y +/- ?z))))
(when (consp xrrrrr)
(let ((xrrrrrl (first xrrrrr)) (xrrrrrr (rest xrrrrr)))
(when (eql xrrrrrl '%)
(when (eql xrrrrrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target x y z)
(declare (ignore _fmode _target))
(let ((xval (km-unique-int x :fail-mode 'error))
(yval (km-unique-int y :fail-mode 'error))
(zval (km-unique-int z :fail-mode 'error)))
(cond ((and (numberp xval) (numberp yval) (numberp zval))
(cond ((<= (abs (- xval yval))
(*
(max (abs xval) (abs yval))
(abs zval)
0.01))
'(|t|)))))))
f-mode target xl xrrl xrrrrl)
'(?x = ?y +/- ?z %)))))))))))))))))
(when (eql xrl '/=)
(when (consp xrr)
(let ((xrrl (first xrr)) (xrrr (rest xrr)))
(when (eql xrrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (fmode target x y)
(declare (ignore target))
(let ((xv (km-int x :fail-mode fmode)) (yv (km-int y :fail-mode fmode)))
(cond ((not (km-set-equal (dereference xv) yv)) '(|t|)))))
f-mode target xl xrrl)
'(?x /= ?y)))))))
(when (eql xrl '|has-definition|)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target instance-expr slotsvals)
(declare (ignore _fmode _target))
(let ((instance (km-unique-int instance-expr :fail-mode 'error)))
(cond ((not (kb-objectp instance))
(report-error 'user-error "~a~%~a isn't/doesn't evaluate to a KB object name.~%"
`(|every| ,instance-expr |has-definition| ,@slotsvals)
instance-expr))
((are-slotsvals slotsvals)
(let* ((slotsvals0 (desource+decomment slotsvals))
(parents-of-defined-concept (vals-in (assoc '|instance-of| slotsvals0))))
(cond ((not (every #'kb-objectp parents-of-defined-concept))
(report-error 'user-error
"~a~%The `instance-of' slot-filler(s) in a has-definition must be atomic class name(s) only.~%"
`(,instance-expr |has-definition| ,@slotsvals0)))
((null parents-of-defined-concept)
(report-error 'user-error
"~a~%You must specify an `instance-of' slot value for a has-definition, pointing to the parent class(es)!~%"
`(,instance-expr |has-definition| ,@slotsvals0)))
(t
(add-slotsvals instance slotsvals0 :facet 'own-definition)
(point-parents-to-defined-concept instance parents-of-defined-concept
'own-definition)
(km-setq '*are-some-definitions* t)
(un-done instance)
(classify instance :slots-that-changed (mapcar #'slot-in slotsvals))
(list instance))))))))
f-mode target xl xrr)
'(?instance-expr |has-definition| &rest))))
(when (eql xrl '|now-has-definition|)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target instance-expr slotsvals)
(declare (ignore _fmode _target))
(let ((instance (km-unique-int instance-expr :fail-mode 'error)))
(cond ((not (kb-objectp instance))
(report-error 'user-error "~a~%~a isn't/doesn't evaluate to a KB object name.~%"
`(|every| ,instance-expr |now-has-definition| ,@slotsvals)
instance-expr))
((are-slotsvals slotsvals)
(let* ((slotsvals0 (desource+decomment slotsvals))
(parents-of-defined-concept (vals-in (assoc '|instance-of| slotsvals0))))
(cond ((not (every #'kb-objectp parents-of-defined-concept))
(report-error 'user-error
"~a~%The `instance-of' slot-filler(s) in a now-has-definition must be atomic class name(s) only.~%"
`(,instance-expr |now-has-definition| ,@slotsvals0)))
((and (null parents-of-defined-concept) slotsvals0)
(report-error 'user-error
"~a~%You must specify an `instance-of' slot value for a now-has-definition, pointing to the parent class(es)!~%"
`(,instance-expr |now-has-definition| ,@slotsvals0)))
(t
(let ((own-definition-parents
(get-vals instance '|instance-of| :facet 'own-definition)))
(cond (own-definition-parents
(unpoint-parents-to-defined-concept instance
own-definition-parents 'own-definition))))
(mapc #'(lambda (situation)
(mapc #'(lambda (slotvals)
(let ((slot (slot-in slotvals))
(vals (vals-in slotvals)))
(uninstall-inverses instance slot vals situation)
(put-vals instance slot nil
:facet 'own-definition
:situation situation)))
(get-slotsvals instance
:situation situation
:facet 'own-definition)))
(all-situations-and-theories))
(cond (parents-of-defined-concept
(add-slotsvals instance slotsvals0 :facet 'own-definition)
(point-parents-to-defined-concept instance
parents-of-defined-concept
'own-definition)
(km-setq '*are-some-definitions* t)
(un-done instance)
(classify instance
:slots-that-changed (mapcar #'slot-in slotsvals))))
(list instance))))))))
f-mode target xl xrr)
'(?instance-expr |now-has-definition| &rest))))
(when (eql xrl '>)
(when (consp xrr)
(let ((xrrl (first xrr)) (xrrr (rest xrr)))
(when (eql xrrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target x y)
(declare (ignore _fmode _target))
(let ((xval (km-unique-int x :fail-mode 'error))
(yval (km-unique-int y :fail-mode 'error)))
(cond ((and (numberp xval) (numberp yval)) (cond ((> xval yval) '(|t|)))))))
f-mode target xl xrrl)
'(?x > ?y)))))))
(when (eql xrl '<)
(when (consp xrr)
(let ((xrrl (first xrr)) (xrrr (rest xrr)))
(when (eql xrrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target x y)
(declare (ignore _fmode _target))
(let ((xval (km-unique-int x :fail-mode 'error))
(yval (km-unique-int y :fail-mode 'error)))
(cond ((and (numberp xval) (numberp yval)) (cond ((< xval yval) '(|t|)))))))
f-mode target xl xrrl)
'(?x < ?y)))))))
(when (eql xrl '>=)
(when (consp xrr)
(let ((xrrl (first xrr)) (xrrr (rest xrr)))
(when (eql xrrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target x y)
(declare (ignore _fmode _target))
(let ((xval (km-unique-int x :fail-mode 'error))
(yval (km-unique-int y :fail-mode 'error)))
(cond ((and (numberp xval) (numberp yval)) (cond ((>= xval yval) '(|t|)))))))
f-mode target xl xrrl)
'(?x >= ?y)))))))
(when (eql xrl '<=)
(when (consp xrr)
(let ((xrrl (first xrr)) (xrrr (rest xrr)))
(when (eql xrrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target x y)
(declare (ignore _fmode _target))
(let ((xval (km-unique-int x :fail-mode 'error))
(yval (km-unique-int y :fail-mode 'error)))
(cond ((and (numberp xval) (numberp yval)) (cond ((<= xval yval) '(|t|)))))))
f-mode target xl xrrl)
'(?x <= ?y)))))))
(when (eql xrl '|and|)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target x rest)
(declare (ignore _fmode _target))
(cond ((and (listp x) (= (length x) 3) (eq (second x) '==))
(let* ((xx (first x)) (yy (third x)))
(cond ((and (km-varp xx) (km-varp yy)) (km-int (subst xx yy rest)))
((km-varp xx) (km-int (subst (vals-to-val (km-int yy)) xx rest)))
((km-varp yy) (km-int (subst (vals-to-val (km-int xx)) yy rest)))
((and (lazy-unify-&-expr `(,xx == yy) :fail-mode 'error :joiner '==)
(km-int rest))))))
(t (and (km-int x) (km-int rest)))))
f-mode target xl xrr)
'(?x |and| &rest))))
(when (eql xrl '|or|)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target x y)
(declare (ignore _fmode _target))
(or (and (not (on-goal-stackp x)) (km-int x)) (km-int y)))
f-mode target xl xrr)
'(?x |or| &rest))))
(when (eql xrl '|is-subsumed-by|)
(when (consp xrr)
(let ((xrrl (first xrr)) (xrrr (rest xrr)))
(when (eql xrrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (fmode target x y)
(km-int `(,y |subsumes| ,x) :fail-mode fmode :target target :rewritep t))
f-mode target xl xrrl)
'(?x |is-subsumed-by| ?y)))))))
(when (eql xrl '|subsumes|)
(when (consp xrr)
(let ((xrrl (first xrr)) (xrrr (rest xrr)))
(when (eql xrrr 'nil)
(return-from km-handler
(values (funcall #'(lambda (_fmode _target x y)
(declare (ignore _fmode _target))
(let ((yv (km-int y)))
(cond ((null yv) '(|t|))
(t
(let ((xv (km-int x)))
(cond ((and (not (null xv)) (subsumes xv yv)) '(|t|))))))))
f-mode target xl xrrl)
'(?x |subsumes| ?y)))))))
(when (eql xrl '|is-covered-by|)
(when (consp xrr)
(let ((xrrl (first xrr)) (xrrr (rest xrr)))
(when (eql xrrr 'nil)
(return-from km-handler