Open ironstrider opened 9 years ago
So obviously the static analysis is only counting the number of arguments in the last lambda expression. It's probably too hard in the analysis to try and track which lambda function actually gets returned (it might even be impossible).
Probably the best solution is to add an extra check to the analysis to first give an error if there is more than one lambda function defined. It would still cause this answer to be marked wrong even when the code behaves correctly, but the error message would be more accurate. (I'm mostly in favour of this, since the student should be able to recognise and remove the redundant code, especially this late in the semester.)
I agree - and maybe the question should perhaps say that a single lambda terms is required
It actually wouldn't be too hard to track which lambda is returned (if the lambda is returned directly, it is a property of the return node; else, it would/should/could be in .assigned_value) but I agree that it's not worth the effort.
I reckon just error out if there's more than one lambda. (Even a generic error on any question where there's code after the return statement could be useful.)
I would prefer not to say that a single lambda term is required in the question; better to have students work that out themselves (with the analyser prodding them as required).
On 25 May 2015 at 09:52, Peter Robinson notifications@github.com wrote:
I agree - and maybe the question should perhaps say that a single lambda terms is required
— Reply to this email directly or view it on GitHub https://github.com/CSSE1001/MyPyTutor/issues/163#issuecomment-105080143.
OK - fair point - making it an error to have code after return would be fine - what about
if some_test: return lambda x,y: ... else: return lambda x: ...
My proposed fix is to count every lambda expression in the whole function, regardless of return values. So that example should count as two, and give the error "You only need to define one lambda function".
Static analysis incorrectly detects the following as erroneous (due to erroneous code after return):