Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I thought this would be worth a separate reply rather then a comment, so here goes:</p> <p>Some times, when you think you need a structure or an object, but you have some special requirements that these entities don't fulfil, perhaps this is because what you actually needed is some different data structure? Objects or structs are good when some conditions are met, one such condition is that the slots are statically known - this allows the compiler to better reason about the code, which is both good for optimization and error reporting.</p> <p>On the other hand, there are data structures. Some provided with the language standard library, others added on top of it. Here's one library that provides many of them: <a href="http://cliki.net/cl-containers" rel="nofollow">http://cliki.net/cl-containers</a> but there are even more for special cases.</p> <p>Now, I will argue that using a structure such as list, array, some sort of a tree etc is better then trying to extend objects or structs to allow adding slots dynamically. This is because usually we expect the time to access a slot to be negligible. That is we expect it to be O(1). This is what normally happens regardless of the number of slots an object has. Now, when you are using a list underneath you are making it O(n), while you keep the same semantics! You could, of course, use a hash-table to make it O(1) (although this will be still generally slower then slot access), but then you will have some other unexpected behaviour, such as <code>nil</code> returned when slot doesn't exist instead of the regular error etc.</p> <p>I don't think that extending objects in such way is a common practice in CL, this is probably why other responses don't discourage you from doing that. I know less of CL then other respondents, but I've had a good deal of grief with this kind of manipulations in another language, where this is common and usually discouraged.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload