On Fri, Jul 17, 2009 at 05:49:23AM -0400, Paul Davis wrote:
> 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;"}

All those fail.

$ curl -X POST -d '{"map":"var x=123;\nfunction(doc) { emit(x,null); }"}' 
http://localhost:5984/mailme/_temp_view
{"error":"compilation_error","reason":"expression does not eval to a function. 
(var x=123;\nfunction(doc) { emit(x,null); })"}
$ curl -X POST -d '{"map":"var x=123; function(doc) { emit(x,null); };"}' 
http://localhost:5984/mailme/_temp_view
{"error":"compilation_error","reason":"expression does not eval to a function. 
(var x=123; function(doc) { emit(x,null); };)"}
$ curl -X POST -d '{"map":"var x=123; var f = function(doc) { emit(x,null); }; 
f;"}' http://localhost:5984/mailme/_temp_view
{"error":"compilation_error","reason":"expression does not eval to a function. 
(var x=123; var f = function(doc) { emit(x,null); }; f;)"}

It's not a biggie, but it was rather annoying that code which I had tested
and was working fine in the js shell, using load("filename.js"), didn't work
when I put it into a map. After some cutting and pasting it turned out that
'var' was the culprit.

Even this doesn't work at the top level in a map definition:

  bar = [...];
  for (var i in bar) { ... }
       ^^^^^

To avoid a global index variable 'i' I ended up doing this:

  bar = [...];
  (function() {
    for (var i in bar) ...
  })();

Regards,

Brian.

Reply via email to