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


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

Login to reply

👍?
helpful
5:12pm Fri 6th Sep, Zexu D.

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!


SVG not supported

Login to reply

👍?
helpful
5:16pm Fri 6th Sep, Zexu D.

Also, should i initalise automatically a new identifier when it appears in an expression?


# a doesn't appear before

(add(1, 2) + call(1, a))


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.


SVG not supported

Login to reply

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

"Zexu Ding" [email protected] wrote:

Also, should i initalise automatically a new identifier when it appears in an expression?


# a doesn't appear before

(add(1, 2) + call(1, a))

You can do that if you want but I think the easiest way is to replace a with 0.0 if it doesn't match any identifier stored.


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

Login to reply

👍?
helpful
4:14pm Thu 12th Sep, ANONYMOUS

Since the same identifier name can't be reused / its a local variable being called outside of its scope shouldn't this cause an error?


SVG not supported

Login to reply

👍?
helpful
9:13pm Thu 12th Sep, Joshua N.

ANONYMOUS wrote:

Since the same identifier name can't be reused / its a local variable being called outside of its scope shouldn't this cause an error?

Why can't the same identifier name be reused? After the function ends the program would believe it is seeing the identifier for the first time and so would initialize it to 0.


SVG not supported

Login to reply

👍?
helpful
10:38pm Fri 13th Sep, ANONYMOUS

This assumption was based off 'you cannot introduce a new function if its name is already used as a variable's name, or introduce a new variable if its name is already used as a function's name.' from https://secure.csse.uwa.edu.au/run/help2002?p=np&opt=U151 and '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'.

I must've misunderstood the meaning of 'becomes unavailable', is the correct rules that only function identifiers must be wholly unique, variables can be reassigned within their scope, and any local identifiers (function parameters + identifiers used in a function body) can be assigned/used as 'new' variables outside of their scope?

Thank you for all of the help!


SVG not supported

Login to reply

👍?
helpful
10:43pm Fri 13th Sep, ANONYMOUS

https://secure.csse.uwa.edu.au/run/help2002?p=np&opt=B388&year=2024 do we instead follow this and not allow any duplicate names of variable reassignment now??


SVG not supported

Login to reply

👍?
helpful
7:09am Sat 14th Sep, Joshua N.

ANONYMOUS wrote:

https://secure.csse.uwa.edu.au/run/help2002?p=np&opt=B388&year=2024 do we instead follow this and not allow any duplicate names of variable reassignment now??

Yes, otherwise if you have already done it Amitava said you can state the assumptions you made in a file. So, you can do either, just state what assumption you made.

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