News for hackers. Stuff that matters.
Re:To all who Think Themselves a Programmer by frig on Tuesday July 07, 2009 @07:29PM (#692847)
Missed the edit interval, so:

  def findPossibleSolutions(querytext): 
    for result in GoogleCodeSearch(query=querytext): 
      yield result

  def tryOutPossibleSolution(candidate): 
    output = None 
    with SafeSandboxedEvaluatorFactoryFactory(candidate.language).safeSandboxedEvaluator() as evaluator: 
      output = evaluator.evaluate(candidate.code) 
      return output

  def validatePossibleSolution(candidate, validator): return 
    validator(tryOutPossibleSolution(candidate))

  def giveMeValidSolutionSourceCodes(querytext,validator): 
    for validSolution in (candidate for candidate in findPossibleSolutions(querytext) if validatePossibleSolution(candidate,validator)): 
      yield {'source'=validSolution.code,'extension'=validSolution.languageExtension}

  if __name__ == "__main__": 
    helloWorlds = giveMeValidSolutionSourceCodes("hello world", lambda x: x == "hello world") 
    firstValidSource = helloWorlds() 
    if firstValidSource: 
      print "helloworld.%s:\n\n%s" % (firstValidSource["extension"],firstValidSource["source"]) 
    else: 
      print "helloworld.py:\n\nprint \"hello world\"" # default case ''

There are no comments on this comment yet.