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 75 other people reading this forum.


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

Login to reply

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

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 https://secure.csse.uwa.edu.au/run/help2002?p=np&opt=U290
# 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 https://secure.csse.uwa.edu.au/run/help2002?p=np&opt=U263 
# 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 https://secure.csse.uwa.edu.au/run/help2002?p=np&opt=U240
# 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)

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