Update to my toy.
Function may return #f rather than cons, which will leave the list it’s building as is. Was needed for filter. Also slows it down a great deal. :[
(define (stillhasnoname lst func) ;; Grab pointer to first cons. ;; Contents of car will be dropped. ;; Contents of cdr will be clobbered. (let ((newlst (list #f))) ;; acc is usually the result of the ;; "reduce so far", here it is the ;; last pair in newlst. cur is ;; current item of consideration ;; in the original list. (lfold (lambda (acc cur) ;; func should return either ;; a new pair to be tacked ;; onto the end of newlst, ;; or #f which will leave ;; acc as-is. (let ((tst (func cur))) (if tst (begin (set-cdr! acc tst) (rest acc)) acc))) newlst ; Accumulator lst) ; list we're deriving from (rest newlst))) ; car is trash, see above.
No comments yet.
Leave a Reply