annotate said.rhope @ 168:d2b941f82d74

Fix type of list constants in inference pass and return type of some Array related workers
author Mike Pavone <pavone@retrodev.com>
date Sun, 01 May 2011 18:41:17 -0700
parents f582fd6c75ee
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1 /*
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
2 This program implements Paul Graham's "Arc Challenge"
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
3 While I think the Arc Challenge is a little silly, it does provide a simple
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
4 example of how to use the web framework I whipped up for the Rhope blog
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
5 */
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
6
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
7 //The Import keyword causes another Rhope source file to be included
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
8 //Here we import the Rhope web framework
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
9 Import framework.rhope
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
10
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
11 //Here we define an event handler that will get called when the user clicks the button
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
12 //Event handlers get passed the current page tree and an event object
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
13 Save Text[page,event:out]
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
14 {
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
15 //First we store the value from the text box in a session variable
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
16 out <- [[[page]Set["said",[[page]Get Child By Name["foo"]]Value >>]
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
17 //Then we empty the page object
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
18 ]Clear Children
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
19 //And we add a hyperlink
147
f3686f60985d Sort of working port of framework. Transaction bug seems to be getting in the way. Going to work around, but want the old version in the repo so I can test later.
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
20 ]Add Child[Web Link["Click Here","/said"]]
0
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
21 }
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
22
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
23 //This worker defines our page
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
24 Said[page,query:out]
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
25 {
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
26 //Here we try to retrieve the session variable "said"
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
27 [page]Index["said"]
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
28 {
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
29 //If it's present we display it on the page
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
30 out <- [page]Add Child[ ["You said: "]Append[~] ]
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
31 }{
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
32 //Otherwise we provide them with a form to enter a word
147
f3686f60985d Sort of working port of framework. Transaction bug seems to be getting in the way. Going to work around, but want the old version in the repo so I can test later.
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
33 out <- [[[page]Add Child[Web Field["foo","","text"]]
0
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
34 ]Add Child[
147
f3686f60985d Sort of working port of framework. Transaction bug seems to be getting in the way. Going to work around, but want the old version in the repo so I can test later.
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
35 Web Button["blah","Click!"]
0
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
36 //The Set Handler call here attaches the worker Save Text to the click event for the page
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
37 //Events propagate can propagate themselves up the page hierarchy and handled wherever appropriate
148
f582fd6c75ee Fixed framework port, works for said.rhope example
Mike Pavone <pavone@retrodev.com>
parents: 147
diff changeset
38 ]]Set Handler["click",Save Text[?]]
0
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
39 }
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
40 }
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
41
147
f3686f60985d Sort of working port of framework. Transaction bug seems to be getting in the way. Going to work around, but want the old version in the repo so I can test later.
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
42 Main[args]
0
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
43 {
147
f3686f60985d Sort of working port of framework. Transaction bug seems to be getting in the way. Going to work around, but want the old version in the repo so I can test later.
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
44 [args]Index[1]
f3686f60985d Sort of working port of framework. Transaction bug seems to be getting in the way. Going to work around, but want the old version in the repo so I can test later.
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
45 { port <- Int32[~] }
f3686f60985d Sort of working port of framework. Transaction bug seems to be getting in the way. Going to work around, but want the old version in the repo so I can test later.
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
46 { port <- Val[80] }
0
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
47 //Start Web starts the webserver and initializes the web framework
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
48 Start Web[
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
49 //It takes a dictionary mapping paths to Workers that define dynamic pages
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
50 //Rather than just passing the name of the Worker, we're passing a List of info
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
51 //that allows the framework to take care of some of the drudgework for us
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
52 //The first element in the list is the worker name, the second the page title
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
53 //and the third element indicates whether this page will be using session data or not
147
f3686f60985d Sort of working port of framework. Transaction bug seems to be getting in the way. Going to work around, but want the old version in the repo so I can test later.
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
54 [Dictionary[]]Set["/said",[(0,"That's what she said",Yes)]Set[0,Said[?]]], port
0
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
55 ]
76568becd6d6 Rhope Alpha 2a source import
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
56 }