Boost logo

Boost :

From: Brian Davis (bitminer_at_[hidden])
Date: 2008-07-27 01:06:25


>
>
>> [snip]
> In this thread, there's frequent mention of domains, and groups of
> related types and transformations between domains. Thes phrases
> remind me of proto's transformations:
>
>
> http://boost-sandbox.sourceforge.net/libs/proto/doc/html/boost_proto/users_guide/expression_transformation.html
>
> is there any chance proto could be used?
>

Yes it appears proto with the syntax of

(_1 + 3)
(_2 - _1) / _2 * 100

could be used. This format seemingly provides a simple syntax for the
programmer. My example only called pairwise non MPL transformation
functions which the programmer can specify... there is some merit to non MPL
syntax in keeping the code simple and the transformation simple to specify.
So another issue is runtime / compile time specification of transforms. Can
transforms be specified at runtime? With my example they can as the
transform functions are simply boost::function calls. Can the syntax (_2 -
_1) / _2 * 100 ) also call user defined functions such as ( _2 -1) / _2 *100
/ g(_1, _2 ) )

Can the syntax be used to specify arbitrary function transforms defined by
the programmer?
Does it allow to bind two or more values together where one is changed and
the remaining values are affected through overloading the operator= and
calling specified transform functions.
If yes then yes this is what I am after.

I think there are two issues here transforms and how they are specified and
databinding where multiple values are bound to each other... change 1 and
they all change automatically (binding). Transformations specify how the
bound values get transformed. The key I desire is to specify the transforms
upfront and then simply change the value in code knowing that the
transformation functions will yield a result on the remaining data bound
variables based on the specified transform(s).

Excerpt from proto:
"The transform above might look a little strange at first. It appears to be
constructing a temporary object in place. In fact, it is a *function type*.
Since terminal<long>::type and _arg are types, terminal<long>::type(_arg) is
actually the type of a function that takes _arg as a parameter and returns
terminal<long>::type. That is immaterial; there is no such function in
reality. Rather, Proto interprets this function type as a transform, the
effect of which is described above. The resemblance to an in-place
construction of a temporary object is intentional. It is a concise and
natural notation for specifying transforms. Proto transforms use function
types extensively, as we'll see. "

and

"When using function types as Proto transforms, they can either represent an
object to construct or a function to call. It is similar to C++ where the
syntax foo(x) can either be interpreted as an object to construct or a
function to call, depending on whether foo is a type or a function. "

so my above example ( _2 -1) / _2 *100 / g(_1, _2 ) ) would not work. Which
is fine... I do not have an answer for this either unless g(_1,_2) also
created an mpl object correct?

I don't see here where operator= is overloaded which will automatically call
specified transforms. It is not to say Proto could not be made to work or
it does work and just requires more thought on my part. With Proto
transforms

Excerpt from proto

int i = 0; // not used, dummy state and visitor parameter

std::cout << CalcArity()( lit(100) * 200, i, i) << '\n';
std::cout << CalcArity()( (_1 - _1) / _1 * 100, i, i) << '\n';
std::cout << CalcArity()( (_2 - _1) / _2 * 100, i, i) << '\n';

Calculates how many arguments are operated on 0 for the first as they are
constants, 1 for the second as only _1 is specified, and 2 for the third
because both _1 and _2 are specified.

What I desire is:

int i =0, j =0;

bind_values<int, int>( ( _1 = 2 * _2, _2 = 1 / 2 *_1,i, j ); // my example
does not support this syntax which proto does

i = 2;
std::cout << j << std::endl; // produces 4
j = 16;
std::cout << i << std::endl; // produces 8

>
> Also, the mention of common set of types and transformations reminds
> me of algebras and transformations between those algebras. In
> particular, there was mention of some operators defined for
> some domains and not for others. This reminds me of algebraic
> structure that have a limited set of operators. For example:
>
> http://planetmath.org/encyclopedia/Monoid.html
> http://planetmath.org/encyclopedia/Ring.html
>
> and more generally, for any number of operators:
>
> http://planetmath.org/encyclopedia/HomomorphismBetweenAlgebraicSystems.html
>
> The 'group of related types' phrase reminds me of 'many-sorted
> algebras' where each sort corresponds to type in 'group of
> related types':
>
> http://planetmath.org/encyclopedia/ManySortedStructure.html
>
> Is there any chance the data_binding library is related?
> IOW, would the data_binding library dos use some of the
> terminology in the above planetmath .htmls to describe
> the library's purpose?
>

My data binding does example, and I stress here simple, does not support
domain transformation, but it sounds like Brook's transformation library
does.

Brian


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk