|
Argg! Argg! And thrice Argg!
I have an expression evaluator; see me articles if you care. I am adding in function support so you can define a function [as an expression or an external class] that will can then be used in further expressions. Examples of built in functions are trig - sin, cos, tan and pi - and a simple null function to return null .
Simples, simples, simples or so it bloody should be. I have now hit a problem that to create the function library, you need to be able to parse expressions and to parse expressions you need the functions.
So I decided there should be a single point to start construction. Now, does the expression use the function or the function the expression? I am going in stupid circles here, so for now I have taken the decision to go to the pub.
speramus in juniperus
|
|
|
|
|
Backup first - then go to the pub.
That way, tomorrow it is easy to throw away the drunken garbage you thought was good code at the time...
The only instant messaging I do involves my middle finger.
|
|
|
|
|
Unless you are doing this for fun, it strikes me Java isn't you best place to start and these types of things generally sail close to the "Inner-Platform effect" anti-pattern (at least where I've been involved), albeit one that replicates another platform rather than Java itself in this case.
I'm just gonna leave this here[^]
Nagy Vilmos wrote: I have taken the decision to go to the pub
Good call. I wish I could make the same one.
|
|
|
|
|
I'm using it, mostly, for quite simple stuff that needs to be parametrised and is driven from configuration. When I get my finger out, I'll write some more articles explaining more how and why.
For the time being, I've decided that the expressions will be built from the functions and so my load order is decided. Thank you goes to my muse[^].
speramus in juniperus
|
|
|
|
|
I was in a team helping crack a similar problem (actually, defining mortgage acceptability criteria for multiple mortgage types) a few years back.
The idea we were close to implementing an XML-based language was was always at the back of our minds. Greenspun's tenth rule was discussed as well, we considered writing it all in LISP (or f# if it got out of beta quickly enough) but the accepted wisdom was we'd never get it past the IT manager.
If it is any help, my inspiration normally comes here[^].
|
|
|
|
|
This is a fun project. Even though I am using it in several bits of work I'm doing, the idea is a flexible framework. The evaluator is used mostly in the server but going forward I will be using it to provide customisable functionality to the user as well.
As an example, to set the colour of a row depending on if it has a positive or negative amount, something like:
background = (balance < 0) ? "#FF0000" : ((balance > 0) ? "#0000FF" : "#00FF00"))
Simples!
The functions provide parametrised evaluations, so the above could use a function like:
background = [colorByValue balance "#FF0000" "#0000FF" "#00FF00"]
#Function:
colorByValue {
description - return the colour depending on if the value is negative, positive or zero
arguments - value negative positive zero
expression - (value < 0) ? negative : ((value > 0) ? positive : zero))
}
Added onto that, it allows for functions to be defined that don't use expressions but call out to standard java classes added into the function library. Hence I've plugged in maths support for sine, cosine, tangents and pi as well as a few other bobs and bits. Loops are next
speramus in juniperus
|
|
|
|
|
Nagy Vilmos wrote: I have taken the decision to go to the pub
Correct decision. Order some GIN and get back to the project..
The signature is in building process.. Please wait...
|
|
|
|
|
I come to work by train and then bus. The bus is linked to the train. It costs R6 one way if used within an hour of getting off the train, and R20 one way otherwise. So, a trip to the pub would cost just less than two pints, and the buses only run every forty minutes off-peak, so my half hour lunch time would be one and a half hours.
|
|
|
|
|
The pub is only a five minute walk. But lunch can still extend to two hours.
speramus in juniperus
|
|
|
|
|
Google says the nearest pub is a fifteen minute walk. That's two pints if I stretch lunch to an hour.
|
|
|
|
|
Oi! No programming questions in the Lounge!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Nagy Vilmos wrote: does the expression use the function or the function the expression?
Yes. Recursion is as recursion does.
But it occurs to me that there shouldn't be a problem intil the function is evaluated and by then you just have a value, right?
If not, then you pass it an instance of IExpression or something.
|
|
|
|
|
Do I look like a madman? [Don't answer]
The expressions are parsed when they're loaded, so any function must exist before it can be referenced. The only recursion allowed is for a function to call itself, but looped recursion [A -> B -> A] won't be allowed.
The syntax has actually not failed me yet and it is [for an interpreted script] quite efficient. Once created, an expression can be called multiple times with different data and it all works very nicely. It's just this load order that is getting on my unmentionables.
speramus in juniperus
|
|
|
|
|
Nagy Vilmos wrote: now I have taken the decision to go to the pub.
Excellent plan. You can't imagine how many brilliant subroutines and functions I've written on cocktail napkins. Sometimes you just need to lubricate the neurons a bit.
Will Rogers never met me.
|
|
|
|
|
You just need the conceptual idea of a compiler-compiler.
You create build process that creates a minimal set of initial functions. The implementation of that is a tool which does its job without relying on the elegance of the dynamic interface.
|
|
|
|
|
America was not shut down properly. Would you like to start America in safe mode, with free healthcare & without the guns? (Recommended)
---------------------------------
Obscurum per obscurius.
Ad astra per alas porci.
Quidquid latine dictum sit, altum videtur .
|
|
|
|
|
Is the only option the recommended option?
"Rock journalism is people who can't write interviewing people who can't talk for people who can't read." Frank Zappa 1980
|
|
|
|
|
Yes, and can I have a Happy Meal take-out with that ?
bill
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
I wish I bloody cared.
speramus in juniperus
|
|
|
|
|
Time to reinstall a constitutional limited os.
hows that 'free' healthcare your side of the pond?
Charlie Gilley
<italic>You're going to tell me what I want to know, or I'm going to beat you to death in your own house.
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
|
|
|
|
|
Way, way better than the free health care on your side at the moment...
The only instant messaging I do involves my middle finger.
|
|
|
|
|
Funny how "the right to life" always takes a back seat to "the right to possess devices that are designed to kill", over in Leftpond.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
Dalek Dave wrote: America was not shut down properly
It has been shut down while an "America Budget update request" was running..
The signature is in building process.. Please wait...
|
|
|
|
|
Without guns?
In Brazil people can't have guns, and the govern is "awesome", because we can't fight.
My old grandfather tells me about the civil war days...
|
|
|
|
|
Since "Last known good" was not/is not/will not be available for the U.S., i´d prefer the recommended reboot option...
|
|
|
|