New Expression class

Could you share some more info on this class, i know it parses some basic numeric expressions, i saw you can even put functions and variables in.
Could you tell us if that will be extended at any time with more functionality.

Also a question from me, can we do BIT operations in those expressions?

It’s really basic at the moment, and really just there to support the RelativePosition classes, so takes just floating-point numbers, and does the basic + - * / ops, with min, max, abs as functions. If you want to add more functions, you can already do that by writing your own Expression::Scope class.

Sorry to revive the old thread, but I’m trying to use them now - I need to do a bit of variable scaling to an incoming value. I’ll be specific:

  • the user is moving a slider which sends me OSC, with a value of 0.0 - 1.0, let’s call that inValue

  • for each slider, I want to store a string to be used as an expression, say “(inValue * 2.0) - 1.0”

My class that is running the expressions now inherits from Expression::scope, so it can handle things like ‘currentValue’, or parent.x etc.

My question is, can’t I inject the one value in without returning it from the scope? I see I can create an expression from a double, or an operation, should I be making an expression with my value, and then applying the stored expression?

Or do I have to set the incoming value to a member so I can pass it back in the scope, which seems a bit back-assward to me?

Edit: it does work this way. It just seems that I should be able to pass at least one value in when I evaluate.

Bruce

It’s an expression class, not a function class, so it was never designed to have any concept of parameters being passed in. It could be wrapped into a function class that provides a scope containing the parameters that you want it to work with, but that’s not what the basic expression object is about.

I see. I guess it must have some parameters, or else why bother, but I guess your uses of it have been using ‘internal’ parameters, rather than something fed in.

What about something that applies an expression to an Expression?

Like:

Expression calc (Expression(newValue).applyExpression ("* 5 - 2.5));

No, that wouldn’t make much sense, it’d need to take a set of values as parameters, and give them names to use in the expression.