Parameter Passing: Difference between revisions

Line 167:
}
call kappa
</syntaxhighlight>
 
Array items is a special case. Because arrays are objects which hold the actual array, we can pass an array item by reference and interpreter use a copy in/copy out method, so we actually get the value of array item in a local value (the parameter) and at the exit from call, interpreter feed the array back (if the array item exist, because we can pass the array and deallocate items, reducing the length of array). We can't pass by reference array items to subs and simple functions (these two structures are light versions, which didn't have logic to do something for this).
 
<syntaxhighlight lang="m2000 interpreter">
module checkArr (m){
dim arr(10) as long=10
module kappa (&x as long, &a(), m) {
dim a(m)
x++
}
kappa &arr(3), &arr(), m
try ok {
print arr(3)=11
}
if not ok then print "nothing to show"
}
checkArr 2 ' nothing to show
checkArr 5
Module checkArr (m){
function kappa(&x as long, &a(), m) {
dim a(m)
x++
}
dim arr(10) as long=10
kk=kappa(&arr(3), &arr(), m) // this call use new stack of values.
// call kappa(&arr(3), &arr(), m) // you can use call kappa() also, passing the current stack of values, like module's call.
try ok {
print arr(3)=11
}
if not ok then print "nothing to show"
}
checkArr 2
checkArr 5
</syntaxhighlight>
 
404

edits