IsmAvatar
LateralGM Developer
 Joined: Apr 2008
Posts: 877
|
 |
Reply #15 Posted on: January 08, 2011, 12:00:49 AM |
|
|
|
Suppose f1 and f2 return 0, and obj2.array[0,0] = 0.
The statement would be equivalent to the following: obj1.a = 0;
As you can see, I'm totally lost, which is why someone needs to explain this one to me.
|
|
|
RetroX
Master of all things Linux
 Joined: Apr 2008
Posts: 1,055
|
 |
Reply #16 Posted on: January 08, 2011, 01:54:16 AM |
|
|
|
It would be expansion hell.
Now, that makes sense, I guess.
with() will do what it will, I suppose.
|
|
|
RetroX
Master of all things Linux
 Joined: Apr 2008
Posts: 1,055
|
 |
Reply #17 Posted on: January 08, 2011, 01:55:20 AM |
|
|
Quote from: IsmAvatar on January 08, 2011, 12:00:49 AM Suppose f1 and f2 return 0, and obj2.array[0,0] = 0.
The statement would be equivalent to the following: obj1.a = 0;
As you can see, I'm totally lost, which is why someone needs to explain this one to me.
f1() is performed for all objects, f2() is performed for objects, and set to a for all objects. It would be expansion hell, and really, in the end, the last one executed would actually be stored. That's why it's a bad idea to make one variable operate on multiple objects.
|
|
|
polygone
 Joined: Mar 2009
Posts: 794
|
 |
Reply #18 Posted on: January 08, 2011, 12:02:47 PM |
|
|
Quote from: IsmAvatar on January 08, 2011, 12:00:49 AM Suppose f1 and f2 return 0, and obj2.array[0,0] = 0.
The statement would be equivalent to the following: obj1.a = 0;
As you can see, I'm totally lost, which is why someone needs to explain this one to me.
As RetroX has just said, because what if there are multiple instances of obj1 and obj2? You can't run things so straight then. f1 and f2 might return different values depending on the instance it was executed with. RetroX has stated as a solution: Quotein the end, the last one executed would actually be stored But to me this is really not nice and I don't think it is a viable solution. Which is why I mentioned previously: obj.a = obj.f1();People would naturally expect this to work like: with (obj) { a = f1(); }But it would instead work like: global var ______ENIGMATEMP; with (obj) { ______ENIGMATEMP = f1(); } with (obj) { a = ______ENIGMATEMP; }
|
|
|
r9k
 Joined: Aug 2010
Posts: 25
|
 |
Reply #19 Posted on: January 08, 2011, 01:57:17 PM |
|
|
Quote from: polygone on January 08, 2011, 12:02:47 PM
Quote from: IsmAvatar on January 08, 2011, 12:00:49 AM Suppose f1 and f2 return 0, and obj2.array[0,0] = 0.
The statement would be equivalent to the following: obj1.a = 0;
As you can see, I'm totally lost, which is why someone needs to explain this one to me.
As RetroX has just said, because what if there are multiple instances of obj1 and obj2? You can't run things so straight then. f1 and f2 might return different values depending on the instance it was executed with.
RetroX has stated as a solution:
Quotein the end, the last one executed would actually be stored But to me this is really not nice and I don't think it is a viable solution. Which is why I mentioned previously:
obj.a = obj.f1(); People would naturally expect this to work like:
with (obj) { a = f1(); } But it would instead work like:
global var ______ENIGMATEMP; with (obj) { ______ENIGMATEMP = f1(); } with (obj) { a = ______ENIGMATEMP; }
There are no ______ENIGMATEMP. The parser will just convert "obj." to enigma_varaccess and everything will be as fast as a c++ member function call and assignation.
|
|
|
Josh @ Dreamland
Prince of all Goldfish
 Joined: Feb 2008
Posts: 2,950
|
 |
Reply #20 Posted on: January 08, 2011, 04:22:38 PM |
|
|
|
Unfortunately, r9k, it's not that simple. It's not as simple as polygone's suggestion, either. The only way to implement this cleanly is too flawed to implement:
obj1.func()
becomes
(enigma::with_iter(obj1), func())
When the expression starts, it will be as though it was executed for obj1. When the expression ends, the with_iter will destruct, and the code will be back in its original scope. However, this will fail catastrophically:
obj1.func(obj2.func())
Both will be executed for obj2. This is because at the beginning of the expression, obj1 is pushed as the current instance, then obj2 is as well.
I haven't yet found a way around this.
|
|
|
RetroX
Master of all things Linux
 Joined: Apr 2008
Posts: 1,055
|
 |
Reply #21 Posted on: January 08, 2011, 05:51:20 PM |
|
|
|
Polygone, I wasn't suggesting any solution. I was mentioning what would actually happen.
I think that, like obj.x, obj.func() should only operate on one instance.
|
|
|
luiscubal
 Joined: Jun 2009
Posts: 452
|
 |
Reply #22 Posted on: January 08, 2011, 06:36:01 PM |
|
|
|
Perhaps you should have with_iter use some sort of stack?
(enigma::push_with(obj1), func(enigma::push_with(obj2), func(), enigma::pop_with()), enigma::pop_with());
|
|
|
RetroX
Master of all things Linux
 Joined: Apr 2008
Posts: 1,055
|
 |
Reply #23 Posted on: January 08, 2011, 10:33:38 PM |
|
|
|
That was actually what he mentioned doing, I believe.
|
|
|
Josh @ Dreamland
Prince of all Goldfish
 Joined: Feb 2008
Posts: 2,950
|
 |
Reply #24 Posted on: January 09, 2011, 05:41:29 AM |
|
|
|
That's how with_iter works, luis. Issue is, you just passed func() the return value of enigma::pop_with().
|
|
|
luiscubal
 Joined: Jun 2009
Posts: 452
|
 |
Reply #25 Posted on: January 09, 2011, 01:09:54 PM |
|
|
|
I see. What about:
(enigma::push_with(obj1), enigma::pop_with((enigma::push_with(obj2), enigma::pop_with(func())))) where pop_with(K) returns K.
If with_iter is already a stack, then I don't see how "obj1.func(obj2.func())" would fail. After all:
(enigma::with_iter(obj1), func((enigma::with_iter(obj2), func()))) The inner func is called after obj2 is pushed to the stack, and before it is poped, so it is applied to obj2 alone, the top() of the stack(assuming a STL stack) The outer func is called after obj1 and obj2 are pushed to the stack, but obj2 was already poped, so obj1 is the top() of the stack and therefore func() is applied to obj1 alone.
So I think it would work. That is, unless C++ sequence points are playing tricks on me.
|
|
|
Josh @ Dreamland
Prince of all Goldfish
 Joined: Feb 2008
Posts: 2,950
|
 |
Reply #26 Posted on: January 09, 2011, 06:12:24 PM |
|
|
|
The stack is pushed twice at the beginning of the expression in my example, then popped twice right after.
pop_with(K) was what I was considering. But it wasn't until you posted it again that I realized I was thinking about it incorrectly. My first instinct was that there'd be no way to instantiate a template because the return type of func() can't be gathered from &func. But now I see that a simple template function would have done it.
inline template<typename any> any& pop_with(any &r) { return r; }
So thank you, Luis; the simplicity of the matter escaped me.
|
|
|
|