File: breadth-first.scm

package info (click to toggle)
chicken 5.3.0-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 32,892 kB
  • sloc: ansic: 580,083; lisp: 71,987; tcl: 1,445; sh: 588; makefile: 60
file content (19 lines) | stat: -rw-r--r-- 400 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
;;;; breadth-first.scm


(include "QUEUE")


(functor (breadth-first (Q QUEUE)) (search)
  (import scheme (chicken base) Q)
  
  (define (enqlist q xs)
    (foldl (lambda (q x) (enqueue q x)) q xs))

  (define (search next x)
    (define (bfs q)
      (if (empty? q)
	  '()
	  (let ((y (head q)))
	    (cons y (lambda () (bfs (enqlist (dequeue q) (next y))))))))
    (bfs (enqueue empty-queue x))) )