(hello

‘world)

In case I want to grok this in 6 months.

(define (whatdoicallthis lst func)
  ;; Grab pointer to first cons.
  ;; Contents of car will be dropped.
  ;; Contents of cdr will be clobbered. 
  (let ((newlst (list #t))) 
    ;; acc is usually the result of the
    ;; "reduce so far", here it is the
    ;; last pair in newlis. cur is
    ;; current item of consideration
    ;; in the original list. 
    (lfold (lambda (acc cur)
	     ;; func should return a new
	     ;; pair, which gets tacked 
	     ;; onto the end of newlst.
	     (set-cdr! acc (func cur))
	     ;; Have lfold push the new
	     ;; pair into acc next
	     ;; time it loops.
	     (rest acc))
	   newlst ; Accumulator
	   lst) ; list we're deriving from
    (rest newlst))) ; car is trash, see above.

(define (append hd tl)
  (whatdoicallthis hd (lambda (nxt) 
			(cons nxt tl))))

(define (map func lst)
  (whatdoicallthis lst (lambda (nxt) 
			 (list (func nxt)))))
Advertisements

August 1, 2010 - Posted by | Programming, Scheme

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: