[ prog / sol / mona ]

prog


The Forced Indentation Of Code

104 2022-05-31 11:25

Here is a variation of >>99 that uses two coroutines implemented via call-with-current-continuation. The coroutines bounce the task of displaying a line between each other, alternately displaying even and odd lines. The looping needed inside a coroutine is also implemented via call-with-current-continuation as in >>99. No assignments are used and all the state of the computation is passed through the various continuations. This discipline allows the various continuations to be interleaved and mixed without interfering with each other.

scheme@(guile-user)> ((lambda (rec xjoin fore back pad n s chars) ((lambda (coroutine xjoin cell cycle size) ((lambda (bounce expand) ((lambda (chars) ((lambda (symbol) ((lambda (oneline) (bounce oneline size)) (lambda (k) (display (string-append (xjoin size (lambda (j) (symbol k j)) pad) "\n"))))) (lambda (k j) (or (fore n s k j) (back n chars cell cycle k j))))) (expand chars cell))) (lambda (task n) ((coroutine task n) (cons (coroutine task n) 0))) (lambda (chars n) (xjoin (* n (string-length chars)) (lambda (x) ((lambda (idx) (substring chars idx (+ 1 idx))) (quotient x n))) "")))) (lambda (task limit) (lambda (other+n) (rec (lambda (next passto k) (when (< k limit) (task k) ((lambda (next+x) (when (pair? next+x) (next (car next+x) (cdr next+x)))) (call-with-current-continuation (lambda (c) (passto (cons c (+ k 1)))))))) (car other+n) (cdr other+n)))) (lambda (n fun sep) (rec xjoin n fun sep "")) (string-length s) (string-length chars) (- (* 2 n) 1))) (lambda (fun . args) ((lambda (cont+args) ((lambda (cont args) ((lambda (next) (apply fun next args)) (lambda args (cont (cons cont args))))) (car cont+args) (cdr cont+args))) (call-with-current-continuation (lambda (cont) (cons cont args))))) (lambda (next n fun sep acc) (if (<= n 0) "" (if (= n 1) (string-append (fun 0) acc) (next (- n 1) fun sep (string-append sep (fun (- n 1)) acc))))) (lambda (n s k j) (if (< (abs (- n 1 j)) (- n 1 (abs (- n 1 k)))) #f s)) ((lambda (extract) (lambda (n chars cell cycle k j) (extract chars (* cell (modulo (min (abs (- n 1 k)) (abs (- n 1 j))) cycle)) cell))) (lambda (str pos len) (substring str pos (+ pos len)))) " " 11 "co" "█▓▒░ ")

separate output for 413

267


VIP:

do not edit these