[plt-scheme] (no subject)
According to your contracts, you are attempting to make 'hour->wages'
(a function that consumes and produces lists) use 'wage' (a function
that consumes and produces numbers.) However, the body of 'wage' uses
'empty?' ... a function that requires a list. I would take a few
minutes to use a design recipe to define and simplify 'wage', a
function intended to provide the arithmetic that empowers
'hours->wages' to convert lists.
The second problem needs a contract-purpose-header so that others can
determine what it does. Also, an unwritten law of programming is:
don't use the letter l, it looks like the number 1. 'list' shouldn't
be used either, because it has too many uses. On the rare occasion
that a more descriptive name cannot be determined, I enjoy using liszt
even though I rarely listen to his music.
rac
On Jan 21, 2006, at 3:07 AM, igor denisov wrote:
> Hello there
>
> Can somebody help me to figure out what is wrong with these codes.
> DrScheme V208
> Language: Beginning Student.
>
> ;; hours->wages : list-of-numbers -> list-of-numbers
> ;; to create a list of weekly wages from a list of weekly hours (alon)
> (define (hours-wages alon)
> (cond
> ((empty? alon) empty)
> (else (cons (wage (first alon)) (hours-wages (rest alon))))))
>
> ;; wage : number -> number
> ;; to compute the total wage (at $12 per hour)
> ;; of someone who worked for h hours
> (define (wage h)
> (cond
> ((empty? h) 0)
> (else
> (* 12 (first h)
> (wage (rest h))
> );;multiply
> );;else
> );;cond
> );;define
> Produces a bug: first: expects argument of type <non-empty list>;
> given 0
>
> (define (dollar-store l)
> (cond
> ((empty? l) 0)
> ((and
> (< (first l) 1)
> (< (dollar-store (rest l)) 1))
> 'l)))
> (define l
> (cons .98 (cons .87 (cons .76 (cons .34 empty)))))
> Produces a bug: <: expects argument of type <real number>; given 'l
>
> Thanks in advance.
> Igor.
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme