All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
int x;
when(x==0)
{
do_something();
}
x=procedure1();
x=procedure2();
/* at some point x becomes 0 *
* At that point do_something(); is called. *
* That way you don't need to specify *
* that if statement after every function call */
One place? Automatic dying:
1) The when call is made for (x==0)
2) 'x=procedure();'. If it fails, it returns 0. Then when(x==0) is satisfied and the program exits.
I see where you are coming from, syntactically. But it would be a nightmare.
INTERCAL, a programming language designed for incomprehensability, has a "COME FROM" construct. What you are suggesting here is a conditional "COME FROM anywhere".
When should the condition be tested for? After each statement? At each execution point, even?
Changing variables in such a construct... the implied ban on optimization wherever such a "when ()" is in effect...
And at the end of the day it isn't even that useful IMHO.
Every good solution is obvious once you've found it.
Looks somewhat like an event/callback thingy to me, this could be implemented with no problems in c++ (in fact, it's done quite often already). But if you are really after error checking in the first place - what's the big deal with adding a condition check after each function invokation? If you are lazy in writing (which is absolutely ok), use the preprocessor.
In aspectJ I could create joinpoints around writes to x, then consequently check from there.
In all other languages, I would write a get and set function instead.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
int x = 5;
if (fork()==0) {
while (x!=0);
printf("x is zero\n");
return 0;
}
sleep(5);
x = 0;
Unfortunately fork() clones an address space, so the change in x would never be propagated between the processes. Nice try though. Possibly clone() would work better, but you still have the atomicity problem.