CO538 Anonymous Questions and Answers Keyword Index |
This page provides a keyword index to questions and answers. Clicking on a keyword will take you to a page containing all questions and answers for that keyword, grouped by year.
To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers.
Keyword reference for value
2011 |
Submission reference: IN2089
In Question 55 (2011), you wrote:
"From the software engineering principle of cohesion, your move process should just move the rover, reporting back its success and distance moved through reference data parameters. It should not have the additional responsibility of reporting that result back to mission control (which it currently does via the opr.resp channel). The latter should be done separately by whatever has invoked the move. In this way, you will be able to reuse this move code for other purposes – e.g. for Task 4."
I'm not quite sure what you mean by "reference data parameters", please could you explain?
See basics slides 37, 67 and 68. The parameter result is a reference data parameter and, in this example, is expected to be set by the code within the body of the foo process before that terminates. When foo is invoked, an INT variable must be supplied as its third argument (slide 68) – anything the foo code does with result will actually be done to the variable supplied. See also this relevant bit from the occam-pi Reference wiki (which is linked from the "Practical Resources" box on the Moodle page for this course).
In this way, occam-pi PROCs can return results (plural: there can be any number of reference parameters), as well as interact with their environments (through channel communications, barrier syncs etc.). [Aside: occam-pi FUNCTIONs also return results (plural), but they are not allowed side-effects (e.g. interacting with their environments).] For the example provoking this discussion, your move process could have a reference boolean parameter (for success) and a reference integer (for distance).
Revision: VALue data parameters cannot be changed by their PROC body (i.e. they are constants). Supplied arguments may be variables, constant literals or expressions (basics slides 37and 67).
Constant literals or expressions may not, of course, be supplied as arguments for reference parameters.
Also, the answer to Question 57 (2010) is highly relevant to this question – so, do check this as well. The question in Question 57 (2010) may be best ignored!
Final note: better than reference parameters for returning PROC results are RESULT parameters. RESULT parameters are new in occam-pi, not in any course materials and, of course, not examinable. However, they are very simple, easy to use and improve security – see Question 58 (2010) and (the end bit of) Question 60 (2010).
Keywords: mars , parameter , reference , value , result
Referrers: Question 58 (2011)
2007 |
Submission reference: IN1461
Can processes return a value without the use of a channel?
Sure. If a PROC
has reference (i.e. non-VAL
)
data parameters and (if) it terminates, whatever has been assigned to those
parameters will have actually been assigned to the variables passed as arguments
to the call.
If a PROC
only has data parameters (both reference
and VAL
) and is generally used in SEQ
uence with other
processes, it is being used like a procedure (in Pascal), a function
(in C) or a method (in Java).
Keywords: parameter , reference , value
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. |