Description
Our current advice for writing grader programs is to define a function containing all grading logic, and call that function once at the end of the grader program, i.e.
function oth9iexeeY() {
const sum_marks1 = sum(3, 5) === 8 ? 1 : 0;
const sum_marks2 = sum(-3, -5) === -8 ? 1 : 0;
return sum_marks1 + sum_marks2
}
oth9iexeeY();
The point being that this avoids name conflicts wrt identifiers of the student programs vs grader programs. This is a perfectly valid solution imo, since the chances of a student naming an identifier oth9iexeeY
or some other similarly random string is practically zero.
However, it does impose an artificial restriction on how module stuff should write a grader program
Instead of asking staff to define a function and call that function, we should just transform the AST of the grader program to accomplish the same thing. In this way, module staff will be able to freely write grading logic without limitations, e.g.
const sum_marks1 = sum(3, 5) === 8 ? 1 : 0;
const sum_marks2 = sum(-3, -5) === -8 ? 1 : 0;
sum_marks1 + sum_marks2;
And we will modify the AST post source syntax checking (so that we are able to use normally disallowed syntax such as function expressions) accordingly, e.g.
(function() {
// The grader's program is inserted here
const sum_marks1 = sum(3, 5) === 8 ? 1 : 0;
const sum_marks2 = sum(-3, -5) === -8 ? 1 : 0;
// note that the last statement is turned into a return expression
return sum_marks1 + sum_marks2;
})()