view said.rhope @ 75:0083b2f7b3c7

Partially working implementation of List. Modified build scripts to allow use of other compilers. Fixed some bugs involving method implementations on different types returning different numbers of outputs. Added Fold to the 'builtins' in the comipler.
author Mike Pavone <pavone@retrodev.com>
date Tue, 06 Jul 2010 07:52:59 -0400
parents 76568becd6d6
children f3686f60985d
line wrap: on
line source

/*
	This program implements Paul Graham's "Arc Challenge"
	While I think the Arc Challenge is a little silly, it does provide a simple 
	example of how to use the web framework I whipped up for the Rhope blog
*/

//The Import keyword causes another Rhope source file to be included
//Here we import the Rhope web framework
Import framework.rhope

//Here we define an event handler that will get called when the user clicks the button
//Event handlers get passed the current page tree and an event object
Save Text[page,event:out]
{
	//First we store the value from the text box in a session variable
	out <- [[[page]Set["said",[[page]Get Child By Name["foo"]]Value >>]
	//Then we empty the page object
	]Clear Children
	//And we add a hyperlink
	]Add Child[New@Web Link["Click Here","/said"]]
}

//This worker defines our page
Said[page,query:out]
{
	//Here we try to retrieve the session variable "said"
	[page]Index["said"]
	{
		//If it's present we display it on the page
		out <- [page]Add Child[ ["You said: "]Append[~] ]
	}{
		//Otherwise we provide them with a form to enter a word
		out <- [[[page]Add Child[New@Web Field["foo","","text"]]
			]Add Child[
				New@Web Button["blah","Click!"]
			//The Set Handler call here attaches the worker Save Text to the click event for the page
			//Events propagate can propagate themselves up the page hierarchy and handled wherever appropriate
			]]Set Handler["click","Save Text"]
	}
}

Main[]
{
	//Start Web starts the webserver and initializes the web framework
	Start Web[
		//It takes a dictionary mapping paths to Workers that define dynamic pages
		//Rather than just passing the name of the Worker, we're passing a List of info
		//that allows the framework to take care of some of the drudgework for us
		//The first element in the list is the worker name, the second the page title 
		//and the third element indicates whether this page will be using session data or not
		[New@Dictionary[]]Set["/said",("Said","That's what she said",Yes)]
	]
}