scheme - Define queue in a function -
i trying create new queue in 1 of functions, getting error
define: found definition not @ top level
how can resolve this? need create queue somewhere inside. cannot create auxiliary variables outside of it.
(define (bfs-graph x g) (define q (make-queue)) (enqueue! q x) ... work queue ) (define (reachable? x y g) (cond [(empty? (graph-edges g)) #f] [else (bfs-graph x g)] ) )
edit:
ok, seems works. try play code more. thanks.
(define (reachable? x y g) (let ((q (make-queue))) (cond [(empty? (graph-edges g)) #f] [else (bfs-graph x g q)] ) ) ) (define (bfs-graph x g q) (enqueue! q x) )
the code posted should work, try changing language - set "determine language source" , add line @ beginning of file:
#lang racket
if reason can't use different language, equivalent wrote:
(define (bfs-graph x g) (let ((q (make-queue))) (enqueue! q x) ; ... work queue ))
Comments
Post a Comment