Steve Wampler wrote:
> And if you do, be sure to dereference the result appropriately, since
> Icon/Unicon doesn't dereference non-locals on procedure return:
>
>     prod := .value(2) * value(3)
>     write(prod)           # writes: 6, as you'd expect
> Incidently, the 'proper' fix would be to explicitly dereference
> before returning from the procedure, as in:
>     procedure value(k)
>         static result
>        result := k
>        return .result
>    end
>Even though this shouldn't be needed...

While dereferencing works for simple variables, you are still in a mine 
field with static structures as in:

diag2 := diagonal(2)
diag3 := diagonal(3)
write(diag2[1][1] * diag3[1][1])  # writes 6 as hoped
...
y := diagonal(3)
y[1][1] := 2
write(diag3[1][1])   # writes 2 not 3

procedure diagonal(k)
local result
static last_result, last_k
initial {
   last_k := 0
   last_result := [[0,0],[0,0]]
}

if k = last_k then {  #Nothing to do
   return .last_result
}

last_k := k

# Imagine lots of cycles here leading to:

result := [[k,0],[0,k]]
last_result := result

return .result
end

Charles Davis
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Unicon-group mailing list
Unicon-group@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to