[plt-scheme] more possible planet functions
On Feb 7, 2007, at 9:31 AM, Corey Sweeney wrote:
> I have another function that i'm thinking of adding to my plant
> package, but I'm not confidant that the API is as clean as it could
> be, so I'm looking for any more comments...
>
This is a breadth-first search. Why not call it that:
(define (breadth-first-search fn start-list)
(define (sql-recur-on-loop list-to-do list-done-so-far)
(if (null? list-to-do)
list-done-so-far
(begin
(let ([currently-known-records (append list-done-so-far
list-to-do)])
(sql-recur-on-loop
(remove
(lambda (element) (member element currently-known-
records))
(apply append
(map
fn
list-to-do)))
currently-known-records)))))
(sql-recur-on-loop start-list `()))
(define (sql-recur-on sql-function start-list)
(breadth-first-search
(lambda (field)
(sqli-query s (sql-function field))
(sqli-fetchall s))
start-list))
... Also, if you're using this on lists of more than a couple hundred
elements, you're probably better off using a hash table. I don't
have a good feel for where the break-even point would be. If you
leave it as a list, I would definitely re-order the arguments to
append to put the shorter one first.
also, you could do the filter before the append, to save yourself the
trouble of appending elements that are about to disappear. Yikes,
you could also just look for a nice breadth-first search written by
someone else.
Best of luck,
John Clements
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2484 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20070207/7b9501b2/attachment.p7s>