[plt-scheme] Using symbols, introduced with namespace-attach-module, in an emb edding application

From: Khorev Sergey (Khorev at SoftLab.RU)
Date: Mon Dec 15 03:44:35 EST 2003

It seems, that symbols, introduced with namespace-attach-module, couldn't be
used directly in scheme_eval_string, but must be used with
scheme_eval_string("(eval '...)", ...).
Is this behaviour by design?
The testing program is below:

#include <scheme.h>

Scheme_Env *basic = NULL;
Scheme_Env *ns = NULL;

    static Scheme_Object *
prim1(int noargc, Scheme_Object **noargv)
{
    return scheme_make_string("qqqq");
}

int main()
{
    Scheme_Env	*mymod;
    
    scheme_set_stack_base(NULL, 1);

    basic = scheme_basic_env();
    
    MZ_REGISTER_STATIC(basic);
    MZ_REGISTER_STATIC(ns);

    /* define module mymod containing prim1 */
    mymod = scheme_primitive_module(scheme_intern_symbol("mymod"), basic);
    scheme_add_global("prim1", scheme_make_prim_w_arity(prim1, "prim1", 0,
0), mymod);
    scheme_finish_primitive_module(mymod);

    /* make namespace ns. To access basic namespace, define global basic */
    ns = (Scheme_Env *)scheme_make_namespace(0, NULL);
    scheme_add_global("basic", (Scheme_Object *)basic, ns);

    scheme_eval_string("(require mymod)", basic);
    if (scheme_equal(scheme_eval_string("(prim1)", basic),
scheme_make_string("qqqq")))
	printf("prim1 in basic can be called\n");
    scheme_eval_string("(namespace-attach-module basic 'mymod)", ns);
    if (SCHEME_TRUEP(scheme_eval_string("(memq 'prim1
(namespace-mapped-symbols))", ns)))
	printf("Symbol prim1 in namespace ns is defined\n");

    /* This will fail with undefined identifier:
    scheme_eval_string("(prim1)", ns); 
    */
    /* This will fail too: 
    scheme_eval_string("(require mymod)", ns);
    */
    /* And this too:
    scheme_eval_string("(namespace-require 'mymod)", ns);
    scheme_eval_string("(prim1)", ns);
    */
    /* This works but looks strange...*/
    if (scheme_equal(scheme_eval_string("(eval '(prim1))", ns),
scheme_make_string("qqqq")))
    	printf("evaluated successfully\n"); 

    return 0;
}

-- 
Sergey Khorev
http://iamphet.nm.ru
Thank you, good sir, I owe you one.
 -- George Colman, the Younger (1762-1836)
 -- The Poor Gentleman, Act i, Sc. 2



Posted on the users mailing list.