application/octet-stream
•
1.35 KB
•
37 lines
; A bunch of procedurs working on procedures, using type specialized λs
[defun length [α]
"Returns the length of collection α"
[case [type-of α]
[[:pair] [list/length α]]
[[:string] [string/length α]]
[otherwise [throw [list :invalid-type "You can only use length with a collection" α [current-lambda]]]]
]
]
[defun filter [p α]
"Runs predicate p over every item in list l and returns a list consiting solely of items where p is true"
[case [type-of α]
[[:pair] [list/filter p α]]
[[:nil] #nil]
[otherwise [throw [list :invalid-type "You can only use filter with a collection" α [current-lambda]]]]
]
]
[defun for-each [f α]
"Runs f over every item in collection l and returns the resulting list"
[case [type-of α]
[[:pair] [list/for-each f α]]
[[:nil] #nil]
[otherwise [throw [list :invalid-type "You can only use for-each with a collection" α [current-lambda]]]]
]
]
[defun map [f α]
"Runs f over every item in collection l and returns the resulting list"
[case [type-of α]
[[:pair] [list/map f α]]
[[:nil] #nil]
[otherwise [throw [list :invalid-type "You can only use map with a collection" α [current-lambda]]]]
]
]