Page 52 - MSDN Magazine, June 2017
P. 52
C#
Make C# More Dynamic
with Hyperlambda
Thomas Hansen
Traditionally, there have been just two types of programming languages: statically compiled languages and dynam- ically interpreted languages. What if there’s actually a third type of programming language, one that fits in neither of these categories and has the potential to make all other languages seem hopelessly rigid in comparison?
Hyperlambda is that language—a Turing-complete execution environment built entirely upon Active Events (see my previous article at msdn.com/magazine/mt795187). Hyperlambda is neither an interpreted language nor a compiled language. It doesn’t even have syntax. Hyperlambda is a non-programming language, perhaps even an anti-programming language. Technically, it’s not even a programming language at all. At its core, Hyperlambda is simply a relational file format that allows you to declare tree structures. Arguably, it has more in common with HTML and XML than with
C# and JavaScript. It turns out, though, that tree structures just hap- pen to be able to describe what we often refer to as execution trees. Execution trees are what your CPU actually executes. All pro- gramming instructions can basically be understood as branches of a tree, which your CPU moves through as it evaluates your code. For instance, an if/else block creates two possible branches that are mutually exclusive, and your CPU chooses only one, depending on the results of the condition in the if statement. Essentially, what your computer does as it executes code is to move through an execution tree, manipulating its memory in the process. This implies that if you can describe an execution tree and manipulate memory, you can also describe anything you’ve previously described using C# and JavaScript.
Everything Is a Tree
Just like everything is a “list” in Lisp, everything is a “tree” in Hyperlambda. Here’s an example of some Hyperlambda pseudo- code that creates an execution tree after being parsed:
if:condition do-x:argument1
else do-y:argument1
Parsing this code results in a lambda object. This lambda object, or execution tree, can be evaluated by invoking the eval Active Event in Phosphorus Five (P5). You can think of an Active Event basically as a “function object” that allows you to invoke a method created in, for instance, C#, with a graph object or a tree object as its only argument. P5 implements the Active Event design pattern.
This article discusses:
• Execution trees and lambda objects • Using and extending Hyperlambda • Modifying the execution tree
• Several use cases
• Creating “Hello World” in Hyperlambda Technologies discussed:
C#, Hyperlambda, Active Events
48 msdn magazine