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


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

Login to reply

👍?
helpful
8:48am Tue 3rd Sep, Daniel J.

If we pass a function into another function as an argument, is it expected that we can call it, or should it be treated as an un-declared variable, ie 0?
function add a b
    return a + b()

function two
    return 2

print add 1 two
Should this produce 3, or should this be a syntax error (cannot call literal)?


SVG not supported

Login to reply

👍?
helpful
8:51am Tue 3rd Sep, Daniel J.

For clarification, it should be print add(1, two) I should read things more carefully.


SVG not supported

Login to reply

👍?
helpful
12:56pm Tue 3rd Sep, Mark LN.

Instead of passing a function to another function, the first function can just be evaluated in the parameter expression like this:

function add a b
	return a + b
#
function two
	return 2
#
print add(1, two())


SVG not supported

Login to reply

👍?
helpful
1:51pm Tue 3rd Sep, Daniel J.

Thanks, I understand that is an option, but I do want to know whether the language actually permits passing references to functions, because the syntax guide suggests it does, and the language description doesn't seem to forbid it.


SVG not supported

Login to reply

👍?
helpful
8:38pm Tue 3rd Sep, Mark LN.

Yup sure - now you got me thinking about adding that as well! Shouldn't be too hard I guess...

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