[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Axiom-developer] Interpreter commands from Spad?
From: |
Arthur Ralfs |
Subject: |
[Axiom-developer] Interpreter commands from Spad? |
Date: |
Tue, 28 Aug 2007 12:12:39 -0700 |
User-agent: |
Thunderbird 1.5.0.12 (X11/20060911) |
Hi All,
I'm trying to send axiom output to a browser using spad sockets.
So far I'm hung up on submitting the command to axiom from
within spad and understanding the result. Below is my code
attempt to date. I am not at this point trying to actually send
anything back to the browser.
First the lisp stuff, file: http.lisp
-------------------------------------------------------------
;; file: http.lisp
;; some regexp stuff
(defun |StringMatch| (s1 s2)
(si::string-match s1 s2)
)
(defun |MatchBeginning| (i)
(si::match-beginning i)
)
(defun |MatchEnd| (i)
(si::match-end i)
)
;; the socket stuff
(defun |SiSock| (p spadfn)
;; (format t "SiSocket-1")
(si::socket p :server
(function
(lambda (w) (SPADCALL w spadfn) )
)
:daemon nil)
)
(defun |SiListen| (s)
;; (format t "SiListen-1")
(si::listen s)
)
(defun |SiAccept| (s) (si::accept s))
(defun |SiCopyStream| (q s) (si::copy-stream q s))
-----------------------------------------------------------------------
Now the spad code, file axserver.spad
-----------------------------------------------------------------------
)abbrev package SISOCK SiSocket
SiSocket: with
socketServer: (Integer, SExpression->Void) -> Void
axserver: SExpression -> Void
== add
socketServer(port:Integer,serverfunc:SExpression->Void):Void ==
WRITE_-LINE("socketServer")$Lisp
WRITE_-LINE("")$Lisp
s := SiSock(port,serverfunc)$Lisp
-- I listen for just one connection and then close the socket
-- to make debugging easier
i:Integer := 1
while (i > 0) repeat
if not null?(SiListen(s)$Lisp)$SExpression then
w := SiAccept(s)$Lisp
serverfunc(w)
i := 0
CLOSE(s)$Lisp
axserver(s:SExpression):Void ==
httpheaders:List String := []
httphead:String
numheads:Integer := 0
i:Integer
itest:Integer
jtest:Integer := 1
-- read in the http headers
while jtest > 0 repeat
httphead := ""
itest := 1
while itest > 0 repeat
c := STRING(READ_-CHAR(s)$Lisp)$Lisp
if c = " " then itest := 0
else httphead := concat [httphead, c]
numheads := numheads + 1
-- I want to test when there are no more characters to read in s
-- but don't know how to do it properly. The "Connection:" header
-- is the last one I've noticed so I just test for that for now.
-- I could also use read-char-no-hang, test for nil, wait a
bit, and
-- try again.
if StringMatch("Connection:",httphead)$Lisp > -1 then
jtest := 0
httpheaders := concat!(httpheaders, httphead)
headers:String := ""
for i in 1..#httpheaders repeat
headers := concat [headers," ",httpheaders.i]
sayTeX$Lisp headers
-- Pick out the axiom command from the GET string. It should be
-- encoded as, e.g., http://localhost:8085/?axiom=(x+y)**2
StringMatch( "(/?axiom=)(.*)",httpheaders.2)$Lisp
axcomm:String
u:UniversalSegment(Integer)
u :=
segment(MatchBeginning(2)$Lisp+1,MatchEnd(2)$Lisp)$UniversalSegment(Integer)
axcomm := (httpheaders.2).u
-- I found 2 functions in interp/server.boot.pamphlet which seem to
-- be what I want. I don't see any difference between them.
-- parseAndEvalStr$Lisp axcomm
parseAndInterpret$Lisp axcomm
-- fetchOutput is defined in interp/i-hist.boot.pamphlet
histvar := fetchOutput(-1)$Lisp
display(coerce(histvar)$TexFormat)$TexFormat
----------------------------------------------------------------------------
To run this example I first enter:
)lisp (load "http.lisp")
)compile axserver
Now I include my actual axiom output
----------------------------------------------------------------------------
(1) -> )set messages autoload off
(1) -> (x+y)**2
2 2
(1) y + 2x y + x
Type: Polynomial
Integer
(2) -> coerce(%)$TexFormat
(2) ["$$","{y \sp 2}+{2 \ x \ y}+{x \sp 2} ","$$"]
Type:
OutputForm
(3) -> socketServer(8085,axserver$SISOCK)
socketServer
GET /?axiom=(x+y)**2 HTTP/1.1
Host: 127.0.0.1:8085
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.4)
Gecko/20061023 SUSE/2.0.0.4-1.1 Firefox/2.0.0.4
Accept:
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection:
2 2
(3) y + 2x y + x
Type: Polynomial
Integer
$$
{Polynomial
\left(
{{Integer()}}
\right)}
\left(
{WRAPPED, \: 1, \: y, \: {2
\left(
{0}
\right)},
\: {1
\left(
{1, \: x, \: {1
\left(
{0}
\right)}}
\right)},
\: {0
\left(
{1, \: x, \: {2
\left(
{0}
\right)}}
\right)}}
\right)
$$
--------------------------------------------------------------------------
My problem is that I don't know how to interpret the output
and get the correctly formatted TeX. At this point I've tried
everything I can think of.
Thanks for any help
Arthur Ralfs
- [Axiom-developer] Interpreter commands from Spad?,
Arthur Ralfs <=