[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-jel] Locate token in expression?

From: Konstantin L. Metlov
Subject: Re: [Help-jel] Locate token in expression?
Date: Tue, 27 Nov 2018 18:55:24 +0300
User-agent: SquirrelMail/1.4.23 [SVN]

Dear Mark,

if you consider your variable names as nodes, then every expression adds a
certain number of directed links (from the nodes, corresponding to all
used variables, to the target node, which is assigned the value of the
expression). The directed graph, formed by these nodes and links, must be
acyclic (have no loops in it).

The question you are facing is whether adding another edge (newly compiled
expression will add a number of edges, equal to the number of variables it
references) to the DAG (directed acyclic graph) will produce a cycle in

This is quite an interesting problem, which is efficiently addressed by a
number of well known algorithms. See e.g.

JEL can help you to obtain a list of the referenced variables. You can
catch amd collect them in the gnu.jel.DVMap.getTypeName(String name)
method of your dynamic variable resolver, which is called for every
potential variable name JEL encounters in the expression.

With the best regards,

> Dear Konstantin,
> in my application, the user can define a named value at run time
> by supplying a JEL expression, and this name can be used in
> subsequent definitions.  As a convenience, they can also
> redefine an existing name by editing the expression.
> So for instance one can define a name "A" as "B + C",
> assuming that B and C are already known to JEL.
> Later, one can redefine "A" as, e.g., "2*B + C".  So far so good.
> However, if C has already been defined in terms of A, there's trouble:
> the definition is recursive, and evaluation never terminates.
> So, I want some way to catch this condition.  If I can analyse
> the expression "2*B + C" to see whether it contains any
> (explicit or implicit) reference to the name "A",
> then I can issue an error message and prevent the user from
> assigning the new expression as the value of "A".
> I've had a look at the JEL API (though not the source code) and
> I have some ideas of what might work ... but I'm not sure.
> Is this possible with the existing API?  If so, could you give me
> an outline of how to go about it?
> Many thanks,
> Mark
> --
> Mark Taylor   Astronomical Programmer   Physics, Bristol University, UK
> address@hidden +44-117-9288776
> _______________________________________________
> Help-jel mailing list
> address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]