Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;Autor: Carlos A Delgado
- ;;Fecha 22 de Feb de 2021
- ;;Contrato: sumar-lista: lista de numeros -> numero
- ;;Descripción: Esta función toma los elementos de una lista y los suma
- ;;Ejemplo
- ;;(cons 2 (cons 3 (cons 4 (cons 5 (cons 6 empty)))) 20
- ;;(cons 3 (cons 6 (cons 9 empty))) 18
- ;;empty 0
- (define (sumar-lista lst)
- (cond
- [(empty? lst) 0]
- [else
- (+
- (first lst)
- (sumar-lista (rest lst))
- )]))
- (check-expect (sumar-lista (cons 2 (cons 3 (cons 4 (cons 5 (cons 6 empty)))))) 20)
- (check-expect (sumar-lista (cons 3 (cons 6 (cons 9 empty)))) 18)
- (check-expect (sumar-lista empty) 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement