Recently when I self-learnt MIT 6.5151 course, I first read CS 61AS Unit 0 as the preparation. Then I have read SICP 1 to 2.1 (with related lecture notes) as ps0 requires (also read 2.2.1 as CS 61A notes requires) and then Software Design for Flexibility (SDF) Prologue, chapter 1 and partly Appendix on Scheme.
I read the doc when programming ps0:
Combines all the elements of list using the binary operation procedure. For example, using + one can add up all the elements:
(reduce + 0 list-of-numbers)
Trivially and can be one binary operation procedure same as +. The following works:
2 error> (reduce + 0 '(1 2 3))
;Value: 6
Then I tried:
1 ]=> (reduce and #t '(#t #t #t))
;Transformer may not be used as an expression: #[transformer-item 12]
But it throws error ((reduce and 1 '(1 2 3)) also has this error although (and 1 2) gives the output 2).
Maybe as the above doc says, we should use fold-right, but the error message is still there.
Combines all of the elements of list using the binary operation procedure. Unlike reduce and reduce-right, initial is always used:
The problem can be solved by use one self-defined function like
(define (reduce_and lst)
(cond ((null? lst) #t)
((equal? (car lst) #f) #f)
(else (reduce_and (cdr lst)))))
(reduce_and '(#t #f)) ; #f
Could someone tell me the reasons behind the above error message ";Transformer may not be used as an expression: #[transformer-item 12]" (As this comment says, the above error message may not give one useful description of the reasons behind)?
(everyin gnu.org/software/mit-scheme/documentation/stable/… but failed. This comment stackoverflow.com/questions/23186949/… works for me. Thanks.