[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #52980] clear in the caller workspace doesn't
From: |
Philip Nienhuis |
Subject: |
[Octave-bug-tracker] [bug #52980] clear in the caller workspace doesn't clear all references to a variable. |
Date: |
Sat, 27 Jan 2018 08:15:03 -0500 (EST) |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0 SeaMonkey/2.48 |
Update of bug #52980 (project octave):
Status: None => Need Info
_______________________________________________________
Follow-up Comment #1:
Are you sure this is a bug?
My interpretation is that you misunderstand how Octave works.
First you make an array V.
Then you call a function f() to operate on that array.
Now you apparently think that f(V) directly operates on V in the calling
scope. But that's not the way things work in Octave:
1. When you call a function along the lines of f(V), f() operates on its
*local copy* of V, not on V itself. In other words, Octave calls functions
with arguments by value, not by reference. If inside f() you change V, it'll
create a deep copy, so memory consumption doubles. That deep copy is returned
as the output of f(V), see below.
2. Any function always returns a value. That can be a scalar, an array,
struct, anything.
If you don't supply a return argument, Octave will put the outcome in the
default return argument, a variable called "ans".
So after calling f(V) you'll end up with two arrays:
* The original, untouched V
* ans, a copy of V with ans(1) having a value of 5
When you then clear V, obviously "ans" still exists.
That also happens if you call octave with "eval" as the same scopes (calling
and called) will be created.
Or, did I misunderstand you?
I'm tempted to close this bug report right now with "Invalid" but I'll await
your response.
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?52980>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/