Ben, 

let me recommend you work thru the beginning of Part II of HtDP/2e, especially 
the chapter on Designing with Self-referential Data Definitions: 

http://www.ccs.neu.edu/home/matthias/HtDP2e/part_two.html 
<http://www.ccs.neu.edu/home/matthias/HtDP2e/part_two.html>
http://www.ccs.neu.edu/home/matthias/HtDP2e/part_two.html#%28part._ch~3adesign-lists%29
 
<http://www.ccs.neu.edu/home/matthias/HtDP2e/part_two.html#(part._ch~3adesign-lists)>


Before you get there, you will find 

http://www.ccs.neu.edu/home/matthias/HtDP2e/part_two.html#%28part._sec~3alists-cons%29
 
<http://www.ccs.neu.edu/home/matthias/HtDP2e/part_two.html#(part._sec~3alists-cons)>

which is where your professor may have taken the problem from. 

If you follow the design recipe and get stuck, report back to the mailing list 
which steps you have taken and where you’re stuck. We will un-stuck you then 

— Matthias





> On Nov 27, 2016, at 6:13 PM, David Storrs <[email protected]> wrote:
> 
> Ben, I'm guessing that this is homework?  Unless you have an artificial 
> constraint stopping it, I would suggest that you take a look at the docs for 
> Racket's built-in 'sort' function.  Also, 'cons'.  (See the 'Pairs and Lists' 
> documentation.)
> 
> As a more general hint, Racket is a functional language with a strong 
> grounding in recursion.  The way recursion works (pardon me if you already 
> know this, but I'm building to a point) is that you have a function which can 
> do two things:  solve a very trivial problem, or call itself again in order 
> to get one step closer to that trivial problem.  The standard example is the 
> factorial function:
> 
> (define (factorial n)
>   (cond [(= n 1) 1]
>             [else n * (factorial (- n 1))]))
> 
> This function knows how to solve a trivial problem:  find the factorial of 1. 
>  If it's given a number other than 1 then it moves one step closer towards 
> the problem that it knows how to solve, building up its result on the stack.
> 
> The two procedures you want to write would be good candidates for recursive 
> solutions.  
> 
> The first procedure you've already written.  It knows how to solve a trivial 
> problem: put a number (x) on the front of a list if (first lst) is smaller 
> than x.  If (first lst) is not smaller, then it should do whatever is 
> necessary to get one step closer to its result.  
> 
> The second procedure I don't want to outline too clearly, so I will ask: what 
> is the definition of a sorted list?  How do you sort lists of 0, 1, 2, and 3 
> elements?  If you can answer those questions then you'll have your solution.  
> (I suggest answering them in the order I asked them.)
> 
> Good luck!
> 
> Dave
> 
> On Sun, Nov 27, 2016 at 1:31 PM, Jon Zeppieri <[email protected] 
> <mailto:[email protected]>> wrote:
> The first question is: what is a list? Forget empty lists for a moment. Think 
> about a list with a single real in it. According to your program, what does 
> that look like?
> 
> You're defining lists in terms of pairs. Okay, so let's say you want a list, 
> where the only element in it is the number 1.0. What does that look like, in 
> terms of pairs. Maybe you have a pair where the "first" field contains 1.0. 
> But what does the "rest" field contain? What is the *rest* of a list that 
> only has one thing in it?
> 
> 
> 
> 
> > On Nov 27, 2016, at 4:23 PM, Ben Ghanem Anis <[email protected] 
> > <mailto:[email protected]>> wrote:
> >
> >> On Sunday, November 27, 2016 at 10:16:34 PM UTC+1, Jon Zeppieri wrote:
> >> Well, okay, first your program needs to admit the possibility of an empty 
> >> list. But once it does, see my previous message.
> >>
> >>> On Nov 27, 2016, at 3:45 PM, Ben Ghanem Anis <[email protected] 
> >>> <mailto:[email protected]>> wrote:
> >>>
> >>> Hey guys,
> >>> I need some help ..
> >>> I need to write two procedures .. first one should be able to insert a 
> >>> real number in the right position in a list (that is by default sorted 
> >>> ascending) made of pairs (make-pair), also i need to use the procedure to 
> >>> write another one that is able to sort in an ascending way a whole list 
> >>> of real numbers.
> >>> I already did the first step(see included shot) .. but i'm really stuck
> >>> Help!
> >>>
> >>> --
> >>> You received this message because you are subscribed to the Google Groups 
> >>> "Racket Users" group.
> >>> To unsubscribe from this group and stop receiving emails from it, send an 
> >>> email to [email protected] 
> >>> <mailto:racket-users%[email protected]>.
> >>> For more options, visit https://groups.google.com/d/optout 
> >>> <https://groups.google.com/d/optout>.
> >>> <Untitled.jpg>
> > And how could i make it accept empty lists ?
> >
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an 
> > email to [email protected] 
> > <mailto:racket-users%[email protected]>.
> > For more options, visit https://groups.google.com/d/optout 
> > <https://groups.google.com/d/optout>.
> 
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> <mailto:racket-users%[email protected]>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> <mailto:[email protected]>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to