Prolog template for CodeRunner

Prolog template for CodeRunner

by Gauthier Heiss -
Number of replies: 0

Hello,
If anyone needs it, here is the Prolog template for Coderunner we just created with my colleague. It only needs swipl being installed on the jobe server. 

import subprocess, os
os.environ["OMP_NUM_THREADS"] = "1"
SEPARATOR = "#<ab@17943918#@>#"
pl_code = """{{ STUDENT_ANSWER | e('py') }}"""
{% for TEST in TESTCASES %}
pl_code += "\n:- initialization(test{{ loop.index }})." 
pl_code += "\n" + "test{{ loop.index }} :-"
pl_code += "\n" + """{{TEST.testcode | e('py')}}"""
{% if not loop.last %}
pl_code += "\n" + "write(" + SEPARATOR + "), nl."
{% endif %}
{% endfor %}
with open('prog.pl', 'w') as f:
    f.write(pl_code)
subprocess.call(["swipl", "-q", "-g", "halt.", "prog.pl"])

Here is an example: