Re: [racket] Why does this tail recursive list length function fail at cdr l at end of list?

2013-11-20 Thread Bo Gus
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)) >

[racket] Why does this tail recursive list length function fail at cdr l at end of list?

2013-11-20 Thread Bo Gus
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?

[racket] Confused between strings and symbols

2013-10-27 Thread Bo Gus
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

Re: [racket] HTDP 2nd edition exercise 4.2.3 - floating point issues

2013-10-22 Thread Bo Gus
(=~ 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 > > > &

[racket] HTDP 2nd edition exercise 4.2.3 - floating point issues

2013-10-22 Thread Bo Gus
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

[racket] cond and else together

2013-10-22 Thread Bo Gus
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)