1. EURXSC -- Euphoria Routine Exit Status Code idea
- Posted by Aveu Sep 24, 2012
- 1134 views
I have an idea for a new feature for the next major release of Euphoria.
At its heart the idea is nothing more than to create a new built-in global variable (which would be a reserved identifier) that can be R/W accessed by any routine. For purposes of discussion I am suggesting the variable be coded as
global object EURXSC
Beyond that basic idea would be optionally/gradually adding some simple coding to some of the various librar routines so as to take advantage of that variable.
How this variable is used is up to the individual library coders (which is why I suggest it be an object rather than an integer) and it would also be those same coders' responsibility to clear the variable at the top of their routines. Any routine that does not use (ignores) this variable would not be required to clear it, however users should be warned in the documentation that EURXSC would be meaningless in such cases.
Here is a hypothetical example of how this might be used:
8.16.4.7 add_item
include std/sequence.e namespace stdseq public function add_item(object needle, sequence haystack, integer pOrder = 1)
Adds an item to the sequence if its not already there. If it already exists in the list, the list is returned unchanged.
Parameters:
- needle : object to add.
- haystack : sequence to add it to.
- pOrder : an integer; determines how the needle affects the haystack. It can be added to the front (prepended), to the back (appended), or sorted after adding. The default is to prepend it.
Returns:
- A sequence, which is haystack with needle added to it.
- The Routine Exit Status Code will be set as follows:
- If needle was successfully added to haystack then EURXSC = 0
- If needle was already part of haystack then EURXSC = 1
- If needle was not already part of haystack and also failed to be added then EURXSC = -1
2. Re: EURXSC -- Euphoria Routine Exit Status Code idea
- Posted by CoJaBo2 Sep 24, 2012
- 1129 views
This has to be one of the bigger kludges of the C programming language- why introduce it to Eu? (unless you like explaining to the user why their email keeps telling them they are not a typewriter...) If anything, we'd want something modern, like exceptions..
This also seems like a particularly bad example- If you want to see if the sequence contains the object, why not just search for it before adding it, rather than checking an error code from an unrelated routine?
3. Re: EURXSC -- Euphoria Routine Exit Status Code idea
- Posted by Aveu Sep 24, 2012
- 1098 views
If anything, we'd want something modern, like exceptions..
I would be fine with "something modern" in principal but I was thinking in terms of a generic solution that would not add any unnecessary processing overhead to the main language engine. I suspect only a small fraction of the existing library routines would even want to take advantage of this feature.
If you want to see if the sequence contains the object, why not just search for it before adding it, rather than checking an error code from an unrelated routine?
Perhaps because I really don't want to "see if the sequence contains the object".
I want to see if a particular library routine (add_item was just an example) completed as expected without having to build custom test routines for quasi-core routines. This is the exact same logic as having the exit status code for abort(), but at the internal routine level.
4. Re: EURXSC -- Euphoria Routine Exit Status Code idea
- Posted by jimcbrown (admin) Sep 24, 2012
- 1103 views
I have an idea for a new feature for the next major release of Euphoria.
You mean 5.0? That's probably years away. The next minor release and next revision release (4.1.0 and 4.0.5 respectively) are a lot closer.
At its heart the idea is nothing more than to create a new built-in global variable (which would be a reserved identifier) that can be R/W accessed by any routine.
Basically errno from C. I think this is a bad idea, since it's less obvious and more complicated than simply using a function to return the value.
Here is a hypothetical example of how this might be used:
8.16.4.7 add_item
- The Routine Exit Status Code will be set as follows:
- If needle was successfully added to haystack then EURXSC = 0
- If needle was already part of haystack then EURXSC = 1
- If needle was not already part of haystack and also failed to be added then EURXSC = -1
The -1 case will never happen, since it is impossible to fail to add it as part of the haystack if it is not already in there. (I guess we could run out of memory during the attempt, but then Euphoria crashes rather than returning a catchable exception or error code.)
I can see the use of being able to check if the needle was already in the list before it was added. However, I'm not sure that this is worth changing the return value of add_item, especially when doing the check manually first is so cheap. (I could be talked into an add_item_ex() that returns {0,theList} or {1,theList} however.)
5. Re: EURXSC -- Euphoria Routine Exit Status Code idea
- Posted by Aveu Sep 24, 2012
- 1136 views
The -1 case will never happen, since it is impossible to fail to add it as part of the haystack if it is not already in there.
Here is an example of it failing, which is what prompted my thinking about this idea... http://openeuphoria.org/forum/119043.wc?last_id=119049
6. Re: EURXSC -- Euphoria Routine Exit Status Code idea
- Posted by jimcbrown (admin) Sep 24, 2012
- 1093 views
I would be fine with "something modern" in principal but I was thinking in terms of a generic solution that would not add any unnecessary processing overhead to the main language engine.
In this case I think it'd be better to go with a more elegant design, even if it adds more processing overhead.
I suspect only a small fraction of the existing library routines would even want to take advantage of this feature.
I agree, and believe add_item() is not one of them.
Perhaps because I really don't want to "see if the sequence contains the object".
Then what's the point of having it for add_item()? Like I said, I don't believe add_item() is one of the routines that would want this feature.
I want to see if a particular library routine (add_item was just an example) completed as expected without having to build custom test routines for quasi-core routines. This is the exact same logic as having the exit status code for abort(), but at the internal routine level.
But it completes as expected in all cases. So what's the point?
7. Re: EURXSC -- Euphoria Routine Exit Status Code idea
- Posted by jimcbrown (admin) Sep 24, 2012
- 1098 views
The -1 case will never happen, since it is impossible to fail to add it as part of the haystack if it is not already in there.
Here is an example of it failing, which is what prompted my thinking about this idea... http://openeuphoria.org/forum/119043.wc?last_id=119049
No it isn't. http://openeuphoria.org/forum/m/119055.wc