Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define atom? (lambda (U) (cond
- ((LIST? U) #f)
- ((PAIR? U) #f)
- (#t #t))))
- (define notlist? (lambda (U) (cond
- ((LIST? U) #f)
- ((PAIR? U) (cond ((PAIR? (CDR U)) #t)
- (#t #f)))
- (#t #f))))
- (define bool? (lambda (U) (cond
- ((EQ? U '#t) #t)
- ((EQ? U '#f) #t)
- (#t #f))))
- (define not_(lambda (A) (cond
- ((EQ? A '#t) #f)
- ((EQ? A '#f) #t)
- (#t #f))))
- (define or (lambda (A B) (cond
- ((not_ (bool? A)) #f)
- ((not_ (bool? B)) #f)
- (A #t)
- (B #t)
- (#t #f))))
- (define and_ (lambda (A B) (cond
- ((not_ (bool? A)) #f)
- ((not_ (bool? B)) #f)
- (A (cond
- (B #t)
- (#t #f)))
- (#t #f))))
- (define sumAndMultiplyThroughReduct (lambda (list binary_func acc) (
- cond ((eq? list '()) acc)
- (( and_ (atom? list) (not_ (number? list) )) acc )
- ((atom? list) (cons (+ (car acc) list) (cons (* (cadr acc) list) '())))
- (( and_ (atom? (car list)) (not_ (number? (car list))) ) (binary_func (cdr list) binary_func acc) )
- ((atom? (car list) ) (binary_func (cdr list) binary_func (cons
- (+ (car acc) (car list))
- (cons (* (cadr acc) (car list)) '()))))
- (#t (binary_func (cdr list) binary_func (binary_func (car list) binary_func acc)))
- )))
- (define sumAndMultiplyAcc (lambda (list) (
- cond ((eq? list '()) 'empthy_list)
- (#t (sumAndMultiplyThroughReduct list sumAndMultiplyThroughReduct '(0 1)))
- )))
- (sumAndMultiplyAcc '(2 ((((((((((((((((((((((((((((((((((((((((((((((((((((((((())))) 5 . ())))))))))))))))))))))))))))))))))))))))))))))))))))) . 5))
- (sumAndMultiplyAcc '(2))
- (sumAndMultiplyAcc '(2 7 (5 r) 8 1 r))
- (sumAndMultiplyAcc '(2 -3.4 12))
- (sumAndMultiplyAcc '(4 2 . 5))
- (sumAndMultiplyAcc '(2 2 (4)))
- (sumAndMultiplyAcc '())
- (sumAndMultiplyAcc '((4 . 4) 1 (3 2 4)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement