Expressions are evaluated when getToken() or validate() is called on
the Parameter, but only if the expression has changed.  It is a documented
feature that random() in an expression yields one random number, not
a new one each time you read the value of the parameter.

I believe this is the correct behavior.  Reading the value of a parameter
should never cause its value to change.  This would usually be an unexpected
side effect.  Reading is reading, and is distinct from writing.

Edward

At 07:17 PM 3/25/2002 +0000, G Dring wrote:
>This has been posted to com.soft-sys.ptolemy as well - sorry if you see this
>twice, but as a newbie, I'm not sure which is the better way to go...
>
>
>I have a query about how and when expressions are evaluated... I'm coding a
>class in the DE domain which allows you to provide an expression as a
>parameter. This defines an inter-firing period.  I don't think that the
>expression is being evaluated each time.  The relevant bits of code are:
>
>=> variable declaration
>
>     public Parameter interArrival;
>
>=> within the constructor method
>
>     interArrival = new Parameter(this, "interArrival", new
>DoubleToken(1.0));
>
>=> within the fire() method
>
>     _delay = ((DoubleToken)interArrival.getToken()).doubleValue();
>
>     _nextMsgTime = ((DEDirector)getDirector()).getCurrentTime() + _delay;
>
>If I use this as code as a message source, I get a constant inter-arrival
>time for the entire session.  This appears to be setting the value of the
>expression at initialization time, wheras I'd like it set each time I
>evaluate interArrival.getToken().  Any advice?
>
>(I also posted a reply to myself, which I include here for completeness...)
>
>A bit of additional information that I have dug out of the classes...
>
>Parameter is derived from Variable, which (very sensibly, in most cases)
>sets a _needsEvaluation flag. However, when using an expression such as
>random() or gaussian(), this causes the same token to be presented each
>time, unless somehow the value is changed... It seems that the variable
>class could do with another private variable _alwaysEvaluate, so that this
>behaviour can be controlled...
>
>giles
>
>*** A million monkeys were given a million typewriters. It's called the
>Internet
>
>----------------------------------------------------------------------------
>Posted to the ptolemy-hackers mailing list.  Please send administrative
>mail for this list to: [EMAIL PROTECTED]

------------
Edward A. Lee, Professor
518 Cory Hall, UC Berkeley, Berkeley, CA 94720
phone: 510-642-0455, fax: 510-642-2739
[EMAIL PROTECTED], http://ptolemy.eecs.berkeley.edu/~eal


----------------------------------------------------------------------------
Posted to the ptolemy-hackers mailing list.  Please send administrative
mail for this list to: [EMAIL PROTECTED]

Reply via email to