MSDN Magazine - February 2008 - (Page 19) Dynamic Languages and Silverlight Jimmy Schementi C hildren learn through creative playing. From LEGO to GI Joe and Barbie (they were my sister’s, I swear), children tend to pick up toys and intuitively do something with them; they don’t pick up the manual and read it, at least not for the purpose of understanding the toy! It’s human nature to experiment and play with things to understand them, especially as a child when the “right way to do things” isn’t burned into your brain. Such a hands-on approach is arguably one of the best ways to learn. Applying that same idea to software, dynamic languages are traditionally associated with an interactive environment, giving you a run-evaluate-print loop (REPL), and allowing for an explorative trial-and-error approach to programming. In a sense, the REPL approach is a way of turning programming into playing. This is why dynamic language advocates often say, “You just have to play with it.” When my team was integrating dynamic languages into Silverlight™, we immediately wanted to be able to play with Silverlight. Through some clever programming by Jim Hugunin, DLRConsole was born. This column will explore how DLRConsole works, and in turn discuss IronPython, DLR Hosting, and the DLR’s integration with Silverlight. Getting DLRConsole But before digging into DLRConsole, perhaps I should bring you up to speed on the Dynamic Language Runtime (DLR), a dynamic language support system that sits on top of the CLR and provides language services required by most dynamic language implementations. These services include a dynamic type system, dynamic method dispatching, dynamic code generation, and hostDLRConsole is a Silverlight ing APIs. For more infor1.1 sample that enables mation on the DLR, check out Jim Hugunin’s blog post you to edit and run XAML at blogs.msdn.com/hugunin/ and Python code. archive/2007/04/30/a-dynamiclanguage-runtime-dlr.aspx. Figure 1 Opening DLRConsole DLRConsole is a Silverlight 1.1 sample that demonstrates a very lightweight code development and experimentation tool. (Please note that as of January 1, 2008 Silverlight 1.1 was renamed Silverlight 2.0.) It enables you to edit and run XAML and Python code and also to experiment with Python and JScript® in an interactive editor that supports code coloring and completion. DLRConsole exercises the DLR’s integration with Silverlight in two ways. First, it is a Silverlight application written in the DLR-compliant language, IronPython. Secondly, it utilizes the DLR hosting APIs to run the DLR code typed into the console and editor. You can download the DLRConsole code to run locally from silverlight.net/Samples/1.1/ DLR-Console/DLRConsole.zip. If you just want to use DLRConsole interactively, go to silverlight.net/Samples/1.1/DLR-Console/python for a hosted version. To run DLRConsole, you must have Silverlight installed on your machine. Running DLRConsole without Silverlight installed will prompt you with a link to download it, but if you’d like to install it ahead of time for Windows® or Apple platforms go to microsoft.com/silverlight/ install.aspx. If you are running a Linux-based OS, check out Mono’s Moonlight project, an implementation of Silverlight for Linux, at mono-project.com/Moonlight. february2008 19 http://blogs.msdn.com/hugunin/archive/2007/04/30/a-dynamiclanguage-runtime-dlr.aspx http://blogs.msdn.com/hugunin/archive/2007/04/30/a-dynamiclanguage-runtime-dlr.aspx http://blogs.msdn.com/hugunin/archive/2007/04/30/a-dynamiclanguage-runtime-dlr.aspx http://silverlight.net/Samples/1.1/DLR-Console/DLRConsole.zip http://silverlight.net/Samples/1.1/DLR-Console/DLRConsole.zip http://silverlight.net/Samples/1.1/DLR-Console/python http://silverlight.net/Samples/1.1/DLR-Console/python http://microsoft.com/silverlight/install.aspx http://microsoft.com/silverlight/install.aspx http://mono-project.com/Moonlight
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.