Ctadel: Programming Form Handlers

Here is the source of the derivative calculator:

include html, mkcgi, diff.                                % include Ctadel packa ges
form_handler_site := "http://www.cs.fsu.edu/~engelen".    % the form handler site
this_file := substring(file, 1, length(file)-2) where file = seeing_file.
form_handler := form_handler_site // "/" // this_file // ".cgi".
main := proc(local (f, x);  % f is a function and x a coordinate
        html_tth`on;        % use TtH to convert and display LaTeX math in HTML
        output_html(
        [       html_reply, html_start, html_title("Derive"),
                html_body(["background"="canvas.gif" | html_appearance], []),
                html_h1("Derive: a simple derivative calculator")
        ]);
        f := restricted_evaluate(eval(atom_to_term(html_form_value("f"))));
        x := restricted_evaluate(eval(atom_to_term(html_form_value("x"))));
        if x <@> "" and f <@> "" then
                output_html([html_center_math(df(f,x)=diff(f,x)), "Try",
                             html_ref(form_handler, "another")
                ])
        else    output_html(
                [       html_form(form_handler,
                        [       "Complete the derivative:",
                                html_center_math({df("f"?=5, "x"?=["x","y","z"])
}),
                                html_submit("Compute!")
                        ])
                ]);
        output_html([html__body, html_end]);
        halt                                     % exit CGI
).

Next


File translated from TEX by TTH, version 2.21.
On 7 Oct 1999, 14:08.