Oh dear, am I tired. (I made some pretty silly test mistakes a few weeks ago, also. Always read the questions in detail, folks![1])
I will say this, however: The functional programming I'm learning about (not what I had a test in) seems to be coloring my thoughts pretty significantly at the moment, because I used some of today's time wondering how to make a C-alike language that would support a more functional style... and I came up with odd syntax like
void foo(int x, int y) = { cout << x << ", " << y << endl; }
("And all functions are simply variables in the global scope") and
void bar() = {
void foo(int a) = { return(a + 1); }
int an_array[3] = {1, 2, 3};
// increments every element in an_array by 1.
imperative_map(an_array, foo, 3);
for (int i = 0; i < 3; ++i) {
cout << a_list[i] << endl;
}
}
But there might be a language that does this already. Though to be powerful enough, this hypothetical C variant should also support type inference, so that higher order functions like imperative_map can work on any and all types. Either that, or it's typename time!
Er, yeah.
[1] And most definitely don't just skim the question and read "a mapping from [1,2] x [1,3]" as "a mapping from [1,2] x [0,3]". That just won't do! Not to mention that on a multiple choice test, every wrong answer is equally wrong.
This entry was originally posted at
http://davv.dreamwidth.org/44772.html. You may comment there using OpenID, or comment here if you prefer.