This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; スレッドを使わずにcall-with-input-httpを実装してみる | |
| ; スレッドを使うかどうかを切り替えられるように。 | |
| (use rfc.http) | |
| (use gauche.generator) | |
| (use gauche.uvector) | |
| (use sxml.ssax) | |
| (use gauche.vport) | |
| (use inverter) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; イテレータ反転 | |
| (define-module inverter | |
| (use gauche.generator) | |
| (use util.stream) | |
| ; | |
| (use util.queue) | |
| (use gauche.threads) | |
| ; | |
| (export | |
| generator-inverter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; ポートの反転 | |
| (define-module port-inverter | |
| (use gauche.vport) | |
| (use gauche.generator) | |
| (use gauche.uvector) | |
| ; | |
| (use inverter) | |
| (export | |
| mtport-inverter | |
| )) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; http-getのパラメタ指定してhttp-get、procに仮想ポートを渡す。 | |
| (define (call-with-input-http http-param proc :key (queue-size 100) (buffer-size 8000) ) | |
| (let1 inverter (mtport-inverter :queue-size queue-size :buffer-size buffer-size) | |
| (inverter | |
| (^[outp] (apply http-get (append http-param `(:sink ,outp :flusher ,(^ _ (flush outp) #t) )))) | |
| (^[inp] (proc inp) ) ) ) ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (use gauche.uvector) | |
| (define (uvector-slices u k) | |
| (let [(uvclass (class-of u)) | |
| (l (uvector-length u))] | |
| (receive (n r) (quotient&remainder l k) | |
| (let1 s (* n k) | |
| (let loop [(i s) | |
| (d (if (= r 0) | |
| '() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (use gauche.generator) | |
| (use gauche.uvector) | |
| (define (call-with-port-chunk port chunk-size size proc) | |
| (let1 chunk (make-u8vector chunk-size) | |
| (cond | |
| [ (eqv? size 0) #t ] | |
| [ (not size) | |
| (until (read-block! chunk port 0 chunk-size) eof-object? => len |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (use gauche.uvector) | |
| (define (call-with-input-chunk port chunk-size size proc) | |
| (let1 chunk (make-u8vector chunk-size) | |
| (cond | |
| [ (eqv? size 0) #t ] | |
| [ (not size) | |
| (until (read-block! chunk port 0 chunk-size) eof-object? => len | |
| (proc (uvector-alias <u8vector> chunk 0 len) ) ; hook | |
| ) ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (use gauche.generator) | |
| (define (proc-a g yield) | |
| (do-generator (x g) | |
| (yield (* x 2)))) | |
| (define (proc-b g yield) | |
| (do-generator (x g) | |
| (yield (* x 3)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (use gauche.generator) | |
| (use text.tr) | |
| (define (generator-inverter) | |
| (^[produce consume] (consume (generate produce) ) ) ) | |
| (define (pipeline inverter cmd-in cmd-out) | |
| (^[ g yield] | |
| (inverter | |
| (^[yield] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (use gauche.generator) | |
| (define (gtabulate n init-proc) | |
| (gunfold (cut >= <> n) init-proc (cut + <> 1 ) 0 ) ) |