[plt-scheme] Re: It gets shared!

From: Jos Koot (jos.koot at telefonica.net)
Date: Tue Feb 17 06:40:52 EST 2009

Consider:
(define a (list 1 2))
(define b (list a a))
Now the two elements of list b are shared. No set! required to do that. You may or you may not want to show the sharing in the output. Because lists are immutable, the fact that two elements are shared makes no difference as long as the elements are immutable too. Compare this to:

(define a (list (box 1) (box 2))) ; mutable elements!
(define b (list a a))
(set-box! (car a) 3)
b --> (list (list (box 3) (box 2)) (list (box 3) (box 2))) or
b --> (shared ((-1- (list (box 3) (box 2)))) (list -1- -1-))
depending on the output mode.

Jos
  ----- Original Message ----- 
  From: Andrei Estioco 
  To: plt-scheme at list.cs.brown.edu 
  Sent: Tuesday, February 17, 2009 11:53 AM
  Subject: [plt-scheme] Re: It gets shared!



  Oh...well yes that solved my problem for Advanced Student. Thanks. But my question remains. What part of my code made it shared? I mean...I didn't even use set! . Well, as far as I know, set! is the only way in Scheme to have values shared.

  -- 
  Chad Estioco
  BS Computer Science
  University of the Philippines-Diliman
  ==============================
  http://www.geocities.com/lokisky_walker



------------------------------------------------------------------------------


  _________________________________________________
    For list-related administrative tasks:
    http://list.cs.brown.edu/mailman/listinfo/plt-scheme
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090217/881390b7/attachment.html>

Posted on the users mailing list.