Just in time processing on a character stream: Difference between revisions

No edit summary
(→‎{{header|Tcl}}: added zkl)
Line 229:
<lang tcl>[JustInTimeStreamExtract new] stream [open "sample.txt"]</lang>
<!-- no output; I'll wait for someone else to invent something to decode… -->
 
=={{header|zkl}}==
{{trans|C++}}
<lang zkl>class FlyBy{
fcn decode(file,tuplets){
codePad:=File(file).read().mode(String); // blob of text
tuplets.pump(Console.print, _decode.fp1(codePad));
println();
}
fcn [private] _decode(idx,codePad){ // idx is (ff,lf,tab,chr) offset info codePad
z:=-1;
foreach n,c in (idx.zip(T("\f","\n","\t"))){
do(n){ if(Void==(z=codePad.find(c,z+1))) return(Void.Stop); }
}
if(z==-1) z=0; // (0,0,0,n)
try{ return(codePad[z + idx[-1] + 1]) }catch{ return(Void.Stop) }
}
}
 
fcn getUserInput{
// I don't know a user would enter this but we have
// a string of 4 item tuplets : (formfeeds, linefeeds, tabs, characters), ...
// each tuplet is an offset into a code pad (text)
h:="0 18 0 0 0 68 0 1 0 100 0 32 0 114 0 45 0 38 0 26 0 16 0 21 0 17 0 59 0 11 "
"0 29 0 102 0 0 0 10 0 50 0 39 0 42 0 33 0 50 0 46 0 54 0 76 0 47 0 84 2 28";
h.split(" ").pump(List,T(Void.Read,3),
fcn(ff,lf,t,s){ vm.arglist.apply("toInt") });
}</lang>
<lang zkl>input:=getUserInput();
// our code pad is: http://paulo-jorente.de/text/theRaven.txt
FlyBy.decode("theRaven.txt",input);</lang>
{{out}}
<pre>
Silence-Dogood.
</pre>
Anonymous user