Thanks again. On our local Jobeserver, C & Java assignment evaluations are working pretty well. I am now struggling to setup SWI-Prolog. Already installed SWI-Prolog compiler on Jobeserver and tried /var/www/html/jobe/application/libraries/swipl_task.php as given, however SWI-Prolog is not appearing in the Coderunner Question type.
The set of question types is defined by the set of available question prototypes. Adding explicit support for a new language to the Jobe server doesn't give you any new question types.
See the CodeRunner documentation on User defined question types and Supporting or implementing new languages. You'll see in the second of those links that you don't actually need to add explicit support for a new language to Jobe; you just have to install the language on the Jobe server. You can then access it via a script in one of the existing languages. This is the preferred approach because it doesn't create maintenance issues when Jobe is updated.
Virtually all languages at University of Canterbury are nowadays run via Python scripts, because it gives you much more flexibility.
- Richard
While going thru the second link, I found: "Turn on the Twig All checkbox, so that all fields of the question will get processed by Twig, once the template parameters have been set up." Where can I find this checkbox?
It's in the topmost panel of the question authoring form, as shown in the figure below. However, it's a new feature and may not be in your version of CodeRunner. It's only relevant when you're randomising questions, so if this is still about adding prolog to CodeRunner you can ignore it.
I need help as I'm stuck while creating a Prolog question type in CodeRunner. I followed your advice and implemented a custom question type using Python. However, the output does not appear in the Got section of CodeRunner.
Could you please assist me in troubleshooting this issue?
Thanks.
I think the main problem with your template is that the Twig QUERY variable is undefined. Probably should be a field from the TEST variable, e.g. TEST.testcode?
I'm not sure what sort of question you want to ask, but it looks like you want the students to write the Prolog program and your tests will then run queries against that? If so, a possible template is the following. It's more or less what you had, except I've replaced QUERY with TEST.testcode.
""" A generalized template for running any Prolog code and query. """ import subprocess, sys # Write the student's Prolog code to a file prog.pl student_answer = """{{ STUDENT_ANSWER | e('py') }}""" with open("prog.pl", "w") as src: print(student_answer, file=src) # Define the query dynamically (e.g., from a parameter or input) query = """{{ TEST.testcode | e('py') }}""".strip() + '\n' # Run the Prolog program with the query try: # Use SWI-Prolog to execute the query result = subprocess.run('swipl -q -s prog.pl'.split(), capture_output=True, text=True, check=True, input=query) if result.stderr: # Print errors if any print(result.stderr, file=sys.stderr) else: # Print the actual output print(result.stdout.rstrip()) except subprocess.CalledProcessError as e: # Handle errors during execution print(e.stdout.rstrip()) print(e.stderr.rstrip()) if e.returncode > 0: # Non-zero return codes indicate runtime errors print("** Prolog runtime error **", file=sys.stderr) else: # Negative return codes indicate signals (e.g., segmentation fault) if e.returncode < 0: print("Task failed with signal", -e.returncode, file=sys.stderr) print("** Further testing aborted **", file=sys.stderr)
This could be used in questions like the following (with apologies for the kindergarten-level Prolog - I learnt a bit about 40 years ago and haven't touched it since!):
I attach the XML exports of the prototype and the example question. But you'll undoubtedly want to tune the prototype, and you'll need to investigate the error behaviour - I don't know how swi-prolog behaves.
An obvious defect of that example is that a student could simply provide facts that match the tests, rather than writing any predicates. So you'd at very least need some hidden test cases. And a lot more thorough definition of what the program is meant to define.
I tried your sample question, and it works perfectly—thank you very much! However, I’m still encountering a challenge, and I’m unsure whether the issue lies with the Prolog environment or the Prolog question template.
The facts below work okey:
parent(john, mary).
parent(john, tom).
When i add a third fact as shown below, i get an error:
parent(john, mary).
parent(john, tom).
parent(susan, mary).
An error appears on the first fact:
***Run error*** ERROR: Type error: `character_code' expected, found `-1' (an integer) ERROR: In: ERROR: [11] char_code(_9694,-1) ERROR: [10] '$in_reply'(-1,'?h') at /usr/lib/swi-prolog/boot/init.pl:1012As shown below:
