Re: symbols
- Posted by SDPringle May 09, 2012
- 1312 views
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.
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