<!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.2900.2963" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face="Courier New" size=2>Hi</FONT></DIV>
<DIV><FONT face="Courier New" size=2>Are you sure you want to use vectors? If
you represent a partition by a list and let the procedure make a list of
partitions, it can be written in 151 characters, not counting lay-out characters
but including necessary spaces. This is not easy though. Are you familiar with
named let and the procedures map and append? You should master these things
before doing this problem, I think.</FONT></DIV>
<DIV><FONT face="Courier New" size=2>Jos Koot</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV>((((lambda(x)((((((x x)x)x)x)x)x))<BR> (lambda(x)(lambda(y)(x(x
y)))))<BR> (lambda(x)(write x)x))<BR> "greetings, Jos") </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=ahmadissa@gmail.com href="mailto:ahmadissa@gmail.com">Ahmad Issa</A>
</DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=jos.koot@telefonica.net
href="mailto:jos.koot@telefonica.net">Jos Koot</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Tuesday, September 19, 2006 2:20
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> Re: [plt-scheme] Define in
define</DIV>
<DIV><BR></DIV>Thanks for your reply. Can a body contain an internal
definition, followed by an expression, then another internal definition,
followed by an expression?<BR><BR>I see the code i posted above does not
return something (since define isn't an expression), but adding an expression
to the end still causes the same error. I suspect it's because theres a 'let'
expression inbetween the internal defines. <BR><BR>Here's the modified
version:<BR><BR>(define (partition n)<BR> (define results
(make-vector (+ n 1)))<BR> (define (update cur max
val)<BR> (vector-set! (vector-ref
results cur) max val)<BR> val)
<BR> <BR> (let loop ((i
0))<BR> (cond ((> i n)
0)<BR>
(else (vector-set! results i (make-vector (+ n 1)
0))<BR>
(loop (+ i 1)))))<BR> <BR> (define (part cur
max)<BR> (cond ((= cur 0) 1)
<BR>
((not (= (vector-ref (vector-ref results cur) max)
0))<BR>
(vector-ref (vector-ref results cur)
max))<BR>
(else (update cur max (let loop ((i
1))<BR>
(cond ((or (> i max) (> i cur)) 0)
<BR>
(else (+ (part (- cur i)
i)<BR>
(loop (+ i
1))))))))))<BR>
<BR> (part n n)) ;; Just added this in, this is an
expression! so it should work? <BR><BR>
<DIV><SPAN class=gmail_quote>On 9/19/06, <B class=gmail_sendername>Jos
Koot</B> <<A
href="mailto:jos.koot@telefonica.net">jos.koot@telefonica.net</A>>
wrote:</SPAN>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">
<DIV>
<DIV bgcolor="#ffffff">
<DIV><FONT face="Courier New" size=2>Hi Ahmad</FONT></DIV>
<DIV><FONT face="Courier New" size=2>Look in your tutorial text, and closely
follow its instructions. Which book are you using? Even if it were
allowed to intermix define forms and expressions, your procedure would not
return any specified value.</FONT></DIV>
<DIV><FONT face="Courier New" size=2>(define (name argument) body)
means</FONT></DIV>
<DIV><FONT face="Courier New" size=2>(define name (lambda (argument)
body)</FONT></DIV>
<DIV><FONT face="Courier New" size=2>A body consists of any number of define
forms (called internal definitions)followed by at least one expression. The
procedure returns the value of the last expression. The computation of the
values of the define forms must not require the value of any of the
variables being defined. (MzScheme guarantees that the values of the define
forms are evaluated from left to right, but R5RS allows an
interpreter/compiler to choose any arbitrary order) There are several
reasons for these restrictions, one of which is good style. </FONT><FONT
face="Courier New" size=2>It is very tempting to experiment
with constructs in another way than shown in your textbook, but in
order to acquire good style it is wise to let yourself be guided by your
book or teacher. Good style is not merely a matter of beauty, but in the end
allows you to write correct programs in relatively short time and without
making methodological errors. It even helps decrease the number of trivial
bugs.</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV><FONT face="Courier New" size=2>Jos Koot</FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV>
<DIV>((((lambda(x)((((((x x)x)x)x)x)x))<BR>
(lambda(x)(lambda(y)(x(x y)))))<BR> (lambda(x)(write
x)x))<BR> "greetings, Jos") </DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: rgb(0,0,0) 2px solid; MARGIN-RIGHT: 0px"></BLOCKQUOTE></DIV>
<DIV><SPAN class=e id=q_10dc5fd9ce980bff_1>
<DIV
style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal">-----
Original Message ----- </DIV>
<DIV
style="BACKGROUND: rgb(228,228,228) 0% 50%; FONT: 10pt arial; font-size-adjust: none; font-stretch: normal; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"><B>From:</B>
<A title=ahmadissa@gmail.com
onclick="return top.js.OpenExtLink(window,event,this)"
href="mailto:ahmadissa@gmail.com" target=_blank>Ahmad Issa</A> </DIV>
<DIV
style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal"><B>To:</B>
<A title=plt-scheme@list.cs.brown.edu
onclick="return top.js.OpenExtLink(window,event,this)"
href="mailto:plt-scheme@list.cs.brown.edu"
target=_blank>plt-scheme@list.cs.brown.edu</A> </DIV>
<DIV
style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal"><B>Sent:</B>
Tuesday, September 19, 2006 8:32 AM</DIV>
<DIV
style="FONT: 10pt arial; font-size-adjust: none; font-stretch: normal"><B>Subject:</B>
[plt-scheme] Define in define</DIV>
<DIV><BR></DIV>Hi, i'm using MzScheme, with my code:<BR><BR>(define
(partition n)<BR> (define results (make-vector (+ n
1)))<BR> (define (update cur max
val)<BR> (vector-set! (vector-ref
results cur) max val)<BR> val)
<BR> <BR> (let loop ((i
0))<BR> (cond ((> i n)
0)<BR> (else
(vector-set! results i (make-vector (+ n 1) 0))<BR>
(loop (+ i 1)))))<BR>
<BR> (define (part cur max)<BR>
(cond ((= cur 0) 1)<BR>
((not (= (vector-ref
(vector-ref results cur) max) 0))<BR>
(vector-ref
(vector-ref results cur) max))<BR>
(else (update cur max (let loop ((i 1))
<BR>
(cond ((or (> i max) (> i
cur)) 0)<BR>
(else (+ (part (- cur i) i)<BR>
(loop (+ i 1)))))))))))<BR><BR>I receive the error
"define: not allowed in an expression context in: (define (part cur max)
(cond ((= cur 0) 1) ((not (= (vector-ref (vector-ref results cur) max)
0))...", why can't I put a define in a define after a let statement?
<BR></SPAN></DIV>
<DIV>
<P></P>
<HR>
<P></P>_________________________________________________<BR> For
list-related administrative tasks:<BR> <A
onclick="return top.js.OpenExtLink(window,event,this)"
href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme"
target=_blank>http://list.cs.brown.edu/mailman/listinfo/plt-scheme</A><BR>
<P></P></DIV></DIV></BLOCKQUOTE></DIV><BR></BLOCKQUOTE></BODY></HTML>