def person_row(p, conn) {
<tr>
<td>{[p.firstname :: " " :: p.surname]}</td>
<td><a href={"mailto:" :: p.email}>{[p.email]}</a></td>
<td><a href={"http://www.inf.ed.ac.uk" :: p.homepage}>homepage</a></td>
</tr>
};
def person_matches(predicate, title, conn) {
<html>
<head><title>{[title]}</title></head>
<body>
<h1>{[title]}</h1>
<table>
{[person_row(p, conn) | p <- table "person" with {id:int, surname:string, firstname:string, homepage:string, email:string}
order [surname:asc] from conn,
predicate(p)]}
</table>
</body>
</html>
};
def list_everyone = person_matches(fun(x)->true, "Everybody");
def queries = [{text="Search by first name", q=fun (name, p) -> (p.firstname == name)},
{text="Search by last name", q=fun (name, p) -> (p.surname == name)},
{text="Search by name", q=fun (name, p) -> (p.firstname == name || p.surname == name)}] ;
def query(conn) {
<html>
<head><title>Who's who in Edinburgh Informatics</title></head>
<body>
<h1>Who's who in Edinburgh Informatics</h1>
<ul>
{[<li>{[text]} :
<form l:action={person_matches(function(arg), "Results", conn)} method="POST">
<input l:name="arg" type="text"/>
<input type="submit"/>
</form>
</li> | {text=text,q=function} <- queries ]}
</ul>
<form l:action={list_everyone(conn)} method="POST">
<input type="submit" value="list everyone"/></form>
</body>
</html>
};
query(database {name="...", host="...", port=..., user="...", pass="..."})