[plt-scheme] Bug in namespace-variable-value

From: Brian Campbell (brian.p.campbell.04 at Alum.Dartmouth.ORG)
Date: Tue Jul 19 18:48:51 EDT 2005

In PLT scheme v203 (and, judging from the source code in SVN, the  
current trunk version has this bug as well), namespace-variable-value  
occasionally fails unexpectedly. I reduced the problem to the  
following test case, although due to the nature of this bug, it may  
not happen on other people's systems.

(define foo #f)
(list (namespace-variable-value 'foo) (namespace-variable-value 'max))

This should return a list of #f and the value of max, but instead  
throws an exception saying that max is unbound.

It looks to me like the problem is in how namespace-variable-value  
handles its arguments; from <http://svn.plt-scheme.org/plt/trunk/src/ 

static Scheme_Object *
namespace_variable_value(int argc, Scheme_Object *argv[])
   Scheme_Object *v, *id = NULL;
   Scheme_Env *genv;
   int use_map;

   if (!SCHEME_SYMBOLP(argv[0]))
     scheme_wrong_type("namespace-variable-value", "symbol", 0, argc,  
   use_map = ((argc > 0) ? SCHEME_TRUEP(argv[1]) : 1);

That should probably say (argc > 1); otherwise, if only one argument  
is passed in, it reads a random value that happens to be true most of  
the time, but is occasionally false, for instance in the case I  
describe above, at least on my system. When use_map is false,  
namespace-variable-value does not look in imported bindings or syntax  
bindings for the value. 

Posted on the users mailing list.