Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ Programming
➜ General
➜ Recursive Configuration Evaluation
|
Recursive Configuration Evaluation
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1
2
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #15 on Thu 20 May 2010 08:08 PM (UTC) |
| Message
| | But how will this work? You still have the issue of evaluation order. You still have the issue of undeclared variables. Even if you use the metatable trick I mentioned to give defaults for the variables, and instead return these "smart objects", you haven't solved the evaluation order problem... |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Twisol
USA (2,257 posts) Bio
|
| Date
| Reply #16 on Thu 20 May 2010 08:14 PM (UTC) Amended on Thu 20 May 2010 08:16 PM (UTC) by Twisol
|
| Message
| Because they're not evaluated at any point in the context of Bernhard's original example. Each line defines the formula for one variable. This formula is dependant on other variables in the same scope, but none of these variables are actually accessed at any time at this point.
When a formula is defined - __newindex in the scope, "x = ..." - it's placed in a different table than the accesses - __index in the scope, "... = y". When an rvalue is accessed, it gets/creates a getter for that variable, and stores it in a table of getters so more than one is never created for a given name. When an lvalue is set, the definition is stored in a table of definitions, which is never accessed in any way except to set them.
After the file is run, you should be able to access the definitions yourself, which will then evaluate the constructed equations and return a result. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #17 on Thu 20 May 2010 08:25 PM (UTC) |
| Message
| This could work -- except for the problem that you can only handle arithmetic with metatable support, and this can be a big problem.
For example, you can't just do:
math.pow(a, 2)
ok, you can do a^2 and use the __pow__ metamethod. But what about trig functions, etc.
It means that you'd have to provide support under-the-hood for "smart object"-aware mathematical functions, and letting the user write their own functions becomes harder as well.
Additionally, if you go to the original post, he has an example where he does width = myfunc(). This creates more work: as you evaluate this (in Lua) you are losing the fact that you are calling some function. If everything were just an expression, or a function that returns a deferred-computation object, it would be ok, but this is imposing new constraints on users that might be outside the scope of difficulty that Bernhard wanted.
By the way, I don't think you said here what you meant to say:
Quote: When an lvalue is set, the definition is stored in a table of definitions, which is never accessed in any way except to set them.
(If you never access it other than to set it, then in particular you're never retrieving the value you put in...) |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Twisol
USA (2,257 posts) Bio
|
| Date
| Reply #18 on Fri 21 May 2010 12:41 AM (UTC) |
| Message
|
David Haley said:By the way, I don't think you said here what you meant to say:
Quote: When an lvalue is set, the definition is stored in a table of definitions, which is never accessed in any way except to set them.
(If you never access it other than to set it, then in particular you're never retrieving the value you put in...)
I did mean that. Again, within the context of the formula script, nothing actually is evaluated. All that script does is define formulae. After it's done - and in the original environment - you can evaluate and retrieve values by using the definitions table I mentioned before.
And yes, I specifically saw the need for using functions within the formulae scope. You just add these functions to the definitions table at any point, and as long as they're defined before you try to evaluate a formula, it should work fine.
That's the idea, anyways. I've barely done any work on it, but I know the premise is sound. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #19 on Fri 21 May 2010 03:37 AM (UTC) |
| Message
| It requires all user functions to be written in this special way as well, which is unfortunate if the goal is to provide an easy syntax.
Also, the whole idea of using a metatable trick is rather dirty in the first place in that it lets uninitialized or incorrectly named variables slip in and seem initialized, but, well, that's kind of the way it goes given the constraints.
Quote: Again, within the context of the formula script, nothing actually is evaluated.
I realize that you're using your vocabulary somewhat loosely, but it's not at all correct to say that "nothing" is evaluated: of course the script is being evaluated. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Twisol
USA (2,257 posts) Bio
|
| Date
| Reply #20 on Fri 21 May 2010 03:51 AM (UTC) |
| Message
|
David Haley said: It requires all user functions to be written in this special way as well, which is unfortunate if the goal is to provide an easy syntax.
Not really. External functions can be inserted from the outside just like the formula definitions on the inside, and they can be accessed on the inside like any other formula.
David Haley said: Also, the whole idea of using a metatable trick is rather dirty in the first place in that it lets uninitialized or incorrectly named variables slip in and seem initialized, but, well, that's kind of the way it goes given the constraints.
Given the constraints, yes, this seems like the best way to go.
David Haley said:
Quote: Again, within the context of the formula script, nothing actually is evaluated.
I realize that you're using your vocabulary somewhat loosely, but it's not at all correct to say that "nothing" is evaluated: of course the script is being evaluated.
No, you're right. But "a = b + c" doesn't evaluate a and b, but hangs on to them for later use. Basically late evaluation. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #21 on Fri 21 May 2010 05:40 AM (UTC) |
| Message
|
Quote: External functions can be inserted from the outside just like the formula definitions on the inside, and they can be accessed on the inside like any other formula.
I meant user-specified functions within the same configuration file. I guess you could play games with newindex and see that somebody is assigning a value that happens to be a function, and then wrap the function in some kind of lazy-evaluation chunk... or something.
Something like:
function sphere_vol(r)
return (4.0/3.0) * math.pi * r^3
end
mass = volume * density
volume = sphere_vol(radius)
This requires even more trickery, because you have to replace sphere_vol with a function that returns one of these lazy-evaluation objects, such that when sphere_vol(radius) is evaluated, you get back an object that knows how to call the sphere_vol function with the appropriate parameter etc. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Twisol
USA (2,257 posts) Bio
|
| Date
| Reply #22 on Fri 21 May 2010 07:18 AM (UTC) |
| Message
| | That's exactly what I'm hoping to do, actually. And when all's said and done, that example actually doesn't look bad at all. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | | Top |
|
| Posted by
| Bernhard
(18 posts) Bio
|
| Date
| Reply #23 on Mon 24 May 2010 09:18 PM (UTC) |
| Message
|
Actually, the requirement is not to use lua in any case, so all right if there is a better choice – unless the licence is problematic. I would prefer to get along without complicated tricks if possible.
I need the system to understand a statement like ‘mass = volume * density’ as
‘In case you need to know the mass: get volume and density, and then multiply them’
instead of
‘Multiply volume and density, then store it in mass NOW’.
So
* drive off
* then turn on the ignition
* then get into the car
must be understood as a set of rules like
‘to get somewhere drive off’
‘to drive off get into the car and turn on the ignition’
‘to turn on ignition get into the car’
=> up to now nothing happened.
Then someone orders >>get somewhere<<, and the system knows what to do.
‘Native’ lua does not understand an ‘x = y*z’ statement like that.
So option 3 would/could be, e.g., to store all formulas (x = y*z) in a hashmap with key ‘x’ and ‘y*z’ as the value. The ‘x*y’ must then be evaluated with a parser that obtains ‘x’ and ‘y’ from the same hashmap, thus, evaluating a set of dependent formulas in the correct order.
| | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #24 on Mon 24 May 2010 09:26 PM (UTC) |
| Message
|
Quote: So option 3 would/could be, e.g., to store all formulas (x = y*z) in a hashmap with key ‘x’ and ‘y*z’ as the value. The ‘x*y’ must then be evaluated with a parser that obtains ‘x’ and ‘y’ from the same hashmap, thus, evaluating a set of dependent formulas in the correct order.
You can't really do something like this without the same kind of trickery we were talking about, unless you start writing your own parser for mathematical expressions.
I don't know of any programming languages that allow simple syntax and declarative definitions of variables. Prolog, for example, is declarative but not exactly what I'd call simple for users.
Perhaps Nick's expression parser is pretty close, but you would need to add support for the extra control flow that you want.
Basically, no matter which approach you choose, it looks like you'll have some work do. While you can construct something that will be simple for the end-user, I do not think that you will be able to get away with something really easy for you as the developer as well. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Bernhard
(18 posts) Bio
|
| Date
| Reply #25 on Mon 24 May 2010 09:27 PM (UTC) |
| Message
| <Erratum:>
So option 3 would/could be, e.g., to store all formulas (x = y*z) in a hashmap with key ‘x’ and ‘y*z’ as the value. The ‘y*z’ must then be evaluated with a parser that obtains ‘y’ and ‘z’ from the same hashmap, thus, evaluating a set of dependent formulas in the correct order.
<Appendix:>
Since I need the 'do it now' statements as well as the 'do it when you need it' declarations, I should use a slightly different syntax (e.g., := instead of = for one of them) or store it in different files.
| | Top |
|
| Posted by
| Bernhard
(18 posts) Bio
|
| Date
| Reply #26 on Mon 24 May 2010 09:49 PM (UTC) |
| Message
|
David Haley said:
Perhaps Nick's expression parser is pretty close, but you would need to add support for the extra control flow that you want.
That's where I started - but I will have to deal with the 'if' issue then (see the corresponding thread).
David Haley said:
Basically, no matter which approach you choose, it looks like you'll have some work do.
Well, if I can't get something out of the box, I'll have to do it myself. Maybe I will try to adapt the parser (and later explain here what I did, in case someone is interested).
| | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
80,222 views.
This is page 2, subject is 2 pages long:
1
2
It is now over 60 days since the last post. This thread is closed.
Refresh page
top