[plt-scheme] more possible planet functions

From: Corey Sweeney (corey.sweeney at gmail.com)
Date: Wed Feb 7 12:31:09 EST 2007

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 function that is designed to take away the task of
writing a seperate recursive function evey time you want to do a
recursive sql call.  I.E. any time you have a table that has parents
and children and want to know all the ancestors of a record, or all
the children of a record.

;If effiency is a serious issue, you should probably re-layout your
tables so that it is less readable, but the recursive call is not

(define (sql-recurse-on sql-function start-list)
  (define (sql-recurse-on-loop list-to-do list-done-so-far)
    (if (null? list-to-do)
          (let ([currently-known-records (append list-done-so-far list-to-do)])
              (lambda (element) (member element currently-known-records))
              (apply append
                      (lambda (field)
                        (sqli-query s (sql-function field))
                        (sqli-fetchall s))
    (sql-recurse-on-loop start-list `()))

;;here's a example of how to use it for the following table:
            Table "public.groups"
    Column    |       Type        | Modifiers
 groupname    | character varying | not null
 parent_group | character varying |
    "groups_pkey" PRIMARY KEY, btree (groupname)
Foreign-key constraints:
    "groups_parent_group_fkey" FOREIGN KEY (parent_group) REFERENCES

(define (get-all-group-children list-of-groups-to-get-children-of)
   (lambda (list-of-groupname)
      "select all groupname from groups where parent_group = '" (first
list-of-groupname) "'"))
   (map list list-of-groups-to-get-children-of)))

(get-all-group-children (list "root" "group1" "group3"))


((lambda (y) (y y)) (lambda (y) (y y)))

Posted on the users mailing list.