Is it possible to create a function that works on a block scope? Such as
Edited to clarify
enum { cannot, must };
int it(enum modal verb);
describe(fx) {
context("some context") {
it(must) { /* Some test that returns an int to it() */ };
}
}
I doubt this is possible so what is the next best thing I can do?
This looks almost like Smalltalk or Ruby to me, which makes me think you want to pass closures (sometimes called blocks) to functions. This is possible with various extensions to C, and there are also workarounds.
For example, maybe you want to iterate over a list:
If you are using Apple’s extensions to C, you can use something called “blocks”
You can also write a callback,
Callbacks can’t access variables in scope in other functions, so you have to figure out a way to share variables.
And there are nested functions in GCC; these have access to scoped variables just like Apple’s “blocks” extension.
If you find yourself wanting to do this a lot, you may save yourself a lot of headache by switching to a language other than C. C is not very friendly for higher-order programming.