Understood. I was exaggerating the situation here to give a simple example. It wasn't so simple in the program I was working on.
But I've been thinking more about it and realized that MATLAB's rules give a semi-functional environment. That is, in general functions have no side effects. Maybe obvious, but thinking of it from that perspective helped me. So, within a local context, MATLAB isn't functional, but in the larger scale, it is (sort of).
I'm also ignoring globals for the moment, since globals are obviously evil, anyway.
So, I might forgive MATLAB and learn to get more in the groove. Just that deeply nested data structures (which I happened to be working with) take some additional thought.
In MATLAB, almost everything is "by value" instead of "by reference". That is, if you say "a = b", and then change b, a will stay the same.
ReplyDeleteIn this particular example, you can just index in there directly:
items{i}.whatever='something';
Understood. I was exaggerating the situation here to give a simple example. It wasn't so simple in the program I was working on.
ReplyDeleteBut I've been thinking more about it and realized that MATLAB's rules give a semi-functional environment. That is, in general functions have no side effects. Maybe obvious, but thinking of it from that perspective helped me. So, within a local context, MATLAB isn't functional, but in the larger scale, it is (sort of).
I'm also ignoring globals for the moment, since globals are obviously evil, anyway.
So, I might forgive MATLAB and learn to get more in the groove. Just that deeply nested data structures (which I happened to be working with) take some additional thought.
MATLAB, like any other language, has its fair share of quirks.
ReplyDeleteI suspect it was designed to be mostly functional with strict evaluation for simplicity, especially for people who aren't "programmers".