<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>Okay, now see mcons. </div><br><div><div>On Mar 5, 2014, at 1:53 PM, Daniel Carrera wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">I see.<div><br></div><div>k is '(42 2 3) while l is '(1 2 3). This is what I expected to happen, but it is clearly not what was supposed to happen. I just tried the same example with Chicken, and for Chicken both k and l are equal to '(42 2 3).</div>
<div><div class="gmail_extra"><br></div><div class="gmail_extra">Thanks for the explanation.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Cheers,</div><div class="gmail_extra">Daniel.<br><br><div class="gmail_quote">
On 5 March 2014 19:24, Matthias Felleisen <span dir="ltr"><<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><div><br></div><div>Try </div><div><br></div><div> (define l (list 1 2 3))</div><div> (define k l)</div><div><br></div><div>Now what does (set-car! k 42) do? What should it do? </div><div>
<br></div><br><div><div>On Mar 5, 2014, at 1:23 PM, Daniel Carrera wrote:</div><br><blockquote type="cite"><div dir="ltr">But isn't the final effect the same? The pair may be immutable, but I can make a new pair and bind it to the old variable. The main difference that I can see is that what I wrote is a macro, while I believe set-car! is supposed to be a function. That could potentially break code.<div>
<br></div><div>Cheers,</div><div>Daniel.<br><div class="gmail_extra"><br><br><div class="gmail_quote">On 5 March 2014 19:18, Matthias Felleisen <span dir="ltr"><<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
No, set! mutates variable bindings while set-car! mutates cons cells (the first slot of a data structure).<br>
<br>
<br>
On Mar 5, 2014, at 1:13 PM, Daniel Carrera wrote:<br>
<br>
> Hello,<br>
><br>
> My understanding is that Racket intentionally does not provide set-car! and set-cdr! and that this is one of the ways in which Racket is not fully compatible with Scheme.<br>
><br>
> Am I right to think that it is trivially easy to add these features to Racket? Specifically, I'm thinking of:<br>
><br>
><br>
> (define-syntax set-car!<br>
> (syntax-rules ()<br>
> ((_ l new_car) (set! l (cons new_car (cdr l))))))<br>
><br>
> (define-syntax set-cdr!<br>
> (syntax-rules ()<br>
> ((_ l new_cdr) (set! l (cons (car l) new_cdr)))))<br>
><br>
><br>
> Or did I miss something?<br>
><br>
> Cheers,<br>
> Daniel.<br>
<span><font color="#888888">> --<br>
> When an engineer says that something can't be done, it's a code phrase that means it's not fun to do.<br>
> ____________________<br>
> Racket Users list:<br>
> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br>
</font></span></blockquote></div><br><br clear="all"><span class="HOEnZb"><font color="#888888"><div><br></div>-- <br>When an engineer says that something can't be done, it's a code phrase that means it's not fun to do.<br>
</font></span></div></div></div>
</blockquote></div><br></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>When an engineer says that something can't be done, it's a code phrase that means it's not fun to do.<br>
</div></div></div>
</blockquote></div><br></body></html>