Boost logo

Boost Users :

Subject: Re: [Boost-users] proto: analytical-only math functions
From: Eric Niebler (eric_at_[hidden])
Date: 2009-03-14 16:16:32

Hicham, your mail client is messing up the quoting. Is there anything
you can do about that? I'll just snip everything that's been misquoted,
but it is making the discussion very hard to follow.

Hicham Mouline wrote:
> And I would definitely prefer compile-time as well, but as a user
> I would call the the derivative function in a scope that is very far from
> where f is defined. Does that matter?

It certainly does matter. The variable 'f' would need to encode the
entire expression in its type. For that, BOOST_PROTO_AUTO is your only
option (until c++0x and 'auto' declarations).

> In the syntax you proposed above, what is the "let"?

Just another part of the DSEL. It makes it possible to have 'f' and 'g'
defined in the same expression so that 'g' can take the derivative of 'f'.

> What are the curly and square brackets for?

What curly braces? The let defines the formula 'f'. The brackets denote
a scope in which the definition of 'g' can have access to the definition
of 'f'.

> If the derivative function is called outside those square bracket, it will
> not work?

Correct. It has no static type information to work with.

> The declaration of f would be earlier than its definition?

I don't understand.

> Will I be able to put regular c++ code that is not related to f/g inside the
> brackets?

No, everything in the square brackets is part of the DSEL you're defining.

> Will I be able to use g outside of the brackets?

You could assign the whole expression to some variable, which could then
be used outside the brackets. But then you get into the same trouble
with type erasure.

I suggest you take the time to read about type erasure. See the link I
sent in the earlier message. Once you understand the
runtime/compile-time issues, you'll understand why what you want to do
is impossible.

Eric Niebler
BoostPro Computing

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at