Wed, Nov 20, 2013 at 12:09 PM, Bo Gus wrote:
> > My tail recursive implementation of length is like this:
> >
> > (define (length2 l)
> > (define (l-iter l count)
> > (if (null? 1) count
> > (l-iter (cdr l) (+ count 1
> > (l-iter l 0))
>
My tail recursive implementation of length is like this:
(define (length2 l)
(define (l-iter l count)
(if (null? 1) count
(l-iter (cdr l) (+ count 1
(l-iter l 0))
If I call (length2 '(1 2 3)) and step through the code in racket, count
increments to 3 but then on the (if (null?
If I evaluate this:
(list 'this '(is silly))
I get this:
'(this (is silly))
I just want to check I understand what is happening here.
list always returns a proper list hence I see no dotted notation here.
The return value is quoted which means it is a symbol? But there are
spaces so can it
(=~ is interesting. Thanks.
On 22 October 2013 13:53, Matthias Felleisen wrote:
>
> ;; equation3 : number -> boolean
> ;; to determine whether n is a solution for 2n^2 = 102
> (define (equation3 n)
> (=~ (* 2 n n) 102 .001))
>
>
> -- Matthias
>
>
>
&
equation 2 is 2n^2 = 102 so I implement like this:
;; equation3 : number -> boolean
;; to determine whether n is a solution for 2n^2 = 102
(define (equation3 n)
(= (* 2 n n) 102))
And my answer is the same as per the online answer. so great.
But how can I check a valid answer.
Eg if I do
Using DrRacket v5.3.6, if I enter:
(define (tax pay)
(cond
((<= pay 240.0) 0)
((<= pay 480.0) (* (/ 15 100) pay))
((else ((+ (* (/ 15 100) 480) (* (/ 28 100) (- pay 480
I get error
else: not allowed as an expression in: (else ((+ (* (/ 15 100) 480) (* (/
28 100) (- pay 480)
6 matches
Mail list logo