Just in time processing on a character stream: Difference between revisions
Just in time processing on a character stream (view source)
Revision as of 09:39, 23 March 2024
, 2 months ago→{{header|11l}}: new way of specifying file open mode
Alextretyak (talk | contribs) (Added 11l) |
Alextretyak (talk | contribs) m (→{{header|11l}}: new way of specifying file open mode) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 15:
{{trans|Python}}
<
Int formFeed
Int lineFeed
Line 43:
F decode(filename, uiList)
V f = File(filename
V text = f.read()
Line 79:
V uiList = getUserInput()
decode(‘theRaven.txt’, uiList)</
{{out}}
Line 88:
=={{header|C}}==
{{trans|C++}}
<
#include <stdio.h>
#include <stdlib.h>
Line 303:
return 0;
}</
{{out}}
<pre>Silence-Dogood.</pre>
Line 309:
=={{header|C sharp|C#}}==
{{trans|D}}
<
using System.Collections.Generic;
using System.Linq;
Line 387:
}
}
}</
{{out}}
<pre>Silence-Dogood.</pre>
Line 393:
=={{header|C++}}==
Text used to encode:[http://paulo-jorente.de/text/theRaven.txt The Raven - by E.A.Poe]
<
#include <vector>
#include <iostream>
Line 454:
return 0;
}
</syntaxhighlight>
{{out}}
<pre>
Line 462:
=={{header|D}}==
{{trans|Kotlin}}
<
import std.array;
import std.conv;
Line 526:
auto uiList = getUserInput();
decode("theRaven.txt", uiList);
}</
{{out}}
<pre>Silence-Dogood.</pre>
Line 532:
=={{header|Go}}==
{{trans|C++}}
<
import (
Line 610:
log.Fatal(err)
}
}</
{{out}}
Line 619:
=={{header|Java}}==
{{trans|Kotlin}}
<
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Line 737:
decode("theRaven.txt", uiList);
}
}</
{{out}}
<pre>Silence-Dogood.</pre>
Line 745:
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<
def getUserInput:
def nwise($n):
Line 788:
# Input: the text
[emit_until(. == "!"; getUserInput as $ui | decode($ui)) ] | add</
{{out}}
Invocation: jq -Rsr -f program.jq theRaven.txt
Line 797:
=={{header|Julia}}==
Customization is via adding to or deleting from the chars dictionary.
<
chars = Dict(GET_FF => ['\f'], GET_LF => ['\n'], GET_TAB => ['\t'])
Line 836:
stream_decode_jit(open("filename.txt", "r"))
</syntaxhighlight>
=={{header|Kotlin}}==
{{trans|C++}}
<
import java.io.File
Line 889:
val uiList = getUserInput()
decode("theRaven.txt", uiList)
}</
{{out}}
Line 900:
With some modifications compared to the model.
<
type Position = tuple[ff, lf, tab, sp: int]
Line 937:
"33 0 50 0 46 0 54 0 76 0 47 0 84 2 28")
echo "theRaven.txt".decode(UiList)</
{{out}}
Line 945:
{{trans|Raku}}
{{libheader|ntheory}}
<
use warnings;
use feature 'say';
Line 998:
my $enc = jit_encode('The slithey toves did gyre and gimble in the wabe');
say my $result = "Encoded\n$enc\n\nDecoded\n" . jit_decode($enc);</
{{out}}
<pre>Encoded
Line 1,009:
{{trans|C}}
{{libheader|Phix/libcurl}}
<!--<
<span style="color: #000080;font-style:italic;">-- demo/rosetta/BookCipher.exw</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">decode</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">fn</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">sequence</span> <span style="color: #000000;">ui</span><span style="color: #0000FF;">)</span>
Line 1,077:
<span style="color: #000000;">decodeFile</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"theRaven.txt"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"http://paulo-jorente.de/text/theRaven.txt"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">code</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span>
<!--</
{{out}}
<pre>
Line 1,085:
=={{header|Python}}==
{{trans|D}}
<
class UserInput:
Line 1,146:
uiList = getUserInput()
decode("theRaven.txt", uiList)</
{{out}}
<pre>Silence-Dogood.</pre>
Line 1,154:
{{trans|Kotlin}}
<
(define user-input
Line 1,176:
(define c (decode slice))
#:break (char=? #\! c)
(display c))</
{{in}}
Line 1,196:
Will handle any visible character in the ASCII range as well as space and new-line.
<syntaxhighlight lang="raku"
Set srand to set the encode / decode "key".
Need to use the same "key" and same implementation
Line 1,258:
say "\n== Decoded: ==";
say jit-decode($enc);</
<pre>== Secret: ==
Line 1,289:
The input file used by this REXX program only contains one page; it has no ''FF'' (''formfeed'') characters in it),
<br>and the injection of ''FF'' characters into the file would be like putting pencil marks into a holy book. <big><big><big> ☺ </big></big></big>
<
parse arg iFID . /*obtain optional name of file (book).*/
if iFID=='' | iFID=="," then iFID= 'JIT.TXT' /*Not specified? Then use the default.*/
Line 1,323:
?= ? || x /*append the character to the phrase. */
end /*j*/ /* [↑] display letters found in book. */
say '═════►' ? /*stick a fork in it, we're all done. */</
{{out|input|text= supplied to the console (terminal) by the user in response to the prompts, (the commas are optional):}}
<pre>
Line 1,355:
=={{header|Tcl}}==
{{works with|Tcl|8.6}}
<
oo::class create JustInTimeStreamExtract {
Line 1,424:
tcl::mathop::== $counter $counters(page) $counters(line) $counters(field) $counters(char)
}
}</
Demonstration of use:
<
<!-- no output; I'll wait for someone else to invent something to decode… -->
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<
Structure UserInput
Line 1,515:
End Sub
End Module</
{{out}}
<pre>Silence-Dogood.</pre>
Line 1,523:
{{libheader|Wren-dynamic}}
{{libheader|wren-seq}}
<
import "./dynamic" for Tuple
import "./seq" for Lst
var UserInput = Tuple.create("UserINput", ["formFeed", "lineFeed", "tab", "space"])
Line 1,576:
var uiList = getUserInput.call()
decode.call("theRaven.txt", uiList)</
{{out}}
Line 1,585:
=={{header|zkl}}==
{{trans|C++}}
<
fcn decode(file,tuplets){
codePad:=File(file).read().mode(String); // blob of text
Line 1,609:
h.split(" ").pump(List,T(Void.Read,3),
fcn(ff,lf,t,s){ vm.arglist.apply("toInt") });
}</
<
// our code pad is: http://paulo-jorente.de/text/theRaven.txt
FlyBy.decode("theRaven.txt",input);</
{{out}}
<pre>
|