<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6000.16809" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face="Courier New" size=2>unmark `Show sharing in values' in the
`language/choose language' menu. You may have to open the `show details'
first.</FONT></DIV>
<DIV><FONT face="Courier New" size=2>Jos</FONT></DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=chadestioco@gmail.com href="mailto:chadestioco@gmail.com">Andrei
Estioco</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=plt-scheme@list.cs.brown.edu
href="mailto:plt-scheme@list.cs.brown.edu">plt-scheme@list.cs.brown.edu</A>
</DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Tuesday, February 17, 2009 1:30
AM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [plt-scheme] It gets
shared!</DIV>
<DIV><BR></DIV>
<DIV>Hello,</DIV>
<DIV> </DIV>
<DIV>I created a program which will display (in a list) a <A
href="http://en.wikipedia.org/wiki/Farey_sequence">farey sequence</A> of level
n. My code is as follows:</DIV>
<DIV> </DIV>
<DIV>(define-struct farey (num denom))</DIV>
<DIV> </DIV>
<DIV>(define (farey-level n)<BR> (farey-acc (- n 1) (list (make-farey 0
1)<BR>
(make-farey 1 1))))</DIV>
<DIV> </DIV>
<DIV>(define (farey-acc n flist)<BR> (cond<BR> [(= n
0) flist]<BR> [else (farey-acc (- n 1) (insert-new-farey
flist))]))</DIV>
<DIV> </DIV>
<DIV>(define (insert-new-farey flist)<BR> (append (get-first-two
flist)<BR> (get-middle
flist)<BR> (get-last-two
flist)))</DIV>
<DIV> </DIV>
<DIV>(define (get-first-two flist)<BR> (list (first
flist)<BR> (get-between
flist)<BR> (second flist)))</DIV>
<DIV> </DIV>
<DIV>(define (get-middle flist)<BR> (local<BR>
((define (get-mid flist acc)<BR>
(cond<BR> [(empty? flist)
empty]<BR> [(= (length flist)
2) (reverse acc)]<BR> [else
(get-mid (rest flist) (cons (first flist) acc))])))<BR>
(get-mid (rest (rest
flist))<BR>
empty)))</DIV>
<DIV> </DIV>
<DIV>(define (get-last-two flist)<BR> (cond<BR>
[(empty? (rest (rest flist))) (list (first
flist)<BR>
(get-between
flist)<BR>
(second flist))]<BR> [else (get-last-two (rest
flist))]))</DIV>
<DIV> </DIV>
<DIV>(define (get-between flist)<BR> (make-farey (+ (farey-num (first
flist))<BR>
(farey-num (second
flist)))<BR>
(+ (farey-denom (first
flist))<BR>
(farey-denom (second flist)))))</DIV>
<DIV> </DIV>
<DIV>I test the code in Advanced Student. I call the function (farey-level 4)
and get this result:</DIV>
<DIV> </DIV>
<DIV>> (shared ((-1- (make-farey 0 1)) (-9- (make-farey 1 1)))<BR>
(list -1- (make-farey 1 4) (make-farey 1 3) (make-farey 1 2) -9- -1-
(make-farey 1 2) (make-farey 2 3) (make-farey 3 4) -9-))</DIV>
<DIV> </DIV>
<DIV>This is not the result I was expecting so I run the code
again, this time in Intermediate Student, with the same function call,
(farey-level 4). This is the result I get:</DIV>
<DIV> </DIV>
<DIV>>(list<BR> (make-farey 0 1)<BR> (make-farey 1
4)<BR> (make-farey 1 3)<BR> (make-farey 1 2)<BR> (make-farey 1
1)<BR> (make-farey 0 1)<BR> (make-farey 1 2)<BR> (make-farey 2
3)<BR> (make-farey 3 4)<BR> (make-farey 1 1))</DIV>
<DIV> </DIV>
<DIV>Now that is the result I was expecting. My question is, why did it get
(shared) in Advanced Student? I didn't even use (set!). The only instance I
ever encountered (shared) was when I defined a doubly-linked list and, of
course, I was expecting it then. Did I make a mistake in my code?<BR
clear=all><BR>-- <BR>Chad Estioco<BR>BS Computer Science<BR>University of the
Philippines-Diliman<BR>==============================<BR><A
href="http://www.geocities.com/lokisky_walker">http://www.geocities.com/lokisky_walker</A><BR></DIV>
<P>
<HR>
<P></P>_________________________________________________<BR> For
list-related administrative tasks:<BR>
http://list.cs.brown.edu/mailman/listinfo/plt-scheme<BR></BLOCKQUOTE></BODY></HTML>