From: Paul K. <pk...@gm...> - 2008-08-26 22:05:46
|
On 26-Aug-08, at 5:34 PM, Scott L. Burson wrote: > Quoting Paul Khuong <pk...@gm...>: >> >> Either way, is it so hard to (defvar *empty-vector* #())? I don't see >> the point of using NIL instead of an empty vector; it doesn't even >> save space! > > It doesn't save space, but comparing against NIL is very fast in all > implementations of which I am aware. Dereferencing a special is > not, on the other hand, always fast. Testing that a vector's length is zero should be pretty fast too, on any implementation that actually cares about execution speed. Especially these days, I'm fairly certain it's *at best* not a pessimisation to have a distinguished value instead of zero-length vectors. You're adding an, a priori, ill-predictable branch (unlike the type checks) to save a minuscule (nil?) amount of time. >> I believe that special case is better asked for explicitly. The >> proper >> way to achieve the desired effect would be to shadow CL:LENGTH and >> define a new LENGTH *function* and declaim it inline or define a >> compiler macro. > > FSet does in fact shadow CL:LENGTH, as Daniel said ("Where LENGTH > has been shadowed as ..."). The important point is to use a function, not a macro. If FSet did not shadow CL:LENGTH, asdf would have logged an ERROR, not a WARNING. Paul Khuong |