metacall()()()™ + project Euler

metacall, at last!


I shall use a simple form of metacall to create a better solution that will be resilient to change, but in the same time non-intrusive.

Which means: Not getting in the way of the solution of the original problem. This is very important quality for every architectural pattern to be adopted. Let us at last, dive into metacall usage.

This is now more usable. And rather more elegant too. One can ‘stream’ in any number of call’s to compute sum_n(), and then show the accumulated result by using a callback. And of course, implementation might change in any direction without affecting the usage. We could, for example, implement sending input to server, in next version. Above is trivial to implement.

But why stop here?

We are basing our design on a metacall idiom and our solution is thus ultimately changeable. And somehow strangely monadic in nature too.

There is a real possibility, not just a hint, of being able to easily compose new solution form atomic particles of logic. Above initial “sketch”, I could extend to have something like “tool-bench”, for the whole expandable family of similar solutions to “Euler-ian” problems.

Here we have an euler_bench(), metacall based, mediator pattern, which saves results of solutions to two problems, and shows the current result when required.

An argument to euler_bench(), is an id of the result data-set for managing the state of the solution so that we can instantiate and use one or more euler_bench( id ), in the same time in the same scope.

Non-trivial Territory

For this last “release” to work, we would have to implement “behind” few non-trivial state management mechanisms. For example each solution function, like .e.g. sum_n(), would have to emit the result to separate “result stack”. One result-stack for one euler-ian solution. otherwise final expressions will not work, since they will use results from disparate solutions.

And, as above, all this named result stacks will have to be clustered under one id, like “id01” in the example above. For this to work I will have the each solution function (aka: fundamental indivisible particle of logic) return an array of values so that calling mechanism can record its results properly associated with the worker who made it and its input parameters.

Also. Callbacks we send, can be used to control the behavior of the solution “behind”. For example, we can have a callback that will erase the current result data-set, callback that will send the current result data-set to server, another one that can record the time passed, etc. But, all of these will not change the callers experience at all. If properly micro-designed metacall based interfacing mechanism stays intact.

Onto the next page more usage and hopefully some  helpful thinking.