Scopes are intended for the language-implementation side of things. Languages like Ruby and Javascript support nested lexical scoping but Python does not. Even if we were to expose a mechanism in the hosting API that let you create ScriptScopes which reference nested Scopes, there's no guarantee that Python's name resolution would automatically work with this.<div>
<br></div><div>You shouldn't need to define your own implementation of IAttributesCollection. Can't you just use the SymbolDictionary defined in Microsoft.Scripting and fill it manually?<br><br><div class="gmail_quote">
On Tue, Jan 6, 2009 at 12:07 PM, Caspar Lessing <span dir="ltr"><<a href="mailto:caspar.lessing@gmail.com">caspar.lessing@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
You are right, it is basically a "from pricy_scope import *" for each one of my local scopes.<br><br>I considered doing that, but decided against it as I'm really loathe to copy the context a whole bunch of times. The number of symbols _should_ not be excessive but the pricy_scope setup script is configuration and eventually could have a fair amount of symbols. The number of local contexts however will be fairly high. Thousands to 10s of thousands. So copying gets multiplied by that. So I am trying hard not do the copying thing.<br>
<br>However the Scope Parent mechanism is perfectly suited for wat I need. So I was hoping I could use that which means no copying required.<div><div></div><div class="Wj3C7c"><br><br><br><div class="gmail_quote">On Tue, Jan 6, 2009 at 4:56 PM, Curt Hagenlocher <span dir="ltr"><<a href="mailto:curt@hagenlocher.org" target="_blank">curt@hagenlocher.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left:1px solid rgb(204, 204, 204);margin:0pt 0pt 0pt 0.8ex;padding-left:1ex">How many symbols are there in this shared global context? Can't you just initialize them in one ScriptScope and then copy the symbols into the other ScriptScopes where you want to use them? This would be analogous to saying "from pricy_scope import *" at the beginning of each module.<br>
<br>
<div class="gmail_quote"><div><div></div><div>On Tue, Jan 6, 2009 at 5:58 AM, Caspar Lessing <span dir="ltr"><<a href="mailto:caspar.lessing@gmail.com" target="_blank">caspar.lessing@gmail.com</a>></span> wrote:<br>
</div></div><blockquote style="border-left:1px solid rgb(204, 204, 204);margin:0px 0px 0px 0.8ex;padding-left:1ex" class="gmail_quote"><div><div></div><div>Hello People<br><br>I use an embedded instance of IronPython.<br>
My program spends effort to create a global context. It then continues to to execute statements inside a local context which need resolve the items in the global context as well. Think of python functions' local context and its interaction with the module context.<br>
<br>In an older version of IronPython I had a EngineModule which I used for my global context and I could use a Dictionary<string,object> for my locals.<br><br>This allowed my to do the following:<br><br>PythonEngine pe = new PythonEngine();<br>
Context = pe.CreateModule();<br>pe.Execute(ExpensiveGlobalSetupScript,Context);<br>Dictionary<string,object>[] locals = new Dictionary<string,object>[ScriptList.Length];<br>for(int i = 0; i < ScriptList.Length; i++)<br>
{<br> locals[i] = new Dictionary<string,object>()<br> pe.Execute(ScriptList[i], Context, locals[i]);<br>}<br><br>I am having trouble doing something similar with ScriptScope. I have explored some avenues:<br>1. Copying the global context into each local one. It seems too expensive. Possibly it is only the cloning of some form of dictionary, but still.<br>
2. Implementing a new CustomSymbolDictionary and overriding TryGetExtraValue. Problem is that it is called before trying to resolve symbols internally (Which leads to globals being resolved rather than locals)<br>3. Creating my own implementation of IAttributesCollection (Seemed too complex after discovering the Parent mechanism in Scope)<br>
<br>I eventually found the Parent mechanism inside Scope. However I do not have access to create a new ScriptScope (Internal constructor) based on a Parent Scope.<br>I had to create a new Factory method inside ScriptEngine which looks as follows:<br>
<br> public sealed class ScriptEngine<br> {<br> .....<br> public ScriptScope CreateScope(ScriptScope parent)<br> {<br> ContractUtils.RequiresNotNull(parent, "parent");<br> return new ScriptScope(this, new Scope(parent.Scope,null));<br>
}<br> ....<br> }<br><br>My question if whether this is a sensible addition to ScriptEngine or am I missing something?<br><br>Much appreciated<br>Caz<br><br></div></div>_______________________________________________<br>
Users mailing list<br><a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br><a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br></blockquote></div><br>
<br>_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br></blockquote></div><br>
</div></div><br>_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br></blockquote></div><br></div>