it's far more powerful than perl or any other language for text processing
you can use buffers as a data structure, and move by word, paragraph, page, line, or whatever. you can transpose, kill, and browse through the kill ring. wow!
>>6
don't all scheme base their primitives around call-cc? I want to avoid that as much as possible. I've been bitten by that more than being saved by it.
>>11
It's a Lisp with Haskell's type/category system, partial function evaluation, and has first-class support for sequence calculus, bayesian probability and logic programming, pattern matching, and packrat parsing.
call/cc is nice but you often have to wrap it to get a more reliable structure.
;; Lazy lists for scheme with generation via continuations
;; llist is a cons cell, with the car being the current
;; element and the cdr being a function that generates
;; the next llist cell.
(define (lcar llis) (car llis))
(define (lcdr llis) ((cdr llis)))
;; Construct a lazy list from a list of evaluated arguments
(define (llist . args)
(if (null? args)
'()
(cons (car args)
(lambda ()
(apply llist (cdr args))))))
;; Lazy range
(define (lrange i j)
(if (> i j)
'()
(cons i
(lambda ()
(lrange (+ i 1) j)))))
;; Lazy range using continuations
(define (crange i j)
(call/cc (lambda (first-return-c)
(letrec ((loop (lambda (i consumer)
(if (> i j)
(consumer '())
(loop (+ i 1) (call/cc (lambda (c)
(consumer (cons i
(lambda ()
(call/cc c)))))))))))
(loop i first-return-c)))))
;; Give consumer a llist whose car contains value and whose cdr will
;; bring control back to the caller of yield and give it the consumer's
;; return continuation.
(define (yield consumer value)
(call/cc (lambda (this-continuation)
(consumer (cons value
(lambda ()
(call/cc this-continuation)))))))
;; Reimplementation of crange using the yield function.
(define (crange2 i j)
(call/cc (lambda (first-consumer)
(letrec ((loop (lambda (i consumer)
(if (> i j)
(consumer '())
(loop (+ i 1) (yield consumer i))))))
(loop i first-consumer)))))
;; Push all elements of rev-lis onto lis in reverse order
(define (push-all rev-lis lis)
(if (null? rev-lis)
lis
(push-all (cdr rev-lis)
(cons (car rev-lis) lis))))
;; Returns an llist of versions of lis with element
;; inserted into each position in the lis list.
(define (linserted-in-each-spot element lis)
(call/cc (lambda (first-consumer)
(letrec ((loop (lambda (rev-lis lis consumer)
(if (null? lis)
(consumer (llist (reverse (cons element rev-lis))))
(loop (cons (car lis) rev-lis)
(cdr lis)
(yield consumer (push-all (cons element rev-lis) lis)))))))
(loop '() lis first-consumer)))))