Last active
October 6, 2021 13:45
-
-
Save joshpetit/34ed9d33707ad7de960c079cb0f320dd to your computer and use it in GitHub Desktop.
Scheme functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define filters | |
(lambda ((pred <function>) (stream <stream>)) | |
(cond ((stream-empty? stream) stream) | |
((pred (stream-first stream)) | |
(stream-cons (stream-first stream) | |
(filters pred (stream-rest stream)))) | |
(else (filters pred (stream-rest stream)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; maps thorugh stream | |
(define maps | |
(lambda ((f <function>) (stream <stream>)) | |
(if (stream-empty? stream) | |
stream | |
(stream-cons (f (stream-first stream)) (maps f (stream-rest stream)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define reduce | |
(lambda (base combiner lst) ;base <object> combiner<function> lst<list> | |
(if (null? lst) | |
base | |
(combiner (head lst) | |
(reduce base combiner (tail lst)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment