tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View file

@ -0,0 +1,13 @@
(define (power-set set)
(if (null? set)
'(())
(let ((rest (power-set (cdr set))))
(append (map (lambda (element) (cons (car set) element))
rest)
rest))))
(display (power-set (list 1 2 3)))
(newline)
(display (power-set (list "A" "C" "E")))
(newline)

View file

@ -0,0 +1,23 @@
(define (power-set lst)
(define (iter yield)
(let recur ((a '()) (b lst))
(if (null? b) (set! yield
(call-with-current-continuation
(lambda (resume)
(set! iter resume)
(yield a))))
(begin (recur (append a (list (car b))) (cdr b))
(recur a (cdr b)))))
;; signal end of generation
(yield 'end-of-seq))
(lambda () (call-with-current-continuation iter)))
(define x (power-set '(1 2 3)))
(let loop ((a (x)))
(if (eq? a 'end-of-seq) #f
(begin
(display a)
(newline)
(loop (x)))))

View file

@ -0,0 +1,7 @@
(1 2)
(1 3)
(1)
(2 3)
(2)
(3)
()