1. EURXSC -- Euphoria Routine Exit Status Code idea

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:
  1. needle : object to add.
  2. haystack : sequence to add it to.
  3. 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:
  1. A sequence, which is haystack with needle added to it.
  2. The Routine Exit Status Code will be set as follows:
    1. If needle was successfully added to haystack then EURXSC = 0
    2. If needle was already part of haystack then EURXSC = 1
    3. If needle was not already part of haystack and also failed to be added then EURXSC = -1
new topic     » topic index » view message » categorize

2. Re: EURXSC -- Euphoria Routine Exit Status Code idea

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?

new topic     » goto parent     » topic index » view message » categorize

3. Re: EURXSC -- Euphoria Routine Exit Status Code idea

CoJaBo2 said...

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.

CoJaBo2 said...

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.

new topic     » goto parent     » topic index » view message » categorize

4. Re: EURXSC -- Euphoria Routine Exit Status Code idea

Aveu said...

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.

Aveu said...

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.

Aveu said...

Here is a hypothetical example of how this might be used:

8.16.4.7 add_item

  1. The Routine Exit Status Code will be set as follows:
    1. If needle was successfully added to haystack then EURXSC = 0
    2. If needle was already part of haystack then EURXSC = 1
    3. 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.)

new topic     » goto parent     » topic index » view message » categorize

5. Re: EURXSC -- Euphoria Routine Exit Status Code idea

jimcbrown said...

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

new topic     » goto parent     » topic index » view message » categorize

6. Re: EURXSC -- Euphoria Routine Exit Status Code idea

Aveu said...

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.

Aveu said...

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.

Aveu said...

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.

Aveu said...

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?

new topic     » goto parent     » topic index » view message » categorize

7. Re: EURXSC -- Euphoria Routine Exit Status Code idea

Aveu said...
jimcbrown said...

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

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu