It's UWAweek 44 (2nd semester, 1st exam week)

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


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

Login to reply

👍?
helpful
11:01am Fri 6th Sep, Chenjun H.

Hi,

Just a few questions about functions: What should happen if a top level variable shares the same name as a function? Is this disallowed by ml like it is in C?

Also, is it possible to pass a function as a parameter to a function, if it is, how would we implement this?

Thanks in advance.


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

Login to reply

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

"Chenjun Hou" [email protected] wrote:

Hi,

Just a few questions about functions: What should happen if a top level variable shares the same name as a function? Is this disallowed by ml like it is in C?

Identifiers and functions shouldn't have the same name.

Also, is it possible to pass a function as a parameter to a function, if it is, how would we implement this?

Syntax of ml allows this. You should be able to just copy the function call into c and it would work.

Thanks in advance.


SVG not supported

Login to reply

👍?
helpful
8:49pm Fri 13th Sep, Chenjun H.

By passing a function as a parameter to another function, I mean

function exec a
    return a()
#
function seven
    return 7
#
print exec(seven)

Here we pass the function seven to the function exec as its a parameter, and the ``exec``` function executes it, ultimately resulting in 7 being printed.

Is this behavior allowed in ml? If it is, how do we get around c's function type checking? I believe that to pass a function to a function, its necessary to create a function pointer like so void func ( void (*f)(int) );.

Also with respect to functions with the same name, should we assume it never happens or check it?


SVG not supported

Login to reply

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

"Chenjun Hou" [email protected] wrote:

By passing a function as a parameter to another function, I mean

function exec a
    return a()
#
function seven
    return 7
#
print exec(seven)

Here we pass the function seven to the function exec as its a parameter, and the ``exec``` function executes it, ultimately resulting in 7 being printed.

Is this behavior allowed in ml? If it is, how do we get around c's function type checking? I believe that to pass a function to a function, its necessary to create a function pointer like so void func ( void (*f)(int) );.

Also with respect to functions with the same name, should we assume it never happens or check it?

No ml doesn't allow passing a function to a function. It is too complex for this project, and I don't believe it will be covered in the unit.

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