-1

Say you need to store the name of all local variables in a script: local = union(who,"local"). Is there a function to replace the name ("local") with a reference to the variable which is to the left of the expression?

Update: For the sake of clarity, the sentence will be rewritten like local = union(who, leftside()), where the leftside function returns local.

Is there a sort of leftside() function with this behavior?

nightcod3r
  • 752
  • 1
  • 7
  • 26
  • Is there a reason why you can't simply use the code you have in your question? – stephematician Oct 29 '16 at 04:15
  • There's no specific reason to use it, but it creates a dependency that I would like to get ride of. Also because I love this kind of metainstructions that Octave is equipped with. – nightcod3r Oct 29 '16 at 10:17
  • I'm not aware of any such leftside() function. The documentation on the assignment operator (=) doesn't offer any insight either. – stephematician Oct 29 '16 at 11:13

1 Answers1

0

Do you mean like this?

>> a = "test"
a = test
>> b = "rest "
b = rest
>> a = union(b,  a)
a =  erst
>> help union
'union' is a function from the file C:\Octave\Octave-4.0.3\share\octave\4.0
.3\m\set\union.m

 -- Function File: C = union (A, B)
 -- Function File: C = union (A, B, "rows")
 -- Function File: [C, IA, IB] = union (...)

 Return the unique elements that are in either A or B sorted in
 ascending order.

Update:

I'm not aware of such function. There are bunch of built in functions for internal use, that have the names like __func_name__ and you may get a list of them if you type __ in the Octave's command window and press tab twice. At a glance I don't think there is a function, like the one you need, but take a more detailed look if you like.

Can you describe why do you need such behavior, maybe there is a different approach that can suit your needs i.e there are functions for programmatic creation of variables - genvarname.

Iliyan Bobev
  • 3,070
  • 2
  • 20
  • 24