Skip to content

Commit efc40e9

Browse files
authored
Merge pull request #15 from ryukinix/webapp
Add lisp-inference/web system
2 parents ec38898 + 79bb813 commit efc40e9

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed

lisp-inference.asd

Lines changed: 14 additions & 0 deletions
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]>"

roswell/inference-server.ros

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/sh
2+
#|-*- mode:lisp -*-|#
3+
#|
4+
exec ros -Q -- $0 "$@"
5+
|#
6+
7+
#+quicklisp (defun ensure-dist-installed (dist nick)
8+
(let ((d (ql-dist:find-dist nick)))
9+
(when (not (and d (ql-dist:installedp d)))
10+
(ql-dist:install-dist dist
11+
:prompt nil))))
12+
13+
(progn ;;init forms
14+
(ros:ensure-asdf)
15+
#+quicklisp (progn
16+
(ensure-dist-installed "http://dist.ultralisp.org" "ultralisp")
17+
(ql:quickload '(lisp-inference/web)))
18+
19+
)
20+
21+
(defpackage :ros.script.lisp-inference/web
22+
(:use :cl))
23+
(in-package :ros.script.lisp-inference/web)
24+
25+
(defparameter *port* lisp-inference/web:*port*)
26+
27+
(defun main (&rest argv)
28+
(declare (ignorable argv))
29+
(when (car argv)
30+
(setq *port* (parse-integer (car argv))))
31+
(unwind-protect
32+
(handler-case
33+
(progn
34+
(format t "[+] Starting Lisp Inference server...~%")
35+
(lisp-inference/web:start *port*)
36+
(format t "[+] http://127.0.0.1:~a~%" *port*)
37+
(format t "[+] Press C-c to kill Lisp Inference server...~%")
38+
(loop do (sleep 10)))
39+
(#+sbcl sb-sys:interactive-interrupt
40+
#+ccl ccl:interrupt-signal-condition
41+
#+clisp system::simple-interrupt-condition
42+
#+ecl ext:interactive-interrupt
43+
#+allegro excl:interrupt-signal
44+
() (progn
45+
(format *error-output* "Aborting.~&")
46+
(lisp-inference/web:stop)
47+
(uiop:quit))))
48+
(lisp-inference/web:stop)))
49+
;;; vim: set ft=lisp lisp:

web/webapp.lisp

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

0 commit comments

Comments
 (0)