A first use case, for discussion, involves enhancing the inspectability and explainability of computer programs.
The following examples explore the scenario where a developer implements a guard section for a function, to check parameters before proceeding to other computation. Below, the variables r1
, r2
, and r3
are not simply Booleans, but are objects with two properties: value
, which is a simple Boolean, and explanation
, which could be or utilize an abstract syntax tree or expression tree.
function foo(x, y)
{
var r1 = reasoning.assert(1+1, 2);
var r2 = reasoning.assert(x.length, 3);
var r3 = reasoning.assert(y, 1);
if(r1.value && r2.value && r3.value)
{
// ...
}
return reasoning.and(r1, r2, r3);
}
In the above example, the result of the expression x.length
is provided to the assert
function, and the expression itself is unavailable.
With a quote()
keyword, one could enhance the inspectability of the results of these assertions, as the following sketch intends to show:
function foo(x, y)
{
var r1 = reasoning.assert(1+1, 2, quote(1+1), quote(2));
var r2 = reasoning.assert(x.length, 3, quote(x.length), quote(3));
var r3 = reasoning.assert(y, 1, quote(y), quote(1));
if(r1.value && r2.value && r3.value)
{
// ...
}
return reasoning.and(r1, r2, r3);
}
If one desired to utilize the runtime evaluation of abstract syntax trees and expression trees, one could design the above scenario to, instead, more succinctly resemble:
function foo(x, y)
{
var r1 = reasoning.assert(quote(1+1), quote(2));
var r2 = reasoning.assert(quote(x.length), quote(3));
var r3 = reasoning.assert(quote(y), quote(1));
if(r1.value && r2.value && r3.value)
{
// ...
}
return reasoning.and(r1, r2, r3);
}
So, if one or more assertions should fail in the called function, foo
, a calling function could inspect its result's explanation
property, utilizing abstract syntax trees or expression trees, to process why. A developer could also print and view a string from such a tree to examine a situation, e.g., while debugging.
This first use case is a general-purpose one which sketches, and hopefully illustrates, how a quote()
keyword could be used to enhance the inspectability and explainability of computer programs.
There are also other use cases to consider, some interesting ones involving lambda expressions.
What do you think of this first use case?