Giter Site home page Giter Site logo

Comments (2)

picdc avatar picdc commented on June 8, 2024

Actually, it comes from how the grader works:

  1. a toplevel is initialized
  2. prepare.ml then prelude.ml are loaded into it
  3. the student code is loaded into it as the module "Code"
  4. solution.ml is loaded into the module "Solution"
  5. test.ml is loaded

As such, solution.ml will execute its side-effects after the graded code, and sets the reference to the correct value.

One naive solution would be to load solution.ml first. While this would work for constant values, it will not work if the reference contains a value that is computed : in that case, you would expect the grader to check the reference result against the solution's result, which would have been overwritten.

For now, the simplest solution I can think of is:

  1. If an exercise asks to modify a reference that is declared in prepare or prelude, use a second reference to store the result, which will be used specifically by test.ml (you still need to store into the original reference, otherwise the grader will reject the exercise).
  2. Load solution.ml before the student's code.

i.e.

solution.ml

let forty_two_copy = ref 0

let () =
  forty_two := 42;
  forty_two_copy := 42

test.ml

 Section ([Text "Ref: "; Code "forty_two"] ,
           test_ref [%ty: int] forty_two (!Solution.forty_two_copy)) (* /!\ use introspection *)

However, I'm not sure loading solution first is ideal: if you grade with the CLI, you can access the solution from the student code, via Solution.<ident> (it does not work online since it first typechecks the code). One possible solution would be to also typecheck offline.

I'm actually not sure how test_ref can be usable without such hideous tricks.

from learn-ocaml.

AltGr avatar AltGr commented on June 8, 2024

It seems test_ref wasn't intended to test student answers.
In the mooc, I found a couple of uses count application of certain functions during user code execution:

  1. initialise the reference in prepare.ml (never prelude.ml, I agree with @OCamlPro-Couderc wrote, I can't find a reasonable use for it in that case)
  2. (Re-)define the function you want to count uses of to increase the reference on each call
  3. Because of what @OCamlPro-Couderc wrote above about loading both the student code and the solution, in test.ml, you need to check the value of the reference after substracting the calls made from solution.ml
  4. Don't forget to add, in test.ml, an AST check that a clever student didn't redefine the function to not increase your reference

from learn-ocaml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.