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 2 articles in this topic
Showing 2 of 828 articles.
Currently 79 other people reading this forum.


 UWA week 37 (2nd semester, week 7) ↓
SVG not supported

Login to reply

👍?
helpful
3:43pm Tue 10th Sep, Harrison L.

Hello,

I've just posted another article, but thought I should separate these for clarity.

First of all, similar questions have already been asked in my article as well as this article by anon.

That is: If a function has been initialised with no return, if called in an expression is it invalid, or can we safely equate it to zero. Do all functions have a decimal return type with a default of zero, or are there also void functions?

Second of all, ML seems to be relatively strict about scope (see part 12 of "Our ml Language"):

"a function's parameters and any other identifiers used in a function body are local to that function, and become unavailable when the function's execution completes"

So, can a function modify variables defined above its scope? As in, in the ML code:

a <- 3

function dosomething
	a <- a + 2

print a

Will the output be 3, or 5? Can function dosomething modify the variable defined before it, or only use it as in sample 8?

Thank you.


SVG not supported

Login to reply

👍?
helpful
8:21pm Wed 11th Sep, Joshua N.

"Harrison Lisle" [email protected] wrote:

Hello,

I've just posted another article, but thought I should separate these for clarity.

First of all, similar questions have already been asked in my article as well as this article by anon.

That is: If a function has been initialised with no return, if called in an expression is it invalid, or can we safely equate it to zero. Do all functions have a decimal return type with a default of zero, or are there also void functions?

Second of all, ML seems to be relatively strict about scope (see part 12 of "Our ml Language"):

"a function's parameters and any other identifiers used in a function body are local to that function, and become unavailable when the function's execution completes"

So, can a function modify variables defined above its scope? As in, in the ML code:

a <- 3

function dosomething
	a <- a + 2

print a

Will the output be 3, or 5? Can function dosomething modify the variable defined before it, or only use it as in sample 8?

Thank you.

I believe it is fine to return zero if a function doesn't have a return value.

Amitava please respond to the second question.

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