It's UWAweek 52

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 5 articles in this topic
Showing 5 of 835 articles.
Currently no other people reading this forum.


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

Login to reply

👍?
helpful
5:56pm Thu 12th Sep, ANONYMOUS

also ignore the line starting with $, it is meant to be a #, apologies


SVG not supported

Login to reply

👍?
helpful
10:31pm Thu 12th Sep, Joshua N.

ANONYMOUS wrote:
> Hi, would the following code as a .ml file be syntactically valid? > > Additionally, can comments be indented with a '/t' outside of a function or will this cause an error? Chris has said randomly indented lines outside of a function is not permitted, but I am not sure if this applies to comments as well.
It does apply to comments. He made the change to make sure the project isn't too hard.
> This file also assumes that whitespace anywhere except at the start of the line is valid (therefore any line starting with a whitespace (even if it is a commented out line with just #), including any lines with whitespace before or after a '\t' character within a function, causes an error). > Could I please get a clear cut yes or no whether or not this is true instead of a link to another help forum post, I have read all of the posts regarding whitespaces and still am not certain if this is correct. The post that is always linked says 'Whitespace can only appear at the beginning of a line if it is a tab under a function definition' is true, but whitespace and tab are not the same thing so it is confusing.
>From Oxford English Dictionary:
"white space n. (a) Typography the blank areas of a page or other piece of printed matter, as margins, gutters between columns, etc., regarded collectively as an element of layout and design; (b) Computing (frequently as one word) blank space in electronic text produced by one or more keyed characters, as spaces, tabs, line-breaks, etc.; often attributive as whitespace character." The only allowed white space at the beginning of a statement is a single tab (if in a function body). Otherwise, white space is optional but not necessary. Except for key words like print, function, return where there should be at least one space between them and an expression.
> > ``` > # this file should print the following (only the numbers): > # 9 > # 16 > # 0 > # 2 > # 2.500000 > # 3 > # 1 > # > # > # > # additional whitespace except at the start of a line is valid (? still waiting on clarification ?)
Yes (however statements in a function must only start with a single tab)
> # 9 is printed > one <- 1 > # > function increment value > return value + one > # > print increment( 3 ) + increment ( 4 ) > # > # > # > # from [help2002] > # functions can call another function as a parameter > # 16 is printed > function printsum a b > print a + b > print printsum(increment( 5 ) , 10) > # > # > # > # variables do not need to be defined before being used in an expression, and are automatically initialised to the (real) value 0.0 > print d > # > # > # > $ from [help2002] > # functions do not need to end with a return or print statement, if there is no tab the function has ended > # variable reassignment is allowed > # 2 is printed > function none > one -> 2 > none( ) > print one > # > # > # > # comments can start in the middle of a line > # 2.500000 is printed > print 2.5 # comment > # > # > # > # from [help2002] > # 3 is printed then 1 is printed, since noreturn(1, 2) would return 0 > function noreturn x y > print x + y > print 1 + noreturn(1, 2) > ```
Only thing that might be invalid is:
> function none > one -> 2 > none( ) > print one > #
The "one" in the function would likely be a local variable, after the function ends it would likely not exist (and so 0 would be printed). I'm not sure if global variables can be accessed by functions in ml. It would be best to ask Amitava to clarify. Also, the arrow it the wrong way around.


SVG not supported

Login to reply

👍?
helpful
11:29pm Thu 12th Sep, ANONYMOUS

Thank you so much for clarifying! I unfortunately only just noticed the arrow typo, apologies. I will wait for Amitava to clarify regarding the global variables query, thanks again!


SVG not supported

Login to reply

👍?
helpful
3:30pm Fri 13th Sep, Amitava D.

ANONYMOUS wrote:
> Hi, would the following code as a .ml file be syntactically valid? > > Additionally, can comments be indented with a '/t' outside of a function or will this cause an error? Chris has said randomly indented lines outside of a function is not permitted, but I am not sure if this applies to comments as well. > > This file also assumes that whitespace anywhere except at the start of the line is valid (therefore any line starting with a whitespace (even if it is a commented out line with just #), including any lines with whitespace before or after a '\t' character within a function, causes an error). > Could I please get a clear cut yes or no whether or not this is true instead of a link to another help forum post, I have read all of the posts regarding whitespaces and still am not certain if this is correct. The post that is always linked says 'Whitespace can only appear at the beginning of a line if it is a tab under a function definition' is true, but whitespace and tab are not the same thing so it is confusing. > > > ``` > # this file should print the following (only the numbers): > # 9 > # 16 > # 0 > # 2 > # 2.500000 > # 3 > # 1 > # > # > # > # additional whitespace except at the start of a line is valid (? still waiting on clarification ?) > # 9 is printed > one <- 1 > # > function increment value > return value + one > # > print increment( 3 ) + increment ( 4 ) > # > # > # > # from [help2002] > # functions can call another function as a parameter > # 16 is printed > function printsum a b > print a + b > print printsum(increment( 5 ) , 10) > # > # > # > # variables do not need to be defined before being used in an expression, and are automatically initialised to the (real) value 0.0 > print d > # > # > # > $ from [help2002] > # functions do not need to end with a return or print statement, if there is no tab the function has ended > # variable reassignment is allowed > # 2 is printed > function none > one -> 2 > none( ) > print one > # > # > # > # comments can start in the middle of a line > # 2.500000 is printed > print 2.5 # comment > # > # > # > # from [help2002] > # 3 is printed then 1 is printed, since noreturn(1, 2) would return 0 > function noreturn x y > print x + y > print 1 + noreturn(1, 2) > ```
You should make simplifying assumptions, and clearly write those assumptions in your report. I am not sure whether a report was required in the original project description, but you can submit a report that lists all the assumptions you have made.


SVG not supported

Login to reply

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

In the submission requirements it says the following: Submit only a single C11 source-code file named runml.c Do not submit any header-files, documentation, instructions Is this going to be changed so a report can also be submitted? If so, would it be appropriate to include code examples of errors along with the syntax assumptions 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