Page 54 - MSDN Magazine, June 2017
P. 54

equals “Thomas,” it will evaluate the lambda object inside the if node. Otherwise, it will evaluate the lambda object in the else node. A lambda expression can reference any nodes in your tree, and results in a subtree, based upon the original tree. The relationship between a lambda expression and a tree structure is somewhat analogous to the relationship between SQL and a table. Lambda expressions are easily visualized by those who have created XPath expressions. You can compare them to LINQ or “pre-compiled enumerators,” if you wish. The latter is actually how they’re imple- mented. If you believe that building LINQ queries dynamically adds value, purely logically you must believe that lambda expres-
sions might possess value.
Pruning Your Tree
At this point, all that’s needed to have a Turing-complete execu-
tion environment is the ability to change parts of the tree. Here,
I’m doing so with the “set” Active Event:
_input:Thomas _output if:x:/@_input?value
=:Thomas set:x:/@_output?value
src:Yo boss else
set:x:/@_output?value src:Yo stranger
The set Active Event basically works like the assignment operator in C#. At this point, we have a Turing-complete “non-programming language” that allows you to do everything you’re used to doing in a traditional programming language—without ever actually having created a programming language or even having considered syn- tax. Instead, you modify the execution tree directly as the lambda object is evaluated.
One lambda object can transform any other lambda object the same way an XSLT file can transform an XML file.
There are more Active Events you can use to modify your tree. For instance, “add” appends a bunch of nodes to the result of a lambda expression, leading to one or more additional nodes, while “insert- before” and “insert-after” works similarly to add, except that they inject one or more nodes before or after a bunch of nodes. To remove nodes, values, or names is as easy as not supplying a source to set, at which point it will simply remove the node, its value, or its name, depending on what type declaration you use for your expression.
Using constructs like these makes C# a super-dynamic pro- gramming language by giving the programmer the tools needed to be able to change the execution tree directly. Arguably, these traits of Hyperlambda make it the most dynamic programming environment on the planet by far. Even super-dynamic languages, such as Lisp and JavaScript, seem hopelessly static and rigid in comparison to Hyperlambda.
At this point, you might realize that in Hyperlambda, there’s absolutely no difference between data and logic—logic is data and there are no semantic differences at all between the two. This implies that you can just as easily change your logic as you can your data, which, in turn, results in a super-dynamic execution model where your execution tree might completely change during its execution. Just how cool this is can be illustrated with a few highly instructive use cases.
Nurturing Your Tree
Use case 1: Imagine you have 100 records in your database. Each record contains some Hyperlambda. If you wish, you could select all these records, transform them into lambda objects and append them to a destination lambda object, evaluating their combined result afterward. You could even create a new single function object out of these records, persist them to a file on disc and use this file in the same way you’d invoke a function.
Use case 2: If you want, you can evaluate only half of a func- tion, removing the parts of the function you don’t want to execute. As far as I know, no other programming languages on the planet have this capability. It happens to be an extremely useful feature.
Use case 3: You can, if you need to, extract half of the lambda objects from five different functions, creating a single new func- tion derived from the “better parts” of your original functions.
How is this possible? One lambda object can transform any other lambda object the same way an XSLT file can transform an XML file. If you don’t want to execute any while loops in your system, for whatever reason, you can easily create a lambda object that transforms all of your while loops and turns them into for-each loops and have it run in the background as an automated process.
In case you hadn’t realized, this is how HTML works in rela- tionship to its DOM model. In Hyperlambda, modifying lambda objects is as easy as inserting, modifying or deleting an HTML element in your DOM with JavaScript. If you think this capability adds value to HTML, purely logically you must agree that this could potentially add value to “logic.” Hyperlambda opens up a completely new dimension with regard to software development.
Use case 4: Consider the CMS in System42 (bit.ly/2pwMOY9). This CMS allows you to create lambda pages, which instead of simply displaying static HTML, are 100 percent dynamic and interactive in nature. “Big deal,” some might argue, claiming that PHP can at least in theory do the same thing. However, these lambda pages are also reusable components. The dynamic nature of Hyperlambda means you can, for instance, check for the existence of a “parent- widget” argument during the execution of your lambda page and, if it exists, instead of creating a page, you can inject the same page as a user control into another widget on your page.
In fact, you don’t even have to modify your original page; you can instead transform its lambda object before you evaluate its “create-widget” invocation. To categorize things as absolutes the way you’re used to in traditional programming languages is com- pletely meaningless in Hyperlambda.
The result is that every single lambda object you create in Hyper- lambda is also a potentially reusable component you can inject into other parts of your system. This implies that you can incrementally
50 msdn magazine
C#









































































   52   53   54   55   56