Skip to content

Instantly share code, notes, and snippets.

@imphasing
Created August 2, 2011 15:08
Show Gist options
  • Save imphasing/1120378 to your computer and use it in GitHub Desktop.
Save imphasing/1120378 to your computer and use it in GitHub Desktop.
(define foldl (lambda (func accum lst) (if (null? lst) accum (foldl func (func accum (car lst)) (cdr lst)))))
(define append (lambda (list1 list2) (if (null? list1) list2 (cons (car list1) (append (cdr list1) list2)))))
(define filter (lambda (f ls) (foldl (lambda (e r) (if (f e) (append r (list e)) r)) (quote ()) ls)))
# I'm thinking this will never work, since filter can return an empty list, which will be compared with <.. unless scheme is supposed to be able to compare numbers against empties?
(filter (lambda (e) (< e 0)) (quote (-9 0 2 -2 6 4 -3 -99 201 16 -12)))
Type ,? (comma question-mark) for help.
> (define fldl (lambda (func accum lst) (if (null? lst) accum (foldl func (func accum (car lt)) (cdr lst)))))
; no values returned
> (define append (lambda (list1 list2) (if (null? list1) list2 (cons (car list1) (append (cdr list1) list2)))))
; no values returned
> (define filter (lambda (f ls) (foldl (lambda (e r) (if f e) (append r (list e)) r)) (quote ()) ls)))
; no values returned
> (filter (lambda (e) (< e 0)) (quote (-9 0 2 -2 6 4 -3 -99 21 16 -12)))
Error: vm-exception
#f
(< '() 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment