Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 29829 invoked from network); 17 Jul 2009 09:17:41 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 17 Jul 2009 09:17:41 -0000 Received: (qmail 64720 invoked by uid 500); 17 Jul 2009 09:18:45 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 64647 invoked by uid 500); 17 Jul 2009 09:18:45 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 64637 invoked by uid 99); 17 Jul 2009 09:18:45 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Jul 2009 09:18:45 +0000 X-ASF-Spam-Status: No, hits=1.5 required=10.0 tests=NORMAL_HTTP_TO_IP,SPF_PASS,WEIRD_PORT X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of b.candler@pobox.com designates 64.74.157.62 as permitted sender) Received: from [64.74.157.62] (HELO sasl.smtp.pobox.com) (64.74.157.62) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Jul 2009 09:18:35 +0000 Received: from localhost.localdomain (unknown [127.0.0.1]) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTP id C1CF46202 for ; Fri, 17 Jul 2009 05:18:13 -0400 (EDT) Received: from mappit (unknown [80.45.95.114]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTPSA id 466C96201 for ; Fri, 17 Jul 2009 05:18:13 -0400 (EDT) Received: from brian by mappit with local (Exim 4.69) (envelope-from ) id 1MRjZz-0002Tr-G9 for user@couchdb.apache.org; Fri, 17 Jul 2009 10:18:11 +0100 Date: Fri, 17 Jul 2009 10:18:11 +0100 From: Brian Candler To: user@couchdb.apache.org Subject: Why can't I use "var" in map code? Message-ID: <20090717091811.GA9459@uk.tiscali.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.17+20080114 (2008-01-14) X-Pobox-Relay-ID: C10A10F6-72B2-11DE-9FC4-AEF1826986A2-28021239!a-pb-sasl-sd.pobox.com X-Virus-Checked: Checked by ClamAV on apache.org 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.