Odd.
Try one of these:
{"map":"var x=123;\nfunction(doc) { emit(x,null); }"}
{"map":"var x=123; function(doc) { emit(x,null); };"}
{"map":"var x=123; var f = function(doc) { emit(x,null); }; f;"}
On Fri, Jul 17, 2009 at 5:18 AM, Brian Candler<[email protected]> wrote:
> Could somebody explain this subtlety of Javascript to me?
>
> This works fine:
>
> $ curl -X POST -d '{"map":"x=123; function(doc) { emit(x,null); }"}'
> http://127.0.0.1:5984/mailme/_temp_view
> {"total_rows":2,"offset":0,"rows":[
> {"id":"54829ded88644559e6c81a7f482c5800","key":123,"value":null},
> {"id":"ebf1585feb2109429a0cd62528e8ab4b","key":123,"value":null}
> ]}
>
> But this doesn't:
>
> $ curl -X POST -d '{"map":"var x=123; function(doc) { emit(x,null); }"}'
> http://127.0.0.1:5984/mailme/_temp_view
> {"error":"compilation_error","reason":"expression does not eval to a
> function. (var x=123; function(doc) { emit(x,null); })"}
>
> The only difference is the addition of the word 'var'.
>
> (The reason: I'm writing a map function which needs to use a precalculated
> lookup table)
>
> Thanks,
>
> Brian.
>