<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Ariel Neisen's blog</title><link>http://weblogs.asp.net/arielneisen/default.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Debug Build: 20510.895)</generator><item><title>Dynamic Languages Support in Silverlight</title><link>http://weblogs.asp.net/arielneisen/archive/2007/10/13/dynamic-languages-support-in-silverlight.aspx</link><pubDate>Sat, 13 Oct 2007 20:59:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:4570795</guid><dc:creator>arieln</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arielneisen/rsscomments.aspx?PostID=4570795</wfw:commentRss><comments>http://weblogs.asp.net/arielneisen/archive/2007/10/13/dynamic-languages-support-in-silverlight.aspx#comments</comments><description>&lt;P&gt;As I've mentioned in &lt;A class="" href="http://weblogs.asp.net/arielneisen/archive/2007/10/07/silverlight-article.aspx" mce_href="http://weblogs.asp.net/arielneisen/archive/2007/10/07/silverlight-article.aspx"&gt;my last post&lt;/A&gt;, I'm posting a chapter of the Silverlight article that we've published. The following is the introduction to the dynamic languages in Silverlight. &lt;/P&gt;
&lt;H1&gt;Dynamic Languages Support in Silverlight &lt;/H1&gt;
&lt;P&gt;One of the most innovative features of Silverlight new version is the Dynamic Languages Support. To start, let's make a brief introduction to this kind of languages, so that we can show some code. &lt;/P&gt;
&lt;H2&gt;Introduction to Dynamic Languages &lt;/H2&gt;
&lt;P&gt;The Dynamic Languages are those that in execution time perform lots of tasks that other languages perform in compilation time. For instance: The typing is, generally, dynamic. This means that in coding and compiling time there may not be an explicit type definition; this operation is performed in execution time. This interesting feature opens lots of possibilities (we can create and modify types and code during the execution of our program). &lt;/P&gt;
&lt;P&gt;We can see the expressive power of this kind of languages. If you are not familiarize with this you may find it a little confusing, but eventually you will be able to program in a very clear and elegant way. &lt;/P&gt;
&lt;P&gt;Some of these languages are Python, Ruby, Smalltalk and JavaScript. They are widely used due to its portability and speed of develop and execute. Just to name a few examples, Google and BitTorrent have lots of its coding in Python. &lt;/P&gt;
&lt;H2&gt;Implementation in Silverlight &lt;/H2&gt;
&lt;P&gt;Silverlight includes a Dynamic Language Runtime (DLR) which is executed above the Common Language Runtime (CLR). Its responsibility is to provide the compiler the functionality to support dynamic languages. Note that the CLR was not modified in this version of the .Net Framework. The DLR is in charge of generating the code, make the dynamic typing and manage the execution environment of the &lt;EM&gt;dynamic&lt;/EM&gt; code blocks. Currently there's support for IronPython (Python's implementation) and IronRuby (Ruby's implementation). There will also support JavaScript (EcmaScript 3.0) and VisualBasic (VBx). &lt;/P&gt;
&lt;P&gt;One of the objectives is to provide interoperability between these languages and also to use others (we could make an implementation of SmallTalk and then integrate it with our applications through the DLR). In addition, it offers the communication with the Framework components. &lt;/P&gt;
&lt;H2&gt;Examples &lt;/H2&gt;
&lt;P&gt;Now that the introduction is over, let's see some code! First of all, we are going to show some examples using IronPython, because is one of the most robust dynamic languages. Besides, the latest version of Visual Studio 2008 offers debugging. It's recommended to have a basic knowledge of IronPython to make the most of the language; anyway we'll see some simple examples. &lt;/P&gt;
&lt;P&gt;A Silverlight application that uses Python has the same components of any other: the CreateSilverlight.js, Silverlight.js y page.xaml files. The difference is that now we'll have a page.xaml.py file, which will contain our Python code. &lt;/P&gt;
&lt;P&gt;First of all let's create the files mentioned above. An error will be raised if we have a code-behind class (ie. page.xaml.cs) and a Python handler (page.xaml.py). If this happens, we'll see a parsing error very unpleasant (AG_E_PARSER_INVALID_XCODE_TAG). It's fixed by deleting the code-behind file and the &lt;SPAN style="FONT-FAMILY: Consolas"&gt;x:Class&lt;/SPAN&gt; tag of the first element in the Xaml file. &lt;/P&gt;
&lt;P&gt;Then we have to state that the page has an event handler that must be executed by the IronPython host. To do this, the first element that we need to add is the &lt;SPAN style="FONT-FAMILY: Consolas"&gt;x:Code&lt;/SPAN&gt;: &lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;&amp;lt;x:Code Source="page.xaml.py" Type="text/ironpython" /&amp;gt; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Doing this we specify the file path and the host that will be used. &lt;/P&gt;
&lt;P&gt;Let's open the .py file. First of all, we'll add the references to the .Net Framework components: &lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;import clr &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;import System &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Now we add a TextBlock with a handler for the &lt;SPAN style="FONT-FAMILY: Consolas"&gt;MouseLeftButtonDown&lt;/SPAN&gt; event: &lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;&amp;lt;TextBlock &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x:Name="text" &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Loaded="OnLoad" &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;MouseLeftButtonDown="OnClick" &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Width="400" &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TextWrapping="Wrap" Text="Example" /&amp;gt; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;At this point we should define the &lt;SPAN style="FONT-FAMILY: Consolas"&gt;OnClick &lt;/SPAN&gt;method, so will write a function in the Python file. Well, let's look at an easy implementation: &lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;def OnLoad(sender, e): &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sender.Text = "Ejemplo" &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;def OnClick(sender, e): &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sender.Text = "Clickeado" &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Where &lt;SPAN style="FONT-FAMILY: Consolas"&gt;sender&lt;/SPAN&gt; is the control that raises the event and &lt;SPAN style="FONT-FAMILY: Consolas"&gt;e &lt;/SPAN&gt;contains the arguments. The only thing that will happen is that the control's text will change, maintaining the user experience offered by Silverlight (executing the event without a postback). &lt;/P&gt;
&lt;P&gt;Other concept to take into account is the utilization of variables. Every IronPython execution environment has a &lt;SPAN style="FONT-FAMILY: Consolas"&gt;globals()&lt;/SPAN&gt; property. It returns a dictionary in which we can store the variables that we want them to have a global scope. For instance: &lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;globals()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#returns the dictionary &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;globals()["a"] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#returns the "a" variable &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;globals()["a"] = 1 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#assigns a 1 to "a" &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Now we can use the global variables in the event handlers: &lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;def OnLoad(sender, e): &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;globals()["cont"] = 0 &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sender.Text = "Example" &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;def OnClick(sender, e): &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;a = globals()["cont"] &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sender.Text = a.ToString() &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;a = a + 1 &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;globals()["cont"] = a &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;And at every click on the TextBox we'll see that its value increments. &lt;/P&gt;
&lt;P&gt;Despite the fact that the examples shown are very simple, we see that we can use the most of the Python features combined with the .Net components: Reflection, Web Services, our classes, and so on. &lt;/P&gt;
&lt;P&gt;Moving on, let's take a look at another IronPython feature: the power to create an execution engine to manage the code execution in runtime. To do this, we must add a reference to the IronPython component: &lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;import IronPython &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;from IronPython.Hosting import PythonEngine &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;In this namespace will find the classes used to implement the Python host functionality. What's interesting is that our applications can use it. First of all we'll invoke it: &lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;py = PythonEngine.CurrentEngine &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;In &lt;SPAN style="FONT-FAMILY: Consolas"&gt;py&lt;/SPAN&gt; we have the engine instance. Then we can use the &lt;SPAN style="FONT-FAMILY: Consolas"&gt;Execute&lt;/SPAN&gt; method to execute in runtime any code that we want. &lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;py.Execute(code, module) &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;To sum up, this is the entire function: &lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;def engineTest(): &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;py = PythonEngine.CurrentEngine &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;py.Execute("text.Text = 'Changed by the engine' ", &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="BACKGROUND: #d9d9d9"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;py.CreateModule("temp")) &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;And now we can create our execution engine, using the one that the Framework provides. &lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=4570795" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/arielneisen/archive/tags/Articles/default.aspx">Articles</category><category domain="http://weblogs.asp.net/arielneisen/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://weblogs.asp.net/arielneisen/archive/tags/.NET/default.aspx">.NET</category></item><item><title>Silverlight Article</title><link>http://weblogs.asp.net/arielneisen/archive/2007/10/07/silverlight-article.aspx</link><pubDate>Mon, 08 Oct 2007 00:52:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:4479786</guid><dc:creator>arieln</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arielneisen/rsscomments.aspx?PostID=4479786</wfw:commentRss><comments>http://weblogs.asp.net/arielneisen/archive/2007/10/07/silverlight-article.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;.Code Magazine has just published an article written by &lt;A class="" href="http://weblogs.asp.net/spano" target=_blank mce_href="http://weblogs.asp.net/spano"&gt;Soledad Pano&lt;/A&gt;, &lt;A class="" href="http://weblogs.shockbyte.com.ar/rodolfof" target=_blank mce_href="http://weblogs.shockbyte.com.ar/rodolfof"&gt;Rodolfo Finochietti&lt;/A&gt;, Federico Garcia and myself about the &lt;A class="" title=Article href="http://www.redusers.com/noticias/code-42" target=_blank mce_href="http://www.redusers.com/noticias/code-42"&gt;Silverlight Technology&lt;/A&gt;&amp;nbsp;as its cover article. The article is written in Spanish; but I'll try to translate and post it so that you can enjoy it.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;IMG title=Cover style="WIDTH: 202px; HEIGHT: 286px" height=286 alt=Cover src="http://www.tectimes.com.ar/noticias/img//tapa-code-42.gif" width=202 align=bottom mce_src="http://www.tectimes.com.ar/noticias/img//tapa-code-42.gif"&gt;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=4479786" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/arielneisen/archive/tags/Orcas/default.aspx">Orcas</category><category domain="http://weblogs.asp.net/arielneisen/archive/tags/Articles/default.aspx">Articles</category><category domain="http://weblogs.asp.net/arielneisen/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>The Start</title><link>http://weblogs.asp.net/arielneisen/archive/2007/09/28/the-start.aspx</link><pubDate>Fri, 28 Sep 2007 18:35:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:4233137</guid><dc:creator>arieln</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/arielneisen/rsscomments.aspx?PostID=4233137</wfw:commentRss><comments>http://weblogs.asp.net/arielneisen/archive/2007/09/28/the-start.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;Hi All,&lt;/P&gt;
&lt;P mce_keep="true"&gt;My name is Ariel Neisen. Since a long time I've wanted to start blogging my technology adventures and misadventures, and when I found out that there were opening some asp.net blog I realized that it was the time to do it. &lt;/P&gt;
&lt;P mce_keep="true"&gt;I live in Buenos Aires, Argentina; where I work as a Technical Leader at Lagash Systems.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Well, that was my introduction. I'll try to blog as&amp;nbsp;frequently as I can; and I hope&amp;nbsp;to hear some of your comments.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=4233137" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/arielneisen/archive/tags/Myself/default.aspx">Myself</category></item></channel></rss>