It's UWAweek 42 (2nd semester, week 12)

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 selected article
Showing 1 of 738 articles.
Currently 194 other people reading this forum.


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

Login to reply

👍?
helpful
5:25pm Fri 6th Sep, Joshua N.

"Zexu Ding" [email protected] wrote:

Hello,

How am I supposed to treat new identifiers? As mentioned, a new identifier doesn't need to be initialised explicitly, however, at the same time, the variable will be invisible out of the function area. So should I treat a as a new variable with a default value of 0 or report an error

function test
    a <- 1
# 
print a

Thx!

Hi Zexu,

"7.variables do not need to be defined before being used in an expression, and are automatically initialised to the (real) value 0.0"

"12. 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"

My interpretation of rules 7 and 12 is since a was defined in the local function, a is no longer available when the function ends, so when a is used outside the function it is treated as a new parameter so it will be 0.0.

In other words, a it would be 0.

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