octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

namespaces, etc.


From: Przemek Klosowski
Subject: namespaces, etc.
Date: Tue, 29 Jan 2008 13:46:03 -0500 (EST)

This posting is inspired by a recent request from the help list, asking
for a way to load into octave variables that are named at runtime. The
orginal idea was to eval([varName '=' varValue]), and I suggested using

        myVars.(varName)=varValue

I commented that this looks like a namespace, and then I spoke to Paul
Kienzle and we came up with the idea that this technique is useful to
import foreign namespace into local function symbol table, like so:

function y=f(myVars,x)  <-- pass the 'namespaced' variables, or use a global var
 for [val,key]=myVars
   eval([key '=' val])
 endfor

i.e. make a caller-defined related variables available in local
variables of the function. The problem with the above approach is that
it doesn't work out the box: val is a numerical object, and needs to
be massaged before the eval() argument is concatenated: eval([key '='
num2str(val)]), or even something more complex for array values.

Paul suggested that things like that would simplify if the local
symbol table could be accessed as a struct:

                function y=f(myVars,x)
                 for [val,key]=myVars
                   __locals__.(key) = val;
                 endfor
or even
                __locals__ = myVars

Anyway, I thought it is an interesting idea, which would simplify
moving state variables into and out of subroutines. Maybe even it
could be useful in some way for your properties database in the
graphics subsystem? I haven't even began looking at the implementation
issues--I am just sending this for a reality check.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]