Hi,
I'm embedding IP2 in an C# application. The user can extend objects by
entering expressions based on the object's properties and expressions
defined so far. That means an expression is evaluated in the object's
"scope".
Now I want to allow expressions that reuse other expressions, but
override the scope in which these referenced expressions are evaluated.
For that the user should use the name of an expression and give the
properties to override as keyword arguments.
Example:
class Transport {
public double Distance { get; set; }
public double Weight { get; set; }
// ...
}
Expression "Freight" is defined by the user as:
>>> Transport.Freight = "Distance * 1.1 * Math.Sqrt(Weight / 24000)"
>>> t = Transport(Distance=100, Weight=6000)
>>> print t.Freight
55
>>> Transport.FreightFTL = "0.8 * Freight(Weight=24000)"
>>> print t.FreightFTL
88
So when the expression Freight is evaluated the Weight property is
overriden with 24000 and Distance is used normally from the object's scope.
I see 3 possible directions to achieve this:
1. Using GetBoundMember/GetCustomMember and somehow identify, if
the requested property is expected to be a function or a regular return
type.
2. Accessing expression-properties returns an object that has a Call
SpecialMethod with ParamDictionary args and a "default property" that
returns the expression's value.
3. Parsing the expression and determine if the expression uses other
expression in a functional context or normally as a property.
Does anyone have an idea how to achieve this or improve the design?
Thanks
Christian
_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com