mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-23 20:15:06 +02:00
They can be close()d explicitly with close-file-descriptor, and will close() on gc, but only explicitly closing the last port on them will close the fileno. Notably needed for network sockets where we open separate input and output ports on the same socket.
53 lines
1.3 KiB
Scheme
53 lines
1.3 KiB
Scheme
; The recursive-nfa benchmark. (Figure 45, page 143.)
|
|
|
|
;; Changed by Matthew 2006/08/21 to move string->list out of the loop
|
|
|
|
|
|
(define (recursive-nfa input)
|
|
|
|
(define (state0 input)
|
|
(or (state1 input) (state3 input) #f))
|
|
|
|
(define (state1 input)
|
|
(and (not (null? input))
|
|
(or (and (char=? (car input) #\a)
|
|
(state1 (cdr input)))
|
|
(and (char=? (car input) #\c)
|
|
(state1 input))
|
|
(state2 input))))
|
|
|
|
(define (state2 input)
|
|
(and (not (null? input))
|
|
(char=? (car input) #\b)
|
|
(not (null? (cdr input)))
|
|
(char=? (cadr input) #\c)
|
|
(not (null? (cddr input)))
|
|
(char=? (caddr input) #\d)
|
|
'state2))
|
|
|
|
(define (state3 input)
|
|
(and (not (null? input))
|
|
(or (and (char=? (car input) #\a)
|
|
(state3 (cdr input)))
|
|
(state4 input))))
|
|
|
|
(define (state4 input)
|
|
(and (not (null? input))
|
|
(char=? (car input) #\b)
|
|
(not (null? (cdr input)))
|
|
(char=? (cadr input) #\c)
|
|
'state4))
|
|
|
|
(or (state0 input)
|
|
'fail))
|
|
|
|
(time (let ((input (string->list (string-append (make-string 133 #\a) "bc"))))
|
|
(let loop ((n 150000))
|
|
(if (zero? n)
|
|
'done
|
|
(begin
|
|
(recursive-nfa input)
|
|
(loop (- n 1)))))))
|
|
|
|
|
|
|