Skip to content

Commit 5803a65

Browse files
committed
Add lisp-inference/web system
It contemples a webapp HTTP interface for Lisp Inference Truth Table system. It receives a infix logic proposition and returns a truth table.
1 parent ec38898 commit 5803a65

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

lisp-inference.asd

+14
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@
2121
(:file "truth-table"
2222
:depends-on ("parser" "operators" "equivalences"))))
2323

24+
(asdf:defsystem #:lisp-inference/web
25+
:description "An web interface for Lisp Inference Truth Table"
26+
:author "Manoel Vilela <[email protected]>"
27+
:license "BSD"
28+
:version "0.2.0"
29+
:serial t
30+
:depends-on (:lisp-inference
31+
:weblocks
32+
:weblocks-ui
33+
:find-port
34+
:str)
35+
:pathname "web"
36+
:components ((:file "webapp")))
37+
2438
(asdf:defsystem #:lisp-inference/test
2539
:description "Lisp Inference Test Suit"
2640
:author "Manoel Vilela <[email protected]>"

web/webapp.lisp

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
(defpackage lisp-inference/web
2+
(:use #:cl
3+
#:weblocks-ui/form
4+
#:weblocks/html)
5+
(:import-from #:weblocks/widget
6+
#:render
7+
#:update
8+
#:defwidget)
9+
(:import-from #:weblocks/actions
10+
#:make-js-action)
11+
(:import-from #:weblocks/app
12+
#:defapp)
13+
(:export #:main
14+
#:*propostion*
15+
#:*port*)
16+
(:nicknames #:webapp))
17+
18+
(in-package lisp-inference/web)
19+
20+
(defvar *proposition* '(P => Q) "Default proposition")
21+
(defvar *port* (find-port:find-port))
22+
23+
(defapp truth-table
24+
:prefix "/"
25+
:description "Lisp Inference Truth Table")
26+
27+
(defwidget table ()
28+
((prop
29+
:initarg :prop
30+
:accessor prop)
31+
(truth
32+
:initarg :truth
33+
:initform nil
34+
:accessor truth)))
35+
36+
(defun truth-table (exp)
37+
(with-output-to-string (s)
38+
(let ((inference:*output-stream* s))
39+
(inference:print-truth-table (inference:infix-to-prefix exp)))))
40+
41+
(defun create-table (exp)
42+
(make-instance 'table
43+
:prop (format nil "~a" exp)
44+
:truth (truth-table exp)))
45+
46+
(defun update-table (table exp)
47+
(setf (prop table) (format nil "~a" exp))
48+
(setf (truth table) (truth-table exp)))
49+
50+
(defgeneric update-proposition (table exp))
51+
52+
(defmethod update-proposition (table (exp list))
53+
(update-table table exp)
54+
(update table))
55+
56+
(defmethod update-proposition (table (string string))
57+
(update-proposition
58+
table
59+
(mapcar (lambda (x)
60+
(intern (string-upcase x)))
61+
(str:words (string-trim '(#\( #\)) string)))))
62+
63+
(defmethod render ((table table))
64+
(with-html
65+
(:h1 "Lisp Inference Truth Table System")
66+
(with-html-form (:POST (lambda (&key prop &allow-other-keys)
67+
(update-proposition table prop)))
68+
(:input :type "text"
69+
:name "prop"
70+
:placeholder (prop table))
71+
(:input :type "submit"
72+
:value "Eval"))
73+
(:pre (truth table))))
74+
75+
(defmethod render ((string string))
76+
(with-html
77+
(:pre string)))
78+
79+
(defmethod weblocks/session:init ((app truth-table))
80+
(declare (ignorable app))
81+
(create-table *proposition*))
82+
83+
(defun main (&optional (port *port*))
84+
(weblocks/debug:on)
85+
(weblocks/server:stop)
86+
(weblocks/server:start :port port))

0 commit comments

Comments
 (0)