Re: [q-lang-users] Special values or failing functions
Brought to you by:
agraef
From: Albert G. <Dr....@t-...> - 2007-05-17 16:01:18
|
John Cowan wrote: > Presumably "const bottom;" somewhere in the standard library is enough? > I like the name "bottom". No, that's a misunderstanding. I was talking about an operation which bails out of the current reduction, not a general-purpose sentinel value to be returned by a function. That is, an operation like 'fail' [http://q-lang.sourceforge.net/qdoc/qdoc_10.html#IDX287], but making the entire reduction fail (effectively turning the redex being reduced into a normal form), not just the current equation. Example: foo X Y = _FAIL_ if not (isnum X and then isnum Y); = /* ... */; So, e.g., 'foo 99 bla' would be a normal form, but subsequent equations may be tried if X and Y are both numbers. Alexander, I think that this is what you wanted, right? > IMHO it's better to use "nan" than "inf" in the numeric case. It has > exactly the right semantics. The specific application was shortest path computations, where it makes perfect sense to use 'inf' for the length of a non-existing edge, because X+inf = inf and max X inf = inf if X is either a number or inf. That's also what you'll see in many text book algorithms for the shortest path problem, whether it is Bellman-Ford, Dijkstra, or the maxtrix-based algorithms. Of course this only works for algorithms where you don't have to distinguish between non-existing and infinite-length edges. Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikinformatik.uni-mainz.de/ag |