Creation and Constants

49 views
Skip to first unread message

Colin Doncaster

unread,
May 11, 2011, 1:24:00 PM5/11/11
to seexpr-...@googlegroups.com
Hi there -

First off I've already answered one of my other questions, usesVar() to query if a variable is actually used or not. RTFM!

I noticed in the examples you pass the expression and external variables to the constructor of the derived expression class, I'd like my custom SeExpression to be a variable of another class which means I can't use this constructor. I assume there's no issue with calling setExpr vs supplying the expression via the constructor?

I assume that if a constant is supplied the expression is evaluated once with the result cached in some way, is this what prep() does?

Cheers,
Colin

Andrew Selle

unread,
May 11, 2011, 3:59:37 PM5/11/11
to seexpr-...@googlegroups.com
On Wed, May 11, 2011 at 10:24 AM, Colin Doncaster <colin.d...@gmail.com> wrote:
Hi there -

First off I've already answered one of my other questions, usesVar() to query if a variable is actually used or not.  RTFM!
 
I noticed in the examples you pass the expression and external variables to the constructor of the derived expression class, I'd like my custom SeExpression to be a variable of another class which means I can't use this constructor.  I assume there's no issue with calling setExpr vs supplying the expression via the constructor?
No this is fine. What is always important is to called isValid() to check if the expression parsed and prep'd properly.  You could also make your class contain a pointer to the expression and then just construct it later.

I assume that if a constant is supplied the expression is evaluated once with the result cached in some way, is this what prep() does?
This is not done automatically.  But you can call isConstant() to query if the expression uses any variables. If it is constant() you can call evaluate() once and then cache the result.

Cheers,
Colin

Colin Doncaster

unread,
May 11, 2011, 4:18:04 PM5/11/11
to seexpr-...@googlegroups.com

I've wrapped it in a shared pointer and using that now. 

Based on your comment is it good practice to always call prep after a setExpr() call?  The docs for evaluate say it will parse and bind if needed, is that different from prep?

Cheers

Andrew Selle

unread,
May 11, 2011, 4:31:44 PM5/11/11
to seexpr-...@googlegroups.com
setExpr() sets flags that things need to be reparsed/repreped. So It should be safe to go directly calling isValid(). You want to call at least that before calling anything else. Typically a user of the library should not need to call prep(). If that is the case, it is a bug.
-Andy
Reply all
Reply to author
Forward
0 new messages