[ create a new paste ] login | about

Link: http://codepad.org/KFy9f8y3    [ raw code | fork ]

Scheme, pasted on Sep 20:
; remove member from list
; test? - comparison function

; example from the little schemer:

(define rember-f
  (lambda (test?)
    (lambda (a l)
      (cond
        ((null? l) (quote()))
        ((test? (car l) a) (cdr l))
        (else (cons (car l)
                    ((rember-f test?) a (cdr l))))))))


; my attempt, lisp:

(defun rember-f (testp)
  (function
    (lambda (a l)
      (cond
        ((null l)          nil)
        ((testp (car l) a) (cdr l))
        (t                 (cons (car l)   
                                 (funcall (rember-f testp) a (cdr l))))))))
;Compiler warnings :
;   In an anonymous lambda form inside REMBER-F: Undefined function REMBER-F
;   In an anonymous lambda form inside REMBER-F: Undefined function TESTP

(funcall (rember-f (function eq)) '1 '(1 2 3))

> Error: Undefined function TESTP called with arguments (1 1) .
> While executing: (:INTERNAL REMBER-F), in process listener(1).


Create a new paste based on this one


Comments: