3 ms·
Then you changed the semantics of the code. Now a program that e.g. prints a message in its destructor, which gives this output: Message 1 Message 2 Mess
by yakubin 6y ago
Then you changed the semantics of the code. Now a program that e.g. prints a message in its destructor, which gives this output:
Message 1
Message 2
Message 3
Will give this output:
Message 3
Message 2
Message 1
Your odd/even fix also won't work, because a function may push an argument to a list, and pass the list in another argument, making the original temporary accessible from any recursion level.
A call to a destructor is a normal call. If you need to call destructors, then it means your tail call is a call to a destructor and not what you're seeing in the code. It's a fundamental semantical problem. You can't have "make the last call in this function be an implicit call to some function" and "make the last call be the explicit call to this other function" at the same time.
- syrrim 6y agoIf it's a different syntax, then you can expect people to know that it's semantically different. That's the whole point of using a different syntax, I think.
- yakubin 6y agoI thought that the point of this syntax was to make the compiler warn you when, what you think is a tail call, in fact isn't one, and demand that the compiler optimizes it; not introduce a completely new control flow construct.
- im3w1l 6y ago> push an argument to a list, and pass the list in another argument, making the original temporary accessible from any recursion level. Either you push a copy of the object to the list, in which case it is fine. Or you push a pointer/reference to the object, in which case it becomes dangling.
- yakubin 6y agoExactly. It wouldn't be dangling without the transformation you proposed.