A place for the startup ecosystem around Chennai
%% handle(Path, Method)What the above code does is to return "not a resource" if you call the handle function with the path parameter as "/" and any method. If you call handle with any path and method parameter as "GET" then it calls retrieve_resource(Path) and so on.
handle("/", _) ->
not_a_resource;
handle(Path, 'PUT') ->
create_new_resource(Path);
handle(Path, 'POST') ->
update_resource(Path);
handle(Path, 'GET') ->
retrieve_resource(Path);
handle(_, _) ->
invalid_request.
>>> from peak.rules import abstract, whenHere is what is happening:
>>> from prioritized_methods import prioritized_when
>>> @abstract()
... def handle(path, method):
... pass
...
>>> @prioritized_when(handle, "path == '/'", prio=1)
... def not_a_resource(path, method):
... print "not a resource"
...
>>> @when(handle, "method == 'GET'")
... def get_resource(path, method):
... print "getting", path
...
>>> @when(handle, "method == 'PUT'")
... def create_resource(path, method):
... print "creating", path
...
>>> @when(handle, "method == 'POST'")
... def update_resource(path, method):
... print "updating", path
...
>>> @when(handle, "method == 'GET'")This defines one implementation for the handle function. It says, when the handle function is called, and the condition given is True (in this case method == "GET"), then call the implementation given below (here: the get_resource function).
... def get_resource(path, method):
... print "getting", path
...
>>> handle("/", "GET")
not a resource
>>> handle("/", "POST")
not a resource
>>> handle("/home", "PUT")
creating /home
>>> handle("/home", "POST")
updating /home
>>> handle("/home", "GET")
getting /home
Pretty cool! The best part of this is that you can dispatch on virtually any condition. While the resulting code is a little more verbose than the Erlang example, its not too bad and it does the job well.I attended a seminar this evening presented by one of our largest banks (name not mentioned to protect some friendships). A middle manager introduced Eugene White, an economist from Rutgers. “I earned nothing last year,” said the hard-working bank employee. “Zero for 2008. No bonus. No options. No stock.”
Over dessert and coffee I asked one of the guy’s subordinates if the boss wouldn’t also have gotten some sort of base salary. “Sure,” he replied, “but maybe as low as $500,000 per year.” How did that round to zero? “Well, he might have made $12 million the year before.”
And you thought Peano arithmetic was challenging….

Posted on February 3, 2009 at 2:24pm —
Posted on July 25, 2008 at 10:06am — 3 Comments
Posted on September 3, 2007 at 9:34am — 1 Comment
Posted on August 28, 2007 at 1:11pm —
Posted on August 13, 2007 at 10:35am — 2 Comments

© 2009 Created by Siddharta Govindaraj on Ning. Create Your Own Social Network