void ScriptedFitnessFunction::addCustomScriptContextStructures() { ScriptingContext::addCustomScriptContextStructures(); QScriptValue error = mScript->evaluate(QString("function terminateTry() {") + " nerd.terminateCurrentTry() };"); if(mScript->hasUncaughtException()) { reportError(QString("Could not add defVar function. ") + error.toString()); return; } error = mScript->evaluate("var fitness = nerd.fitness;"); if(mScript->hasUncaughtException()) { reportError(QString("Could not add fitness variable. ") + error.toString()); return; } defineVariable("tryCount", EvolutionConstants::VALUE_EXECUTION_NUMBER_OF_TRIES, false); defineVariable("stepCount", EvolutionConstants::VALUE_EXECUTION_NUMBER_OF_STEPS, false); error = mScript->evaluate( "function _calculateFitness() { fitness = nerd.fitness; nerd.fitness = this.calc(); };"); if(mScript->hasUncaughtException()) { reportError(QString("Could not add _calculateFitness() method. Naming conflict? ") + error.toString()); return; } }
sExpression *evalDefineSyntax(sExpression *exp, sEnvironment *env){ if(isDefinitionSyntax(exp) && isSyntaxRules( cadr(toList( cdr(toList(exp)))))){ sSymbol *name = toSymb(cadr(toList(exp))); sExpression *rules = cdr(toList( cdr(toList( cadr(toList( cdr(toList( exp)))))))); defineVariable(name, callProcSyntaxRules(rules), env); return &sTrue; } return &sError; }
void EXParser::loadDefaultVariables(void) { defineVariable("pi", 3.14159); //pi constant //defineVariable("e", 2.718282); //eulers constant }
/* BAD PART. NEEDS REFACTORING */ void Configurator::handleConfigurationFileLine(std::string line, int type) { std::string configurationExpressions[] = {CONFIGURATIONEXPRESSIONS}; int numberOfExpressions = sizeof(configurationExpressions) / sizeof(std::string); double value = -1; for(int i = 0; i < numberOfExpressions; i++) { std::string toFind(configurationExpressions[i]); std::size_t found = line.find(toFind); if (found != std::string::npos) { value = getNumberFromString(line); defineVariable(i, value, type); } } }
void XS08(struct S08_st *d) { //var = expression; int eval; int (*fnc)(void *) = NULL; defineVariable(&variableList, d->name); //define if not exists switch (d->t) { case tE01: fnc = &XE01; break; case tE02: fnc = &XE02; break; case tE03: fnc = &XE03; break; default: fprintf(stderr, "Unknown expression\n"); abort(); } eval = *fnc(d->match); setVariable(&variableList, d->name, eval); }
void XS06(struct S06_st *d) { //def var if (!defineVariable(&variableList, d->name)) fprintf(stderr, "%s is already defined!\n", d->name); }
sExpression *evalDefine(sExpression *exp, sEnvironment *env){ if(defineVariable(definitionSymbol(exp), eval(definitionValue(exp, env), env), env)){ return &sTrue; } return &sFalse; }