how to convert a list to num in scheme?
问题 like convert (1 2 3 4) to 1234~ 回答1: The problem is characterized by coalescing a list into a single value, strongly suggesting use of a fold: (define (fold-left op initial items) (define (loop result rest) (if (null? rest) result (loop (op result (car rest)) (cdr rest)))) (loop initial items)) (define (list->num list) (fold-left (lambda (value digit) (+ (* value 10) digit)) 0 list)) (list->num '(1 2 3 4)) ;Value: 1234 回答2: This sounds like a homework question... Think about powers of ten and