Re: length() of an atom
- Posted by petelomax Sep 23, 2010
- 1641 views
That really didn't make a whole lot of sense to me!
Anyway, as soon as this thread reappeared, I had two thoughts:
To keep things in order, length(atom) should return {}.
Well, it made me chuckle anyway, of course I'm joking. However, the other solution is to code (the equivalent of)
function length(object x, object default_result={}) if sequence(x) then return eu:length(x) elsif atom(default_result) then return default_result else crash_and_burn() end if end function
Then of course you can simply code length(5,1) to get your 1 rather than crash, and no legacy code whatsoever will be affected at all (and I hope not even performancewise), nor will it affect anyone that disagrees with changing length().
Regards, Pete