remove math.blas.syntax and merge parsing words into math.blas.vectors/matrices
[factor/jcg.git] / extra / webapps / calculator / calculator.factor
bloba8c8383e628c3f633e46f1ab7e75f2fb8db4176e
1 ! Copyright (C) 2008, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: furnace furnace.actions furnace.redirection
4 http.server.dispatchers html.forms validators urls accessors
5 math ;
6 IN: webapps.calculator
8 TUPLE: calculator < dispatcher ;
10 : <calculator-action> ( -- action )
11     <page-action>
13     [
14         { { "z" [ [ v-number ] v-optional ] } } validate-params
15     ] >>init
17     { calculator "calculator" } >>template
19     [
20         {
21             { "x" [ v-number ] }
22             { "y" [ v-number ] }
23         } validate-params
25         URL" $calculator" "x" value "y" value + "z" set-query-param
26         <redirect>
27     ] >>submit ;
29 : <calculator> ( -- responder )
30     calculator new-dispatcher
31         <calculator-action> >>default ;
33 ! Deployment example
34 USING: db.sqlite furnace.alloy namespaces http.server ;
36 : calculator-db ( -- db ) "calculator.db" <sqlite-db> ;
38 : run-calculator ( -- )
39     <calculator>
40         calculator-db <alloy>
41         main-responder set-global
42     8080 httpd ;
44 MAIN: run-calculator