Past (20 years or so) and present code. A variety of languages and platforms. Some gems. More gravel. Some useful stuff and some examples of how not to do it.
Wednesday, August 17, 2005
Found another use for Eval() in VBScript - state tables
Imagine trying to keep track of all possible combinations of four variables. Big if/then/else/end if, right? Not necessarily.
2 comments:
Anonymous
said...
Your example looks terrifying. Why not simply do the following (don't mind my python):
def calculateState(*args): state = 0 for i in reversed(args): state *= 2 if i > 0: state += 1 return state
It achieves the same effect with much less pain and suffering. Not that this function actually turns a list of arguments representing a binary number into a decimal number. You could use foldl if you were using a functional language.
Hmm ... will have to take the code home and try it out on the iBook.
Mind you, the issue was to do the job in VBScript, which is what I'm using at work.
And after a meeting today, which removed the need for the state-table approach, the whole thing is moot.
And then there was the issue of what to do with the different states: I had 5 years which could have had 16 states each to derive rules for. I'm kind of glad that that the meeting removed the need.
2 comments:
Your example looks terrifying. Why not simply do the following (don't mind my python):
def calculateState(*args):
state = 0
for i in reversed(args):
state *= 2
if i > 0:
state += 1
return state
It achieves the same effect with much less pain and suffering. Not that this function actually turns a list of arguments representing a binary number into a decimal number. You could use foldl if you were using a functional language.
Hmm ... will have to take the code home and try it out on the iBook.
Mind you, the issue was to do the job in VBScript, which is what I'm using at work.
And after a meeting today, which removed the need for the state-table approach, the whole thing is moot.
And then there was the issue of what to do with the different states: I had 5 years which could have had 16 states each to derive rules for. I'm kind of glad that that the meeting removed the need.
--Bruce.
Post a Comment