Subject: Re: Good way to strip nulls from list ?
From: (Rob Warnock)
Date: 2000/04/08
Newsgroups: comp.lang.scheme
Message-ID: <8cmcfp$17mp2$>
Colin Walters  <> wrote:
| "Rob" == Rob Warnock <> 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))
	      ((null? node) 0)
	      ((not (pair? node))
	       (if (pred? node) 1 0))
		(+ (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 Warnock, 41L-955
Applied Networking
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		PP-ASEL-IA
Mountain View, CA  94043