O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Pro DLR in .NET 4

Book Description

Dynamic Language Runtime (DLR) in .NET is a framework for designing and interacting with dynamic languages such as Python and Ruby. For the first time, the DLR places such languages on an equal footing in the .NET world with compiled languages such as C# and VB.NET. Chaur Wu's book, Pro DLR in .NET 4, introduces you to this important new framework, helping you to take practical advantage of the DLR in your day-to-day work.

Pro DLR in .NET 4 begins with the fundamentals of the DLR, showing how they work to provide interoperability support for dynamic languages. You'll learn to mix and match objects and functions from compiled and dynamic languages such as C# and Python, allowing you to take advantage of the right tool at the right time for the right task.

The DLR also brings new flexibility and possibility to your software application design. Pro DLR in .NET 4 shows you how to host dynamic languages in your application, enabling users to write scripts to automate tasks. You'll understand the meta-object protocol and meta-programming capabilities. These reside at the core of DLR, bringing new possibilities to the design and architecture of .NET applications.

  • Comprehensive coverage of an important new .NET technology

  • Meets the needs of programmers wanting to apply dynamic languages such as Python and Ruby in their .NET solutions

  • Assists language developers in supporting their languages under .NET.

Table of Contents

  1. Cover Page
  2. Title Page
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. About the Author
  8. About the Technical Reviewer
  9. Acknowledgments
  10. Introduction
    1. Prerequisites
    2. Structure of the Book (or How this Book is Organized…)
    3. Obtaining the Source Code
  11. PART 1: DLR Fundamentals
    1. CHAPTER 1: Introduction to DLR
      1. Setting Up Code Examples
        1. Software Requirements
        2. Installing the DLR, IronPython, and IronRuby
      2. Hello World Examples
      3. Hello World from a Dynamic Language
      4. Creating a “Hello” Language
      5. Implementing REPL for the Hello Language
      6. Practical Uses for the DLR
        1. Application Scripting and DSL
        2. XML Builder
        3. Aspect-Oriented Programming
      7. Runtime
        1. Runtime vs. Run Time
        2. Run Time vs. Compile Time
      8. Dynamic vs. Static
        1. Dynamic Typing
        2. Dynamic Dispatch
      9. Language
      10. Programming Languages in Practice
      11. Putting It Together
      12. Summary
    2. CHAPTER 2: DLR Expression
      1. DLR Expression as a Language
        1. Code as Data  
        2. A Common Denominator like CLR
        3. Concrete Syntax and Serialization
      2. Expressions vs. Statements
      3. Expression Type and Kind
      4. Binary Expressions
      5. Flow Control Expressions
        1. If-Then-Else Expressions
        2. Switch Expressions
      6. Scopes and Name Binding
        1. Lexical vs. Dynamic Scope
        2. BlockExpression and Lexical Scoping
      7. Lambda Expressions and Closure
      8. The GotoExpression Class
      9. While Loops
      10. Dynamic Expressions
      11. Index Expressions
      12. Expression Abstraction, Reduction and Extension
      13. Immutability and the Visitor Pattern
        1. Visitor Pattern in General
        2. Visitor Pattern in DLR Expression
        3. Expression Visitor Examples
      14. Summary
    3. CHAPTER 3: Late Binding and Caching
      1. Binding
      2. Call Sites and Early Binding
      3. Call Sites and Late Binding
      4. DLR Binders
      5. Set Up Code Examples
        1. Making a Debug Build of the DLR for .NET 2.0
        2. Developing for Both .NET 2.0 and .NET 4.0
      6. The CallSiteBinder Class
      7. DLR Call Sites
      8. Binding Restrictions and Rules
      9. Checking Binding Rules in Debug Mode
      10. Caching
        1. Three Cache Levels
        2. Late-Binding Context
        3. L0 Cache Example
        4. L1 Cache Example
        5. L2 Cache Example
      11. Creating Canonical Binders
      12. Summary
    4. CHAPTER 4: Late Binding and Interoperability
      1. Language Interoperability
      2. Static and Dynamic Objects
      3. Late-Binding Logic in Two Places
        1. Late Binding Logic in Binders
        2. Late-Binding Logic in Dynamic Objects
      4. Late-Bound Actions
        1. Examples
        2. Common Type System
        3. Class Hierarchy of Binders
      5. Implement a Custom Binder Class
      6. Interoperability Protocol
      7. Summary
    5. CHAPTER 5: Dynamic Objects
      1. What is a Dynamic Object?
      2. IDynamicMetaObjectProvider Interface
      3. Dynamic Meta Objects
        1. DynamicMetaObject and Binding Logic
        2. DynamicMetaObject and Binding Result
      4. Interoperability
      5. DynamicObject Class
      6. XML Builder
      7. Summary
    6. CHAPTER 6: DLR Hosting API
      1. Life Without the DLR Hosting API
        1. Using a Static Language’s Code in Another Static Language
        2. Using a Static Language’s Code in a Dynamic Language
        3. Using a Dynamic Language’s Code in a Static Language
        4. Using a Dynamic Language’s Code in Another Dynamic Language
      2. Overview of the DLR Hosting API
        1. Major Classes in the API
        2. The Tale of Two APIs
        3. The DLR Hosting API in Relation to Binders and Dynamic Objects
      3. Using Script Runtime to Execute Code
      4. Configuring the Languages You Want to Speak
        1. Configuring Script Runtime Declaratively
        2. Configuring Script Runtime Programmatically
      5. Scripting an Object Model
      6. Script Scopes
      7. Value and Reference Variables
        1. Global Scope and Variable Passing
        2. Language Neutral Scope and Variable Passing
      8. Level Two Use of the DLR Hosting API
        1. Compiling Code
        2. Loading Assemblies into Script Runtime
        3. Creating Python Class Instances Using Object Operations
      9. Level Three Use of the DLR Hosting API
        1. Script Host
        2. Object Operations
        3. Remote Script Runtime
      10. .NET Remoting Quick Tour
      11. Running Script Runtime in a Separate Process
      12. Summary
  12. PART 2: Applying the DLR
    1. CHAPTER 7: DLR and Aspect-Oriented Programming
      1. Aspect-Oriented Programming
        1. Cross-Cutting Concerns
        2. Advice, Join Points, and Pointcuts
        3. An Example
        4. A Test Run
      2. AOP for Dynamic Objects
        1. Understanding the Framework
        2. Implementing the Framework
      3. Integration with Spring.NET AOP
        1. Getting the AOP Advisors
        2. Implementing Advice
        3. Applying Advice
        4. Cutting Across Dynamic and Static Objects
      4. Summary
    2. CHAPTER 8: Metaprogramming
      1. Overview of Metaprogramming
      2. Changing Class Definitions
        1. Ruby
        2. Python
        3. DLR
      3. LINQ Query Provider
        1. Understanding the End Goal
        2. Implementing the Query Class
        3. Implementing the QueryProvider Class
        4. Implementing QueryExpressionVisitor
      4. Data Access
        1. Static Data Access
        2. Dynamic Data Access
        3. Generated Data Access
      5. Summary
    3. CHAPTER 9: Stitch — A DSL for Hosting Languages
      1. The Need for Stitch
      2. Syntax of the Stitch Language
      3. Requirements for the Example
        1. Software Requirements
        2. Organization of the Code
      4. Stitch in Use
        1. Being Declarative
        2. Hosting DLR- and Non-DLR-Based Languages
        3. Hosting Stitch Itself
        4. Executing in Parallel
      5. Stitch Language Grammar
        1. Setting Up Eclipse and ANTLR
        2. Defining the Grammar
        3. Test-Driving the Grammar
      6. The Stitch Runtime
        1. Overview of the Runtime
        2. The Script Engine
        3. Function Execution Coordinator
        4. Parallel Extensions for .NET
        5. Script Runner
      7. Running DLR-based Language Code
      8. Language Plug-In
        1. Develop a Stitch Plug-In for PowerShell
        2. Configuring a Plug-In
      9. Summary
    4. CHAPTER 10: Application Scripting
      1. Ball World
      2. Software Requirements
      3. Application Architecture
      4. Application Object Model
      5. Application Scripting
      6. The Physics Engine
      7. User Interface
      8. Summary
    5. CHAPTER 11: DLR in Silverlight
      1. Different Client Side Web Scripting Approaches
      2. Apache HTTP Server Configurations
      3. Using the Hosted Gestalt Components
      4. Hosting the Gestalt Components
      5. Dissecting the Gestalt Components
      6. Scripting HTML
      7. Scripting XAML
      8. DLR Settings
      9. Speak Your Own Language in Silverlight
        1. Software Requirements
        2. Build DLR for Silverlight
      10. The Hello Language
      11. Hello Console in Silverlight
      12. Gestalt-like Hello Console on Silverlight
      13. Summary
    6. CHAPTER 12: Dynamic Languages on JVM
      1. Quick Comparisons
      2. Python and Ruby on JVM
        1. Hosting Python Code in Java Programs
        2. Hosting Ruby Code in Java Programs
      3. Overview of the BoolScript Example
      4. BoolScript Language
      5. Script Engine Factory
      6. Script Engine Discovery Mechanism
      7. Bindings, Scope, and Context
      8. BoolScript Engine
      9. Compile BoolScript Code
      10. Run BoolScript Code as Invocable Function
      11. Summary
  13. Index