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))]
[
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
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,
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
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
> 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]
>
On Sun, 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]
>
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
8 matches
Mail list logo