-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexamples.lisp
792 lines (676 loc) · 22.3 KB
/
examples.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
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
;;==================================================================;;
;; Joshua Taylor
;; December 9, 2009
;;==================================================================;;
(defpackage #:mobile-ambients-examples
(:documentation "The symbols exported from this package are not
likely to be of too much use on their own, but rather
``examples.lisp'' should be read in parallel with Cardelli & Gordon's
``Mobile ambients.'' The section number of this file follows their
paper, and most of the examples have worked out here.")
(:use #:mobile-ambients "COMMON-LISP")
(:nicknames #:amb-ex)
(:shadowing-import-from #:mobile-ambients
#:open)
(:shadow #:get #:set)
(:export ; A Generic Process engine
#:shorten
#:generic-process-example)
(:export ; 2.4.1 Locks
#:acquire
#:release
#:lock-example)
(:export ; 2.4.2 Mobile agent authentication
#:authentication-example)
(:export ; 2.4.3 Firewall access
#:firewall
#:agent
#:firewall-example)
(:export ; 2.4.4 Movement ... subjective vs. objective
#:obj-in #:obj-in^
#:obj-out #:obj-out^
#:obj-in-example
#:obj-out-example
#:entrap
#:entrap-example)
(:export ; 2.4.5 Dissolution
#:acid #:acid^
#:acid-example
#:acid-in
#:acid-out
#:acid-in-example
#:acid-out-example
#:acid*
#:acid*-example)
(:export ; 2.4.6 Encoding objective moves
#:allow
#:mv-in
#:mv-out
#:ambi
#:ambo
#:ambio
#:objective-move-example-1
#:objective-move-example-2)
(:export ; 2.4.7 Synchronization on named channels
#:?
#:!
#:synchronization-example)
(:export ; 2.4.8 Choice
#:choice
#:choice-example)
(:export ; 2.4.9 Renaming
#:be
#:be-example)
(:export ; 2.4.10 Seeing
#:see
#:see-example)
(:export ; 2.4.11 Iteration
#:rec-fn
#:rec
#:rec-example)
(:export ; 2.4.12 Numerals
#:|0|
#:|i+1|
#:ifzero
#:numeral-example-1
#:numeral-example-2
#:inc
#:inczero
#:incsucc
#:dec
#:numeral-example-3
#:numeral-example-3)
(:export ; 3.4.1 Cells
#:cell
#:get-for
#:get
#:set
#:get-and-set-in
#:get-and-set
#:cell-example-1
#:cell-example-2)
(:export ; Safe Ambients
#:$in #:$in^ #:$out #:$out^ #:$open #:$open^
#:in$ #:in$^ #:out$ #:out$^ #:open$ #:open$^
#:safe-ambients-example-1
#:safe-ambients-example-2
#:safe-ambients-example-3)
(:export ; Miscellaneous Examples
#:tree-reduce
#:tree-reduce-example-1
#:tree-reduce-example-2))
(in-package #:mobile-ambients-examples)
(defmacro defexample (name &body body)
(let ((args (gensym (string '#:args-))))
`(defun ,name (&rest ,args)
(apply 'run-process
(progn (par ,@body))
,args))))
;;; A Generic Process Engine
(defun shorten (list)
(setf (rest list) (rest (rest list))))
(defmethod evolutions ((list list))
(if (endp (rest list)) '()
(list #'(lambda () (shorten list)))))
(defmethod cleanup ((list list))
(declare (ignore list))
nil)
(defun generic-process-example ()
(run-process
(list 1 2 3 4 5)))
;;; Mobile Ambients
;; 2.4.1 Locks
(defun acquire (n P)
(open n P))
#+lispworks (editor:setup-indent "acquire" 1)
(defun release (n P)
(par (amb n) P))
(defexample lock-example
(acquire 'n (release 'm (named 'P)))
(release 'n (acquire 'm (named 'Q))))
;; 2.4.2 Mobile agent authentication
(defexample authentication-example
(amb 'home
(new (n)
(par (open n)
(amb 'agent
(out 'home
(in 'home
(amb n
(out 'agent
(open 'agent (named 'p)))))))))))
;; 2.4.3 Firewall access
(defun firewall ()
(new (w)
(amb w
(amb 'k (out w (in 'k2 (in w))))
(open 'k2 (open 'k3 (named 'p))))))
(defun agent ()
(amb 'k2
(open 'k
(amb 'k3
(named 'Q)))))
(defexample firewall-example
(firewall)
(agent))
;; 2.4.4 Movement ... subjective vs. objective
(defclass obj-in (capability) ()
(:documentation "Objective entry capability."))
(defun obj-in^ (name)
(make-instance 'obj-in :name name))
(defun obj-in (name process)
(cap (obj-in^ name) process))
(defmethod write-process (stream (oi obj-in))
(format stream "omv in ~:w" (capability-name oi)))
;; this implementation uses less LOOP
#-(and)
(defmethod action-evolutions ((oi obj-in) (action action))
(let ((parent (process-parent action))
(aprocess (action-process action))
(name (capability-name oi))
(evolutions '()))
(dolist (sibling (process-siblings action))
(when (and (typep sibling 'ambient)
(eql name (ambient-name sibling)))
(let ((sibling sibling))
(push #'(lambda ()
(setf (process-parent aprocess) sibling)
(push aprocess (composition-processes sibling))
(setf (composition-processes parent)
(delete action
(composition-processes parent))))))))))
;; this implementation uses more LOOP
(defmethod action-evolutions ((oi obj-in) (action action))
(loop with parent = (process-parent action)
with aprocess = (action-process action)
with name = (capability-name oi)
for sibling in (process-siblings action)
when (amb::ambientp sibling name)
collect (let ((target sibling))
#'(lambda ()
(setf (process-parent aprocess) target)
(push aprocess (composition-processes target))
(setf (composition-processes parent)
(delete action
(composition-processes parent)))))))
(defexample obj-in-example
(obj-in 'm (named 'P))
(amb 'm (named 'R)))
(defclass obj-out (capability) ()
(:documentation "Objective exit capability."))
(defun obj-out^ (name)
(make-instance 'obj-out :name name))
(defun obj-out (name process)
(cap (obj-out^ name) process))
(defmethod write-process (stream (oo obj-out))
(format stream "omv out ~:w" (capability-name oo)))
(defmethod action-evolutions ((oo obj-out) (action action))
(let ((parent (process-parent action))
(aprocess (action-process action)))
(if (not (amb::ambientp parent (capability-name oo))) '()
(let ((pparent (process-parent parent)))
(list #'(lambda ()
(setf (process-parent aprocess) pparent)
(setf (composition-processes parent)
(delete action (composition-processes parent)))
(push aprocess (composition-processes pparent))))))))
(defexample obj-out-example
(amb 'm
(obj-out 'm (named 'P))
(named 'R)))
(defun entrap (m)
(new (k)
(par (amb k)
(obj-in m (in k)))))
(defexample entrap-example
(entrap 'm)
(amb 'm (named 'P)))
;; 2.4.5 Dissolution
(defclass acid (capability) ()
(:documentation "A dissolution capability."))
(defun acid^ ()
(make-instance 'acid))
(defmethod write-process (stream (acid acid))
(declare (ignore acid))
(write-string "acid" stream))
(defun acid (process)
(cap (acid^) process))
(defmethod action-evolutions ((acid acid) (action action))
(let ((parent (process-parent action)))
(if (not (amb::ambientp parent)) '()
(list #'(lambda () (amb::open-ambient action parent))))))
(defexample acid-example
(amb 'm
(acid (named 'P))
(named 'Q)))
(defun acid-in (n P)
(new (q)
(amb q (in n (acid P)))))
(defun acid-out (n P)
(new (q)
(amb q (out n (acid P)))))
(defexample acid-in-example
(acid-in 'm (named 'P))
(amb 'm (named 'R)))
(defexample acid-out-example
(amb 'm (acid-out 'm (named 'P)) (named 'R)))
(defun acid* (n &optional (P (zero)))
(amb 'acid (out n (open n P))))
(defexample acid*-example
(amb 'n
(acid* 'n (named 'P))
(named 'Q))
(open 'acid))
;; 2.4.6 Objective moves
(defun allow (n)
(open n (fun (allow n))))
(defun mv-in (n P &optional (enter 'enter))
(new (k)
(amb k (in n (amb enter (out k (open k P)))))))
(defun mv-out (n P &optional (exit 'exit))
(new (k)
(amb k (out n (amb exit (out k (open k P)))))))
(defun ambi (n P &optional (enter 'enter))
(amb n
(par P)
(allow enter)))
(defun ambo (n P &optional (exit 'exit))
(par (amb n P)
(allow exit)))
(defun ambio (n &optional (P (zero)) (enter 'enter) (exit 'exit))
(par (amb n (par P (allow enter)))
(allow exit)))
(defexample objective-move-example-1
(mv-in 'n (named 'P))
(ambio 'n (named 'Q)))
(defexample objective-move-example-2
(ambio 'n
(par (mv-out 'n (named 'P))
(named 'Q))))
;; 2.4.7 Synchronization on named channels
(defun ? (n P)
(mv-in n (acquire 'rd (release 'wr (mv-out n P)))))
(defun ! (n P)
(mv-in n (release 'rd (acquire 'wr (mv-out n P)))))
(defexample synchronization-example
(ambio 'a)
(! 'a (named 'P))
(? 'a (named 'Q)))
;; 2.4.8 Choice
(defun choice (n P m Q)
(new (a b c)
(par (amb a (in n (out n (amb b (out a (open c P))))))
(amb a (in m (out m (amb b (out a (open c Q))))))
(open b)
(amb c))))
(defexample choice-example
(choice 'n (named 'P)
'm (named 'Q))
(amb 'n (named 'R)))
;; 2.4.9 Renaming
(defun be (n m P)
(par (amb m (out n (open n P))) (in m)))
(defexample be-example
(amb 'n
(be 'n 'm (named 'P))
(named 'Q)))
;; 2.4.10 Seeing
(defun see (n P)
(new (r s)
(par (amb r (in n (out n (be r s P))))
(open s))))
(defexample see-example
(amb 'n)
(see 'n (named 'P)))
;; 2.4.11 Iteration
(defun rec-fn (clauses process)
"* Syntax:
rec-fn clauses process => rec-process
* Arguments and Values:
- clauses---a plist of ambient names and process generating functions
- process, rec-process---processes
* Description:
rec-fn is based on Cardelli & Gordon's rec, about which they say:
``The following iteration construct has a number of branches (mi)Pi
and a body Q. Each branch can be triggered by exposing an ambient
mi[] in the body, which is then replaced by a copy of Pi.'' rec-fn
implements this construct as follows. Clauses is a property list of
ambient names \(objects) and functions of no arguments each of which,
when called, produces a process. Specifically, when an ambient with a
given name appears in the body, the corresponding function is called
to generate a process. The primary purpose of rec-fn is its use in
implementing the friendlier {defmacro amb-ex::rec} .
* See Also:
- {defmacro amb-ex::rec}"
(labels ((recopen (name alternative-gen)
(open name
(par (funcall alternative-gen)
(fun (recopen name
alternative-gen))))))
(if (endp clauses) process
(par (recopen (first clauses) (second clauses))
(rec-fn (rest (rest clauses)) process)))))
(defmacro rec (clauses &body processes)
"* Syntax:
rec ({(var form*)}) forms* => process
* Arguments and Values:
- var---a symbol naming a variable
- form---a form evaluated to produce a process
- process---a {defclass amb::process}
* Description:
The rec iteration and binding construct is described in section 2.4.11
of Cardelli & Gordon's ``Mobile ambients''. Each var is bound to a
new ambient name and within the body of the rec \(a parallel
composition of the processes produced by the body forms), if an
ambient is created with a given name, then a parallel composition of
the processes associated with the name is generated.
* Examples:
;;; (run-process
;;; (rec ((a (fun (print 'a1))
;;; (fun (print 'a2)
;;; (amb b)))
;;; (b (fun (print 'b1))
;;; (fun (print 'b2))))
;;; (amb a))
;;; nil)
;;; =>
;;; A1
;;; A2
;;; B2
;;; B1
;;; #<open #:A.({proc} | {proc} | {proc})
;;; | open #:B.({proc} | {proc} | {proc})>
* See Also:
- {defun amb-ex::rec-fn}"
`(new ,(mapcar 'first clauses)
(rec-fn (list ,@(mapcan
#'(lambda (clause)
(list (first clause)
`#'(lambda ()
,(list* 'par (rest clause)))))
clauses))
(par ,@processes))))
(defexample rec-example
(rec ((a (fun (print 'a)))
(b (fun (print 'b)))
(c (fun (print 'c))))
(amb a)))
;; 2.4.12 Numerals
(defun |0| ()
(amb 'zero))
(defun |i+1| (i)
(amb 'succ (open 'op) i))
(defun ifzero (P Q)
(choice 'zero P
'succ Q))
(defexample numeral-example-1
(|0|)
(ifzero (named 'P)
(named 'Q)))
(defexample numeral-example-2
(|i+1| (|i+1| (|0|)))
(ifzero (named 'P)
(named 'Q)))
(defun inc (P)
(ifzero (inczero P)
(incsucc P)))
(defun inczero (P)
(open 'zero
(par (|i+1| (|0|))
P)))
(defun incsucc (process)
(new (p q)
(par (amb p (amb 'succ (open 'op)))
(open q (open p process))
(amb 'op
(in 'succ
(in p
(in 'succ
(par (amb q (out 'succ (out 'succ (out p))))
(open 'op)))))))))
(defun dec (process)
(new (p)
(par (amb 'op
(in 'succ
(amb p (out 'succ))))
(open p (open 'succ process)))))
(defexample numeral-example-3
(|i+1| (|i+1| (|i+1| (|0|))))
(inc (named 'P)))
(defexample numeral-example-4
(|i+1| (|i+1| (|i+1| (|0|))))
(dec (named 'P)))
;; 3.4.1 Cells
(defun cell (cell-name value)
(ambio cell-name (output value)))
(defun get-for (cell process-function)
(mv-in cell (input x
(par (output x)
(mv-out cell (funcall process-function x))))))
(defmacro get (cell var &body process)
`(get-for ,cell #'(lambda (,var) ,@process)))
(defun set (cell value &optional (process (zero)))
(mv-in cell
(input x
(declare (ignore x))
(par (output value)
(mv-out cell process)))))
(defun get-and-set-in (cell value process-function)
(mv-in cell (input x
(par (output value)
(mv-out cell (funcall process-function x))))))
(defmacro get-and-set (cell var value &body process)
`(get-and-set-in ,cell ,value #'(lambda (,var) ,@process)))
(defexample cell-example-1
(cell 'c 1)
(get-and-set 'c v1 2
(get-and-set 'c v2 3
(get-and-set 'c v3 4
(get-and-set 'c v4 5
(fun (format t "~&;; *** ~A ~A ~A ~A "
v1 v2 v3 v4)))))))
(defexample cell-example-2
(cell 'c 0)
(set 'c 1)
(set 'c 2)
(set 'c 3)
(set 'c 4)
(set 'c 5)
(get 'c w
(get 'c x
(get 'c y
(get 'c z
(fun (format t "~&;; *** ~A ~A ~A ~A"
w x y z)))))))
;;; Mobile Safe Ambients
(defmacro defcapability (name)
"Define a class named NAME that includes capability as a superclass,
a write method for the class, a constructor NAME^ and function NAME
that constructs a process with prefixed with an instance of the new
capability with the specified name."
(let ((constructor (intern (concatenate 'string (string name) "^")))
(stream (gensym (string '#:stream-)))
(cname (gensym (string '#:cname-)))
(process (gensym (string '#:process-))))
`(progn
(defclass ,name (capability)
())
(defmethod write-process (,stream (,name ,name))
(format ,stream "~(~:w~) ~:w"
',name (capability-name ,name)))
(defun ,constructor (,cname)
(make-instance ',name :name ,cname))
(defun ,name (,cname ,process)
(cap (,constructor ,cname) ,process)))))
;; $x tries to achieve x, and x$ allows x to happen.
(defcapability $in)
(defcapability in$)
(defcapability $out)
(defcapability out$)
(defcapability $open)
(defcapability open$)
(defmethod action-evolutions (($in $in) (action action))
;; n[$in m.P] | m[in$ m.Q] => m[n[P] | Q]
(if (not (amb::ambientp (process-parent action))) '()
(let ((mover (process-parent action))
(target-name (capability-name (action-capability action)))
(evolutions '()))
(flet ((entry-allower-p (x)
(and (typep x 'action)
(typep (action-capability x) 'in$)
(eql target-name
(capability-name (action-capability x))))))
(dolist (sibling (process-siblings mover) evolutions)
(when (amb::ambientp sibling target-name)
(dolist (p (composition-processes sibling))
(when (entry-allower-p p)
(let ((p p)
(sibling sibling))
(push #'(lambda ()
(amb::deprefix action)
(amb::deprefix p)
(amb::move-ambient mover sibling))
evolutions))))))))))
(defmethod action-evolutions (($out $out) (action action))
;; m[n[$out m.P] | out$ m.Q] => n[P] | m[Q]
(let ((n (process-parent action))
(m (capability-name $out))
(evolutions '()))
(flet ((out-allower-p (x)
(and (typep x 'action)
(typep (action-capability x) 'out$)
(eql m (capability-name (action-capability x))))))
(when (and (amb::ambientp n)
(amb::ambientp (process-parent n) m))
(dolist (sibling (process-siblings n) evolutions)
(when (out-allower-p sibling)
(let ((sibling sibling))
(push #'(lambda ()
(amb::deprefix action)
(amb::deprefix sibling)
(amb::move-ambient
n (process-parent (process-parent n))))
evolutions))))))))
(defmethod action-evolutions (($open $open) (action action))
;; $open n.P | n[open$ n.Q] => P | Q
(let ((n (capability-name $open))
(evolutions '()))
(flet ((open-allower-p (x)
(and (typep x 'action)
(typep (action-capability x) 'open$)
(eql n (capability-name (action-capability x))))))
(dolist (sibling (process-siblings action) evolutions)
(when (amb::ambientp sibling n)
(dolist (p (composition-processes sibling))
(when (open-allower-p p)
(let ((p p)
(sibling sibling))
(push #'(lambda ()
(amb::deprefix action)
(amb::deprefix p)
(change-class sibling 'composition))
evolutions)))))))))
(defexample safe-ambients-example-1
(amb 'n ($in 'm (named 'P)))
(amb 'm (in$ 'm (named 'Q))))
(defexample safe-ambients-example-2
(amb 'm
(amb 'n ($out 'm (named 'P)))
(out$ 'm (named 'Q))))
(defexample safe-ambients-example-3
($open 'n (named 'P))
(amb 'n
(open$ 'n (named 'Q))
(named 'R)))
;;; Miscellaneous Examples
;; Computing the product of the leaves of a binary tree
(defun tree-reduce (leaf-fn node-fn tree result)
(if (atom tree)
(amb result (output (funcall leaf-fn tree)))
(new (m)
(amb result
(input x (input y (output (funcall node-fn x y))))
(open m) (fun (tree-reduce leaf-fn node-fn (first tree) m))
(open m) (fun (tree-reduce leaf-fn node-fn (second tree) m))))))
(defexample tree-reduce-example-1
(tree-reduce '- '+
'((1 2) (3 (4 5)))
'result))
(defexample tree-reduce-example-2
(tree-reduce 'list 'nconc
'((1 2) (3 (4 5)))
'result))
;; A parallelized propositional model finder
(defun %find-model (sentence pos neg posp sentences succeed fail)
(destructuring-bind (op &rest args)
(if (listp sentence) sentence
(list sentence))
(case op
((or)
(if posp
;; a positive disjunction spawns a number of processes,
;; testing the possible disjuncts.
(new (inner-fail)
(labels ((disjoin (args failer)
(if (endp args) failer
(par (disjoin (rest args)
(open inner-fail failer))
(fun (%find-model (first args)
pos neg t
sentences
succeed inner-fail))))))
(disjoin args (amb fail))))
;; a negative disjunction falsifies all its disjuncts
(%find-model `(not ,(first args))
pos neg t
(nconc (loop for a in args
collect `(not ,a))
sentences)
succeed fail)))
;; negation swaps posp for the negate
((not)
(%find-model (first args)
pos neg (not posp)
sentences
succeed fail))
;; (and x1 ... xn) becomes (not (or (not x1) ... (not xn)))
((and)
(%find-model `(not (or ,@(loop for a in args collect `(not ,a))))
pos neg posp
sentences
succeed fail))
;; (if x y) becomes (or (not x) y)
((if)
(%find-model `(or (not ,(first args))
,(second args))
pos neg posp
sentences
succeed fail))
;; (iff x y) becomes (and (if x y) (if y x))
((iff)
(%find-model `(and (if ,(first args) ,(second args))
(if ,(second args) ,(first args)))
pos neg posp
sentences
succeed fail))
;; atoms
(otherwise
(let ((atom (list* op args)))
(if (member atom (if posp neg pos) :test 'equal) (amb fail)
(if (endp sentences)
(amb succeed
(output
(list (if posp (pushnew atom pos :test 'equal) pos)
(if posp neg (pushnew atom neg :test 'equal)))))
(%find-model (first sentences)
(if posp (pushnew atom pos :test 'equal) pos)
(if posp neg (pushnew atom neg :test 'equal))
t (rest sentences) succeed fail))))))))
(defun find-model (sentence &rest args)
(apply 'run-process
(par
(%find-model sentence '() '() t '() 'succeed 'fail)
(open 'succeed (input model (return-from find-model
model))))
args))