Calling a "hidden" function in octave

Calling a "hidden" function in octave

von Ana Ferraz -
Anzahl Antworten: 4

I would like to provide the students with a hidden function (they don't know the definition) but they are able to freely call the function in their script.

I can't find a way to write the function in the question editor. 

Is there a way to do this ? If yes, do you have an example? If not, do you have a walk around?

I am using some prototypes from ENCN305, auto-expected.

Als Antwort auf Ana Ferraz

Re: Calling a "hidden" function in octave

von Richard Lobb -
There are two or three ways of doing this, depending on what prototype you're usually using and on how experienced you are with CodeRunner.

  1. If you're happy to use the basic CodeRunner built-in function octave_function you could simply click Customise and insert the function you want to hide immediately after the {{ STUDENT_ANSWER }} line.
  2. Again if you're happy with the basic question type you could instead insert {{ QUESTION.globalextra}} into the template after the {{ STUDENT_ANSWER }} line and then insert the function you want into the question's Global Extra field. This is a more general approach and leads easily to creating a new question type that supports arbitrary hidden code, if you know how to create new question types.
    For an example see
    https://coderunner.org.nz/question/preview.php?id=11203&cmid=520
  3. Like the Octave built-in question type(s), the ENCN305 question types all pre-date the introduction of the Global Extra field, which is the best way to handle these problems. Editing these prototypes to use globalextra is a far more demanding task. So I quickly hacked the octave_only_305 question type to create a new question type octave_only_305b question type. This allows you to put hidden code in the Global Extra field, and then with a template parameter {"globalextra": "pretest"} to insert that code before the block of all the tests. You will need to download the new prototype (use at your own risk - it's almost entirely untested!) in order to use the example, which is: https://coderunner.org.nz/question/preview.php?id=11205&courseid=17
Als Antwort auf Richard Lobb

Re: Calling a "hidden" function in octave

von Ana Ferraz -
Thank you Richard for the prompt reply. I have tried both options and they work fine for function type of questions.
I wanted the student to write a full script not a function, and in this script use a hidden function (that might contain lines of code that the student haven't learned yet for example).
It seems that when I try to do this I get the message: "Parse error: expected line starting with "function". Is this valid code?"
Als Antwort auf Ana Ferraz

Re: Calling a "hidden" function in octave

von Richard Lobb -
If you're not too worried about the possibility that a sufficiently smart student can see the code of your function (by reading the current working directory) you should be able to just drop the .m file containing the function into the Support Files section of the question author form. All support files are copied into the current working directory on Jobe when the program runs, so MATLAB should just load it automatically when it's called, shouldn't it? Give it a go and let me know if it doesn't work. [I haven't used MATLAB for several years and I might be mis-remembering.]
Als Antwort auf Richard Lobb

Re: Calling a "hidden" function in octave

von Ana Ferraz -

It works, that's exactly what I needed. I will explore more the support files sections too

The function is "hidden" because is has complicated calculations that is not required for the students to know at this point. It's not a big issue if the student can see the code. So this works well, thank you.