[erlang-questions] [ANN] SeqBind, Sequential Binding Parse Transformation for Erlang (Experimental)

Loïc Hoguin essen@REDACTED
Mon Jan 16 18:57:25 CET 2012


On 01/16/2012 05:28 PM, Tim Fletcher wrote:
> Ignoring the obtuse function name in the second example, I can't see
> why an "accessor" function should need to return state. So
> hypothetically, if the cowboy_http_req module had an API similar to
> the proplists module, you'd be able to write something like this
> instead:
>
>    Q = cowboy_http_req:get_value(<<"q">>, Request)
>    Id = cowboy_http_req:get_value(<<"id">>, Request)
>
> Again, the problem no longer exists!

The example is a bit wrong as it's not just accessors that return the 
Req (get_value doesn't actually exist) and so you do end up having more 
than one Req in the end when you read the request body or send a reply 
anyway.

Also, accessors return the state because Cowboy doesn't try to parse or 
read anything from the socket if it doesn't have to. That means body, 
query string, cookies and so on aren't parsed until you need them, 
saving resources in the process at the expense of a few more characters 
to write.

-- 
Loïc Hoguin
Erlang Cowboy
Nine Nines



More information about the erlang-questions mailing list