It's UWAweek 47

help2002

This forum is provided to promote discussion amongst students enrolled in CITS2002 Systems Programming.
Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.
Displaying the 4 articles in this topic
Showing 4 of 828 articles.
Currently 103 other people reading this forum.


 UWA week 36 (2nd semester, mid-semester break) ↓
SVG not supported

Login to reply

👍?
helpful
1:37am Thu 5th Sep, ANONYMOUS

How can we determine when a function body should end if not every function requires a return statement? The sample code with no return in the function body happens to end with a print statement, is this the only alternative to a return statement for ending a function body? Even so, how are we meant to determine this if multiple print statements are used within one function? (unless there has been a clarification I missed stating that only one print statement is permitted per function, apologies if so) Thanks


SVG not supported

Login to reply

👍?
helpful
7:59am Thu 5th Sep, Joshua N.

ANONYMOUS wrote:
> How can we determine when a function body should end if not every function requires a return statement? > > The sample code with no return in the function body happens to end with a print statement, is this the only alternative to a return statement for ending a function body? Even so, how are we meant to determine this if multiple print statements are used within one function? (unless there has been a clarification I missed stating that only one print statement is permitted per function, apologies if so) > > Thanks
There are no guarantees what the last statement in a function will be, it could return, it could print, or it could be another statement (the syntax of ml allows this). So, relying on seeing a particular statement to know if the function has ended isn't the right approach. The function ends when indentation ends. E.g. if the last line you saw had an indent, and the current line you are examining doesn't, then the function has ended.


SVG not supported

Login to reply

👍?
helpful
2:28pm Thu 5th Sep, ANONYMOUS

each statement in a function's body (one-per-line) is indented with a tab character So for this, we don't need to check if its indented and return a syntax error, we just say that if the line isn't indented then we aren't in a function anymore.


SVG not supported

Login to reply

👍?
helpful
3:27pm Thu 5th Sep, Joshua N.

ANONYMOUS wrote:
> each statement in a function's body (one-per-line) is indented with a tab character > > So for this, we don't need to check if its indented and return a syntax error, we just say that if the line isn't indented then we aren't in a function anymore.
Honestly it would be very hard to tell if a statement is meant to be in a function but it isn't. Since ml syntax allows statements to be inside or outside a function, there's no way of telling if they belong to a function if they aren't indented. The only statement you'd be able to know should be in a function is the return statement. Other than that, you just have to assume that if a statement isn't indented then it mustn't be part of the function.

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  8:08AM Aug 25 2024
Privacy policy