Re: [racket-users] Why doesn't this maxval function correctly return the maximum value in the list
Here's a version of your code that runs in the Intermediate Student language ("local" isn't part of Beginning Student): (define (maxval lst) (local ((define (aux lst max) (cond [(null? lst) max] [(> (car lst) max) (aux (cdr lst) (car lst))] [#t (aux (cdr lst) max)]))) (aux lst 0))) And here's the full grammar for ISL programs: http://docs.racket-lang.org/htdp-langs/intermediate.html Thanks for pointing out that the error message raised by `define` could be improved. On Mon, Feb 13, 2017 at 3:48 PM, Matthias Felleisenwrote: > > You may wish to read up on the design recipe and the necessity of ‘local’ > definitions in HtDP2e: > > http://www.ccs.neu.edu/home/matthias/HtDP2e/ > > > > > > On Feb 13, 2017, at 3:46 PM, Angus Comber wrote: > > > > But it has to have the signature maxval lst - it is a homework problem. > > > > So I thought I would need max in the helper function. Basically to keep > an internal max saved value. Is there another way? > > > > On 13 February 2017 at 20:38, Matthias Felleisen > wrote: > > > > Just lift aux out. > > > > > > > On Feb 13, 2017, at 3:18 PM, Angus Comber > wrote: > > > > > > If I change the code to: > > > > > > (define (maxval lst) > > >(define (aux lst max) > > > (cond [(null? lst) max] > > >[(> (car lst) max) (aux (cdr lst) (car lst))] > > >[#t (aux (cdr lst) max)])) > > >(aux lst 0)) > > > > > > and comment out #lang racket at the top of the file and select > Beginning Student as the language then I get error: > > > > > > define: expected only one expression for the function body, but found > 1 extra part > > > > > > Is this because there is a 2nd define in the function? Or do I need > some syntax to indicate to run aux at the end of the definition. > > > > > > On 12 February 2017 at 21:34, Matthias Felleisen > wrote: > > > > > > > On Feb 12, 2017, at 3:00 PM, Angus wrote: > > > > > > > > I am a beginner Racket developer by the way. > > > > > > > > Here is my maxval function which is supposed to take a list and > return the largest integer in the list. > > > > > > > > (define (maxval lst) > > > > (define (aux lst max) > > > > (cond [(null? lst) max] > > > > [(car lst) > max (aux (cdr lst) (car lst))] > > > > [#t (aux (cdr lst) max)])) > > > > (aux lst 0)) > > > > > > > > > > > > Using the function always returns the last value in the list > > > > > > > >> (maxval (list 1 2 3 5 6 1)) > > > > 1 > > > > > > > > The code looks correct to me, but I must be missing something. What > have I done wrong? > > > > > > > > > Your code is 100% correct, conceptually. Sadly, it’s suffering from a > mistake that I saw many many times in the 90s and before. And that’s > precisely why we get beginners started on Beginning Student Language in > DrRacket instead of plain Racket. Try it out for your next few exercises or > even this one, to see whether the error message would have helped. > > > > > > — Matthias > > > > > > > > > > > > > > -- > 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 racket-users+unsubscr...@googlegroups.com. > For more options, visit 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 racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Why doesn't this maxval function correctly return the maximum value in the list
You may wish to read up on the design recipe and the necessity of ‘local’ definitions in HtDP2e: http://www.ccs.neu.edu/home/matthias/HtDP2e/ > On Feb 13, 2017, at 3:46 PM, Angus Comberwrote: > > But it has to have the signature maxval lst - it is a homework problem. > > So I thought I would need max in the helper function. Basically to keep an > internal max saved value. Is there another way? > > On 13 February 2017 at 20:38, Matthias Felleisen wrote: > > Just lift aux out. > > > > On Feb 13, 2017, at 3:18 PM, Angus Comber wrote: > > > > If I change the code to: > > > > (define (maxval lst) > >(define (aux lst max) > > (cond [(null? lst) max] > >[(> (car lst) max) (aux (cdr lst) (car lst))] > >[#t (aux (cdr lst) max)])) > >(aux lst 0)) > > > > and comment out #lang racket at the top of the file and select Beginning > > Student as the language then I get error: > > > > define: expected only one expression for the function body, but found 1 > > extra part > > > > Is this because there is a 2nd define in the function? Or do I need some > > syntax to indicate to run aux at the end of the definition. > > > > On 12 February 2017 at 21:34, Matthias Felleisen > > wrote: > > > > > On Feb 12, 2017, at 3:00 PM, Angus wrote: > > > > > > I am a beginner Racket developer by the way. > > > > > > Here is my maxval function which is supposed to take a list and return > > > the largest integer in the list. > > > > > > (define (maxval lst) > > > (define (aux lst max) > > > (cond [(null? lst) max] > > > [(car lst) > max (aux (cdr lst) (car lst))] > > > [#t (aux (cdr lst) max)])) > > > (aux lst 0)) > > > > > > > > > Using the function always returns the last value in the list > > > > > >> (maxval (list 1 2 3 5 6 1)) > > > 1 > > > > > > The code looks correct to me, but I must be missing something. What have > > > I done wrong? > > > > > > Your code is 100% correct, conceptually. Sadly, it’s suffering from a > > mistake that I saw many many times in the 90s and before. And that’s > > precisely why we get beginners started on Beginning Student Language in > > DrRacket instead of plain Racket. Try it out for your next few exercises or > > even this one, to see whether the error message would have helped. > > > > — Matthias > > > > > > -- 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 racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Why doesn't this maxval function correctly return the maximum value in the list
But it has to have the signature maxval lst - it is a homework problem. So I thought I would need max in the helper function. Basically to keep an internal max saved value. Is there another way? On 13 February 2017 at 20:38, Matthias Felleisenwrote: > > Just lift aux out. > > > > On Feb 13, 2017, at 3:18 PM, Angus Comber wrote: > > > > If I change the code to: > > > > (define (maxval lst) > >(define (aux lst max) > > (cond [(null? lst) max] > >[(> (car lst) max) (aux (cdr lst) (car lst))] > >[#t (aux (cdr lst) max)])) > >(aux lst 0)) > > > > and comment out #lang racket at the top of the file and select Beginning > Student as the language then I get error: > > > > define: expected only one expression for the function body, but found 1 > extra part > > > > Is this because there is a 2nd define in the function? Or do I need > some syntax to indicate to run aux at the end of the definition. > > > > On 12 February 2017 at 21:34, Matthias Felleisen > wrote: > > > > > On Feb 12, 2017, at 3:00 PM, Angus wrote: > > > > > > I am a beginner Racket developer by the way. > > > > > > Here is my maxval function which is supposed to take a list and return > the largest integer in the list. > > > > > > (define (maxval lst) > > > (define (aux lst max) > > > (cond [(null? lst) max] > > > [(car lst) > max (aux (cdr lst) (car lst))] > > > [#t (aux (cdr lst) max)])) > > > (aux lst 0)) > > > > > > > > > Using the function always returns the last value in the list > > > > > >> (maxval (list 1 2 3 5 6 1)) > > > 1 > > > > > > The code looks correct to me, but I must be missing something. What > have I done wrong? > > > > > > Your code is 100% correct, conceptually. Sadly, it’s suffering from a > mistake that I saw many many times in the 90s and before. And that’s > precisely why we get beginners started on Beginning Student Language in > DrRacket instead of plain Racket. Try it out for your next few exercises or > even this one, to see whether the error message would have helped. > > > > — Matthias > > > > > > -- 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 racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Why doesn't this maxval function correctly return the maximum value in the list
Just lift aux out. > On Feb 13, 2017, at 3:18 PM, Angus Comberwrote: > > If I change the code to: > > (define (maxval lst) >(define (aux lst max) > (cond [(null? lst) max] >[(> (car lst) max) (aux (cdr lst) (car lst))] >[#t (aux (cdr lst) max)])) >(aux lst 0)) > > and comment out #lang racket at the top of the file and select Beginning > Student as the language then I get error: > > define: expected only one expression for the function body, but found 1 extra > part > > Is this because there is a 2nd define in the function? Or do I need some > syntax to indicate to run aux at the end of the definition. > > On 12 February 2017 at 21:34, Matthias Felleisen wrote: > > > On Feb 12, 2017, at 3:00 PM, Angus wrote: > > > > I am a beginner Racket developer by the way. > > > > Here is my maxval function which is supposed to take a list and return the > > largest integer in the list. > > > > (define (maxval lst) > > (define (aux lst max) > > (cond [(null? lst) max] > > [(car lst) > max (aux (cdr lst) (car lst))] > > [#t (aux (cdr lst) max)])) > > (aux lst 0)) > > > > > > Using the function always returns the last value in the list > > > >> (maxval (list 1 2 3 5 6 1)) > > 1 > > > > The code looks correct to me, but I must be missing something. What have I > > done wrong? > > > Your code is 100% correct, conceptually. Sadly, it’s suffering from a mistake > that I saw many many times in the 90s and before. And that’s precisely why we > get beginners started on Beginning Student Language in DrRacket instead of > plain Racket. Try it out for your next few exercises or even this one, to see > whether the error message would have helped. > > — Matthias > > -- 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 racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Why doesn't this maxval function correctly return the maximum value in the list
If I change the code to: (define (maxval lst) (define (aux lst max) (cond [(null? lst) max] [(> (car lst) max) (aux (cdr lst) (car lst))] [#t (aux (cdr lst) max)])) (aux lst 0)) and comment out #lang racket at the top of the file and select Beginning Student as the language then I get error: define: expected only one expression for the function body, but found 1 extra part Is this because there is a 2nd define in the function? Or do I need some syntax to indicate to run aux at the end of the definition. On 12 February 2017 at 21:34, Matthias Felleisenwrote: > > > On Feb 12, 2017, at 3:00 PM, Angus wrote: > > > > I am a beginner Racket developer by the way. > > > > Here is my maxval function which is supposed to take a list and return > the largest integer in the list. > > > > (define (maxval lst) > > (define (aux lst max) > > (cond [(null? lst) max] > > [(car lst) > max (aux (cdr lst) (car lst))] > > [#t (aux (cdr lst) max)])) > > (aux lst 0)) > > > > > > Using the function always returns the last value in the list > > > >> (maxval (list 1 2 3 5 6 1)) > > 1 > > > > The code looks correct to me, but I must be missing something. What > have I done wrong? > > > Your code is 100% correct, conceptually. Sadly, it’s suffering from a > mistake that I saw many many times in the 90s and before. And that’s > precisely why we get beginners started on Beginning Student Language in > DrRacket instead of plain Racket. Try it out for your next few exercises or > even this one, to see whether the error message would have helped. > > — Matthias > > -- 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 racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] [Library Announcement] CSS-expressions, Pollen Component and Extensible Functions
I will definitely check out the CSS package this weekend! On 13 Feb 2017 13:48, "Leandro Facchinetti"wrote: > Hi all, > > I’m here to announce three packages I published recently, because I want > feedback from the community: > > - CSS-expressions: S-expression-based CSS. > https://docs.racket-lang.org/css-expr/index.html > > - Pollen Component: Component-based development for Pollen. > https://docs.racket-lang.org/pollen-component/index.html > > - Extensible Functions: A solution to the expression problem in Typed > Racket. > https://docs.racket-lang.org/extensible-functions/index.html > > Thank you. > -- > Leandro Facchinetti > https://www.leafac.com > GPG: 0x5925D0683DF3D583 > > -- > 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 racket-users+unsubscr...@googlegroups.com. > For more options, visit 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 racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[racket-users] [Library Announcement] CSS-expressions, Pollen Component and Extensible Functions
Hi all, I’m here to announce three packages I published recently, because I want feedback from the community: - CSS-expressions: S-expression-based CSS. https://docs.racket-lang.org/css-expr/index.html - Pollen Component: Component-based development for Pollen. https://docs.racket-lang.org/pollen-component/index.html - Extensible Functions: A solution to the expression problem in Typed Racket. https://docs.racket-lang.org/extensible-functions/index.html Thank you. -- Leandro Facchinettihttps://www.leafac.com GPG: 0x5925D0683DF3D583 -- 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 racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.