Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!husc6!bloom-beacon!think!ames!ucbcad!ucbvax!paris.Berkeley.EDU!larus From: larus@paris.Berkeley.EDU.berkeley.edu (James Larus) Newsgroups: comp.lang.lisp Subject: Re: cdr encoding (was Re: Importance of REPLACA, REPLACD) Message-ID: <19760@ucbvax.BERKELEY.EDU> Date: Fri, 17-Jul-87 20:36:57 EDT Article-I.D.: ucbvax.19760 Posted: Fri Jul 17 20:36:57 1987 Date-Received: Sat, 18-Jul-87 17:47:36 EDT References: <22@citcom.UUCP> <6900008@iaoobelix.UUCP> <19747@ucbvax.BERKELEY.EDU> <17815@cca.CCA.COM> Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: larus@paris.Berkeley.EDU.UUCP (James Larus) Organization: University of California, Berkeley Lines: 54 In article <17815@cca.CCA.COM> jack@CCA.CCA.COM.UUCP (Jack Orenstein) writes: >In article <19747@ucbvax.BERKELEY.EDU> larus@paris.Berkeley.EDU(James Larus) writes: >>Luddy Harrison ... has done some very nice work on >>using vector-like structures to store lists. ... >>Certain common operations, such as APPEND, become very fast and efficient. >>It's main disadvantage is that RPLACA and RPLACD are outlawed because they >>screw up the structure-sharing. ... > >I can see why RPLACD causes trouble, but why RPLACA? Suppose that P >is a pointer to a "cell" in the middle of some list represented by >a vector. P actually points to the location of the car (i.e. one >of the vector components). (RPLACD P ...) won't work because the >cdr field is at the next location in physical memory. (RPLACA P ...) >just updates the contents of the vector component. > >If C is an ordinary cell, then I don't see why (RPLACA C P) or >(RPLACD C P) would cause any trouble. > >Am I missing something? Yes, but it is not your fault. I didn't explain Luddy's idea fully enough to do it justice. His scheme stores the number of elements in a list along with a pointer to the list (the number is important for scheduling multiprocessors tasks). Suppose I have two lists: (setq A (list 1 2 3)) (setq B (list 4 5 6)) The are roughly represented: A: list, 3 --> |1|2|3| B: list, 3 --> |4|5|6| Now, suppose I do (setq C (append A B)), I end up with the following 2 (not 3!) structures: A: list, 3 --| |--> |1|2|3|--| C: list, 6 --| | | | B: list, 3 ---------------|--> |4|5|6| I can't really do it just without better drawings. Needless to say, you can see that because of the large amount of sharing that results, any RPLACA or RPLACD can affect other, unrelated lists. The sharing has many advantages for the intended uses of these structures and side-effect-producing operations like RPLACA just produce headaches on multiprocessors, so the best course is to outlaw them. /Jim