axiom-developer
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [Axiom-developer] Re: Axiom HyperDoc Replacement


From: Bill Page
Subject: RE: [Axiom-developer] Re: Axiom HyperDoc Replacement
Date: Sat, 21 Apr 2007 09:15:52 -0400

On April 21, 2007 7:14 AM I wrote:
> 
> On April 21, 2007 4:03 AM Martin Rubey wrote:
> > 
> > Sorry, yet another question: How do I have to modify foo
> > 
> > (defun foo (s)
> >   (let* ((get (read s nil 'eof))
> >          (fn (and (eq get 'get) (read s nil 'eof))))
> >     (format t "Got ~S~%~%" fn)
> >     (format s "HTTP/1.1 ~S~%~%" (if fn 200 403))
> >     (format t "HTTP/1.1 ~S~%~%" (if fn 200 403))
> >     (format t "~S~%~%" (SPADCALL fn *docfun*))
> >     (format s "~S~%~%" (SPADCALL fn *docfun*))
> >     (close s)))
> > 
> > to make the browser render the html in fn. I.e., so far I 
> > just displayed strings, which were obtained by applying
> > *docfun* to fn.
> 
> You got SPADCALL to work for you - Cool! To bad you have
> to write this in Lisp, I would really like to get this
> working from SPAD.
> 
> > But now, (SPADCALL fn *docfun*) will actually result in
> > a path like binomial-COMBF.html, and I want the browser
> > to display that page.
>

Oh ... Now that I have had a cup of coffee and woken up a
little, I think that's so typically **brilliant** of you!
That is an excellent idea.

Instead of 'foo' let's just call this little Lisp function
the 'server' and 'bar' is called the 'socket'.

Since what we want is a browser interface for the desktop
why not just use the local file system? We don't need any
kind of especially fast web server because the browser can
read are we can write locally stored files much faster than
anything can be transferred over the Internet.

And this can be made transparent to the user because there
is a particular kind of HTTP response called a "redirection"
which does precisely what you want it to do: It tells the
browser to display a page from some place else. See response
status code 303 at http://jmarshall.com/easy/http

So all your *docfun* Spad function has to do is take the
input from fn, parse it to separate the data fields, do some
calculation, prepare the page, save it on disk in a known
location, and then return the location information to the
server, i.e. the path 'binomial-COMBF-001.html' in your
example. The server forwards this path to the browser as a
redirection and the browser automatically loads your newly
written page. Very Simple.
 
> What you need to do is to send an HTTP 'Content-type:'
> header as the first two lines of what is sent to the
> browser. By default the browser is just treating all
> output as text. Try this:
> 
>  (defun foo (s)
>    (let* ((get (read s nil 'eof))
>           (fn (and (eq get 'get) (read-line s nil 'eof))))
>      (format s "HTTP/1.1 ~S~%" (if fn 200 403))
>      (format s "Content-type: text/html~%~%")
>      (format s "<a href='~S'>click here</a>~%" (SPADCALL fn *docfun*))
>      (close s)))
>

For an automatic redirection all you really need is something
like this:

  (defun server (s)
    (let* ((get (read s nil 'eof))
           (fn (and (eq get 'get) (read-line s nil 'eof))))
      (format s "HTTP/1.1 ~S~%" (if fn 303 403))
      (format s "Location: ~S~%~%" (SPADCALL fn *docfun*))
      (close s))) 


> You will need to include the same header when sending HTML
> data from a file.
>

Actually what I wrote is not true in the case of a file that
is accessed locally by a web browser. No header is needed in
this case because the browser choices the content-type based
on the file extension. So a page that ends in .html will
automatically treated as mime-type 'text/html'. No problem.
 
> (Warning: I haven't actually tested it yet.)
> 
> Google for more HTTP references like this one:
> 
> http://www.jmarshall.com/easy/http
> 
> There are also lot of references to HTML such as the link
> 
>  <a href='url'> link </a>
> 
> generated in the example above. 
>

If you use automatic redirection, then you don't need this
in the server, but of course your Spad routines will have to
generate a lot of different HTML commands with embedded data
and graphics. This can even include LaTeX output if we use
the jsMath javascript on the browser.
 
> HTTP is the low level protocol for sending and receiving
> data from a web server. HTML is the mark-up language in which
> the data content usually encoded for web browsers.
> 

Actualy with your brilliantly simple idea, we only need to
know a little of the HTTP protocol. You will probably want
to read about the 'POST' command that allows you to send data
from a form or a text area displayed on the browser. This
information can be passed on to *docfun* as input. 

With this simple approach I think it should be quite easy
to implement the HyperDoc functionaliy using a standard web
browser. 

Regards,
Bill Page.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]