Because of the fact that there are no pointers in matlab, I am relying on inputname() for grabbing the input, output variable names, and function names, along with using f handles. I'm experimenting with different (command line) user interfaces for this purpose, and currently settled on this :
a = intel_pipe;
a.f(a.o(o1,o2),@f1,a.i(i1,i2));
here i1,i2 are input variables, o1,o2 are output variables, and f1 is a function.
function i_vars = i(obj,varargin)
exec_comm_script;
i_vars = obj.add_vars(args);
end
function o_vars = o(obj,varargin)
exec_comm_script;
o_vars = obj.add_vars(args);
end
exec_comm_script.m :
strerror = 'arguments cannot be expressions';
nvarargs = length(varargin);
nconstargs = 1;
args = zeros(1,nvarargs);
for ii=1:nvarargs
varn=inputname(nconstargs+ii);
if isempty(varn)
error(strerror);
end
args(ii)=varn;
end
When I execute this, it works fine if debugging, but crashes unfailingly if not debugging. When, however, I paste the contents of the script into both the functions, (duplicating the content, it works fine.
What's going on?
------------------------------------------------------------------------------
Note : As expected I am using evalin and assignin here, but I really don't see any way to do this kind of thing other than to use matlab's reflection abilities. The important thing here is that this is meant to be used with large data that takes time to compute. Hence I cannot afford to keep copies of data, and hence evalin('base','...'); is a must.
I am also checking for empty names and disallowing expressions in the input and output arguments because it defeats the purpose of deferring execution in input, and is invalid anyway in the output.
You could say I should be asking the users to enter variable name strings in the first place, but then it would become my responsibility to check if the variable exists etc, instead of the interpreter's. Plus it's really ugly and irritating for the user.
0 Comments
Sign in to comment.