Re: PSP
From: Benjamin Johnston (superhero_at_benjaminjohnston.com.au)
Date: 03/20/04
- Next message: Benjamin Johnston: "Re: Mainstreaming Prolog a Pragmatic Approach?"
- Previous message: Alan Bal jeu: "Re: Prolog & Incompleteness"
- In reply to: Michael D. Kersey: "Re: PSP"
- Next in thread: Benjamin Johnston: "Re: PSP"
- Reply: Benjamin Johnston: "Re: PSP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 20 Mar 2004 14:43:08 +1000
Okay, I'd be interested in your opinions on syntax of PSP...
%%%%%%%%%%%%%%%
I am now aware of four syntaxes:
- Suciu and Pusztai
- My own
- Jan Wielemaker from SWI-Prolog (I haven't seen this code, however)
- MINERVA Prolog, has MSS (but I can't find what that stands for)
%%%%%%%%%%%%%%%
% Suciu and Pusztai
%%%%%%%%%%%%%%%
Suciu and Pusztai,
http://conference.iasi.roedu.net/site/conference/papers/SUCIU_A-Prolog_Serve
r_Pages.pdf
used a syntax like this:
<html>
<head><title>Hello World example</title></head>
<body>
<?psp
msg('Hello, World!').
?- msg(X),write(X).
?>
</body>
</html>
I quite like this because it allows clauses to be defined, and queries
submitted in the one document. Furthermore, if a query fails, it does not
cause the entire page to "fail". On the downside, however, it doesn't really
look like it allows the programmer to directly mix the Prolog and HTML.
%%%%%%%%%%%%%%%
% My own
%%%%%%%%%%%%%%%
I experimented with many possibilities, but in my work I settled on the idea
that a PSP page is a query. So I had code like this:
<html>
<head><title>Hello World example</title>
</head>
<body>
<?, X is 3 + 2, ?>
Hi, the sum of 3 and 2 comes to <?= X ?>
The members of my family are:<br>
<?, forall(
member(Person, ['ben','michael','sue','graham']),
?> <b><?= Person?></b><br> <?
),?>
</pre>
</body>
</html>
In other words, each PSP page was a single query - the parser basically just
replaced the HTML sections with writes, so that:
hello <?, X=1, ?> X is equal to <?= X ?>
would be translated into the following query,
write('hello '), X = 1, (write('X is equal to'), write(X)).
Predicates could be defined by the user because every .pl file in the
current directory was automatically consulted on the webserver startup.
The thing that I like about my approach is that it quite easy and natural to
produce fairly complex page layouts -- and that it works in a way that is
very similar to the other server-pages technologies. The downside is that
there is a greater need to be careful about coping with failure - because if
a particular subclause fails then the bottom of the page is likely to be
chopped off. I don't think this is too big a deal, however, because this is
exactly the same issue that you need to consider when writing any old Prolog
predicate. Use of things that always succeed (such as forall) also prevent
that from happenning. Another downside is that predicates cannot be defined
in-line --- however, I don't see any reason that I couldn't extend the
syntax to include a <?prolog ?> or <?psp ?> tag that allows predicates to be
defined.
%%%%%%%%%%%%%%%
% Jan Wielemaker
%%%%%%%%%%%%%%%
As far as I can tell, Jan's code is not available.
%%%%%%%%%%%%%%%
% MINERVA
%%%%%%%%%%%%%%%
I could only find one sample .mss file in the MINERVA evaluation (I can't
seem to find any online discussion of it, or mention of it in the
documentation). But, the basic idea appears to be that you write something
like a Java servlet in Prolog. It appears that MINERVA also has a special
syntax to simplify development.
I don't want to quote MINVERA's sample file in full -- you can download a
free trial edition if you're interested. But, it looks like an .mss file
consists of the following parts:
<%!
a set of prolog predicates to define how to respond to a particular query --
specifically taking POST/GET requests, and then appropriately "invoking" the
next "function" to handle it.
in this case we might have an clause that says (sample copied directly from
MINVERA's file):
select_method(_, Request, Response) :- !,
response_setContentType(Response, 'text/html'),
response_getWriter(Response, Writer),
request_getContentType(Request, ContentType),
show_error(Writer, ContentType).
%>
<%@ function show_error(ContentType) %>
<html>
some html content can go here
</html>
<% end %>
<%@ function show_content(Request, MultipartRequest) %>
<html>
<body>
<%@ include show_data(Request) %>
<%@ include show_parts(MultipartRequest) %>
</body>
</html>
<% end %>
<%@ function show_data(Request) %>
here's an in-line display: <%= request_getMethod(Request) %><br>
<% end %>
<%@ function show_parts(Request) %>
<% loop multipart_element(Request, Element) %>
<%@ include show_element(Request, Element) %>
<% end %>
<% end %>
and so on...
The advantage of this format, appears to be first and foremost a closer
relationship to the underlying mechanisms themselves. It appears to be more
like what Java Servlets are to Java, but for Prolog. Of course, the downside
is that it looks like a lot of effort if all you really want to do is
produce a simple website from a bit of Prolog.
%%%%%%%%%%%%%%%
I think I prefer my single query technique, but I like the way that Suciu
and Pusztai allowed for predicates to be defined within the file. Maybe the
hybrid approach with <?prolog ?> or <?psp ?> defining the compile-time tasks
(that cannot generate input) and the single query approach is the best
combination.
Any thoughts?
-Benjamin Johnston
> Jan Wielemaker wrote:
> <snipped>
> > The SWI-Prolog application database (available from the website) runs
> > in something I also called PSP (obvious name :-). I never published
> > the code though and I don't think it is in a state where it is worth
> > publishing :-)
>
> And here's yet another "Prolog Server Pages" implementation:
>
http://conference.iasi.roedu.net/site/conference/papers/SUCIU_A-Prolog_Serve
r_Pages.pdf
> or in Google's HTML format:
>
http://216.239.41.104/search?q=cache:CZQGjuYJzS8J:conference.iasi.roedu.net/
site/conference/papers/SUCIU_A-Prolog_Server_Pages.pdf+mod_psp+Prolog&hl=en&
ie=UTF-8
- Next message: Benjamin Johnston: "Re: Mainstreaming Prolog a Pragmatic Approach?"
- Previous message: Alan Bal jeu: "Re: Prolog & Incompleteness"
- In reply to: Michael D. Kersey: "Re: PSP"
- Next in thread: Benjamin Johnston: "Re: PSP"
- Reply: Benjamin Johnston: "Re: PSP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|