1. symbols

Is there support for symbols?
basically an object type, but should be distinguishable from object.

I want to do something like this:

type error(integer a) 
    return 1 
end type 
 
error err = -7 
? integer(err)  -- 1, but I want 0 
? error(err)    -- 1 
new topic     » topic index » view message » categorize

2. Re: symbols

On a second thought, I'm not sure I want it

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

3. Re: symbols

kobi said...

On a second thought, I'm not sure I want it

Probably for the best. I can't figure out what you were trying to do. smile

Matt

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

4. Re: symbols

mattlewis said...
kobi said...

On a second thought, I'm not sure I want it

Probably for the best. I can't figure out what you were trying to do. smile

Matt

for example, a function is applied (map) to each object in an objects sequence,
the returned sequence with the results may have results and an error symbol.
I would like to differentiate the error from the result. (I don't like using magic values like -1, sometimes the result can be -1)
it's possible to just use another type like a string, but it's not a general solution and not very clean.

so the idea of a symbol, is that it's like a literal (or sort of like a singleton) but it has its own type that isn't shared, from the developer's perspective.

some oo languages used null for this purpose, and we all know how much trouble this brought. (atleast when not required to explicitly check)
that's why I said I'm not sure it's a good idea to introduce it.
since euphoria can return multiple types from a function, I thought it would be cleaner to have 'this function returns a result or an error symbol'

but it's not limited to errors, you can make many symbols. they're lightweight, and in my opinion, should be read-only. just "passed around", or "come into existence" like literals. it's like a constant with no value.

that's the idea. I'm not sure how it would affect programming in euphoria.

http://docs.factorcode.org/content/article-words.symbol.html

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

5. Re: symbols

kobi said...

for example, a function is applied (map) to each object in an objects sequence,
the returned sequence with the results may have results and an error symbol.
I would like to differentiate the error from the result. (I don't like using magic values like -1, sometimes the result can be -1)
it's possible to just use another type like a string, but it's not a general solution and not very clean.

OK, I see what you're looking for. There are a few ways this has been done in euphoria. Some code uses the special error value. In some of my code, all functions return a sequence on success, or an integral error code on return.

Other code may return a sequence with success / error indicator in one element and the result in another. The most common example of this is value(). It's always been a bit annoying, though, since it requires a bit of extra handling. I think that the new (in 4.1) multi-assignment operator fixes that, however.

Adding some new primitive type to euphoria is probably not going to happen (for a host of low level reasons). The same argument against more efficient string types would apply to this new lightweight whatever.

Matt

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

6. Re: symbols

kobi said...
mattlewis said...
kobi said...

On a second thought, I'm not sure I want it

Probably for the best. I can't figure out what you were trying to do. smile

Matt

for example, a function is applied (map) to each object in an objects sequence,
the returned sequence with the results may have results and an error symbol.
I would like to differentiate the error from the result. (I don't like using magic values like -1, sometimes the result can be -1)
it's possible to just use another type like a string, but it's not a general solution and not very clean.

so the idea of a symbol, is that it's like a literal (or sort of like a singleton) but it has its own type that isn't shared, from the developer's perspective.

some oo languages used null for this purpose, and we all know how much trouble this brought. (atleast when not required to explicitly check)
that's why I said I'm not sure it's a good idea to introduce it.
since euphoria can return multiple types from a function, I thought it would be cleaner to have 'this function returns a result or an error symbol'

but it's not limited to errors, you can make many symbols. they're lightweight, and in my opinion, should be read-only. just "passed around", or "come into existence" like literals. it's like a constant with no value.

that's the idea. I'm not sure how it would affect programming in euphoria.

http://docs.factorcode.org/content/article-words.symbol.html

There are constants for error values for get() and value() that ought to be used. There is no way to distinguish between GET_SUCCESS which has a value of 0, and the value from floor(0.4) which has a value of 0. Some people dislike EUPHORIA for this reason. Others like it for the same reason. :)

It is good practice to use these constants for comparing the error value from get() and value().

Shawn Pringle

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

Search



Quick Links

User menu

Not signed in.

Misc Menu