Subject: Re: Good way to strip nulls from list ?
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 2000/04/08
Newsgroups: comp.lang.scheme
Message-ID: <8cmcfp$17mp2$1@fido.engr.sgi.com>
Colin Walters  <levanti@verbum.org> wrote:
+---------------
| "Rob" == Rob Warnock <rpw3@rigden.engr.sgi.com> writes:
| > And finally, the "letrec" expansion of that:
| > ...
| 
| Just to add to this discussion, there is a specialized form of 'let'
| to do this that I think is one of the best features of Scheme, because
| it allows one to name one's loops in a visually pleasing manner...
+---------------

Ah yezzz, which reminds me...

While I use named-let myself quite frequently for loops, I must confess
that I've only fairly recently gotten over a kind of "blind spot" with
named-let, which involves not seeing it as an opportunity for *general*
recursion, not just "tail-recusive loops". That is, for some reason
(probably because I almost always name it "loop"!! ;-} ;-} ), I was
overlooking the fact that within the named-let form the name isn't
some kind of magic local special form, but is a fully-general procedure
that can be called -- and it's value used! -- like any other, e.g.:

	(define (tree-count pred? tree)
	  (let loop ((node tree))
	    (cond
	      ((null? node) 0)
	      ((not (pair? node))
	       (if (pred? node) 1 0))
	      (else
		(+ (loop (car node))
		   (loop (cdr node)))))))

In any case, it's certainly not a complete replacement for "letrec", which
can (if you need them) provide several mutually-recursive procedures...


-Rob

-----
Rob Warnock, 41L-955		rpw3@sgi.com
Applied Networking		http://reality.sgi.com/rpw3/
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		PP-ASEL-IA
Mountain View, CA  94043