Examples of structure passing in Icon |
|
Here are some small programs that illustrate passing data structures to Icon procedures:
procedure main()
L := [ 1, 2, 3 ]; # Set L to a list of 3 small integers
Change_All ( L ); # This procedure does not affect L
every write ( ! L ); # Display the values of L
Change_One ( L ); # This procedure changes the first element of L
every write ( ! L ); # Display the values of L
end
procedure Change_All ( foo ) # This does not affect the caller's foo...
foo := 86; # ...because we are not changing...
end # ...a PART of an aggregate
procedure Change_One ( foo ) # This procedure affects the caller's foo...
foo[1] := 99; # ...because we are changing...
end # ...a PART of an aggregate