scheme - Starting with Racket, small issue -


i starting racket , want display value of function adds cdrs of list of cons, in racket:

(define (add-cdrs '((a . 1)(a . 2)(a . 3)(a . 4))) (if (null? l)     0     (+ (cdr(car l))(add-cdrs(cdr l))))) 

the output should be: 10

but, don't know how or put display function.

thank you

you're confusing procedure definition (which in case should declare parameter used hold list) procedure invocation (which binds actual list parameter). other that, logic correct. try this:

(define (add-cdrs lst)   (if (null? lst)       0       (+ (cdr (car lst)) (add-cdrs (cdr lst)))))  (add-cdrs '((a . 1) (a . 2) (a . 3) (a . 4))) => 10 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -