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

m
→‎{{header|11l}}: new way of specifying file open mode
(Added 11l)
m (→‎{{header|11l}}: new way of specifying file open mode)
 
(2 intermediate revisions by 2 users not shown)
Line 15:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">T UserInput
Int formFeed
Int lineFeed
Line 43:
 
F decode(filename, uiList)
V f = File(filename, ‘r’)
V text = f.read()
 
Line 79:
 
V uiList = getUserInput()
decode(‘theRaven.txt’, uiList)</langsyntaxhighlight>
 
{{out}}
Line 88:
=={{header|C}}==
{{trans|C++}}
<langsyntaxhighlight lang="c">#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
Line 303:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>Silence-Dogood.</pre>
Line 309:
=={{header|C sharp|C#}}==
{{trans|D}}
<langsyntaxhighlight lang="csharp">using System;
using System.Collections.Generic;
using System.Linq;
Line 387:
}
}
}</langsyntaxhighlight>
{{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]
<langsyntaxhighlight lang="cpp">
#include <vector>
#include <iostream>
Line 454:
return 0;
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 462:
=={{header|D}}==
{{trans|Kotlin}}
<langsyntaxhighlight Dlang="d">import std.algorithm;
import std.array;
import std.conv;
Line 526:
auto uiList = getUserInput();
decode("theRaven.txt", uiList);
}</langsyntaxhighlight>
{{out}}
<pre>Silence-Dogood.</pre>
Line 532:
=={{header|Go}}==
{{trans|C++}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 610:
log.Fatal(err)
}
}</langsyntaxhighlight>
 
{{out}}
Line 619:
=={{header|Java}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="java">import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Line 737:
decode("theRaven.txt", uiList);
}
}</langsyntaxhighlight>
{{out}}
<pre>Silence-Dogood.</pre>
Line 745:
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<langsyntaxhighlight lang="jq"># User input takes the form of quadtuples of integers: [formFeed, lineFeed, tab, space]
def getUserInput:
def nwise($n):
Line 788:
 
# Input: the text
[emit_until(. == "!"; getUserInput as $ui | decode($ui)) ] | add</langsyntaxhighlight>
{{out}}
Invocation: jq -Rsr -f program.jq theRaven.txt
Line 797:
=={{header|Julia}}==
Customization is via adding to or deleting from the chars dictionary.
<langsyntaxhighlight lang="julia">@enum streamstate GET_FF GET_LF GET_TAB GET_CHAR ABORT
chars = Dict(GET_FF => ['\f'], GET_LF => ['\n'], GET_TAB => ['\t'])
 
Line 836:
 
stream_decode_jit(open("filename.txt", "r"))
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
{{trans|C++}}
<langsyntaxhighlight lang="scala">// version 1.2.10
 
import java.io.File
Line 889:
val uiList = getUserInput()
decode("theRaven.txt", uiList)
}</langsyntaxhighlight>
 
{{out}}
Line 900:
With some modifications compared to the model.
 
<langsyntaxhighlight Nimlang="nim">import options, sequtils, strutils
 
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)</langsyntaxhighlight>
 
{{out}}
Line 945:
{{trans|Raku}}
{{libheader|ntheory}}
<langsyntaxhighlight lang="perl">use strict;
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);</langsyntaxhighlight>
{{out}}
<pre>Encoded
Line 1,009:
{{trans|C}}
{{libheader|Phix/libcurl}}
<!--<langsyntaxhighlight Phixlang="phix">(notonline)-->
<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>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,085:
=={{header|Python}}==
{{trans|D}}
<langsyntaxhighlight lang="python">import sys
 
class UserInput:
Line 1,146:
 
uiList = getUserInput()
decode("theRaven.txt", uiList)</langsyntaxhighlight>
{{out}}
<pre>Silence-Dogood.</pre>
Line 1,154:
{{trans|Kotlin}}
 
<langsyntaxhighlight lang="racket">#lang racket
 
(define user-input
Line 1,176:
(define c (decode slice))
#:break (char=? #\! c)
(display c))</langsyntaxhighlight>
 
{{in}}
Line 1,196:
Will handle any visible character in the ASCII range as well as space and new-line.
 
<syntaxhighlight lang="raku" perl6line>#`[
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);</langsyntaxhighlight>
 
<pre>== Secret: ==
Line 1,289:
The input file used by this REXX program only contains one page; &nbsp; it has no &nbsp; ''FF'' &nbsp; (''formfeed'') &nbsp; characters in it),
<br>and the injection of &nbsp; ''FF'' &nbsp; characters into the file would be like putting pencil marks into a holy book. &nbsp; <big><big><big> ☺ </big></big></big>
<langsyntaxhighlight lang="rexx">/*REXX program extracts characters by using a book cipher (that is a text file). */
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. */</langsyntaxhighlight>
{{out|input|text=&nbsp; supplied to the console (terminal) by the user in response to the prompts, &nbsp; (the commas are optional):}}
<pre>
Line 1,355:
=={{header|Tcl}}==
{{works with|Tcl|8.6}}
<langsyntaxhighlight lang="tcl">package require Tcl 8.6
 
oo::class create JustInTimeStreamExtract {
Line 1,424:
tcl::mathop::== $counter $counters(page) $counters(line) $counters(field) $counters(char)
}
}</langsyntaxhighlight>
Demonstration of use:
<langsyntaxhighlight lang="tcl">[JustInTimeStreamExtract new] stream [open "sample.txt"]</langsyntaxhighlight>
<!-- no output; I'll wait for someone else to invent something to decode… -->
 
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<langsyntaxhighlight lang="vbnet">Module Module1
 
Structure UserInput
Line 1,515:
End Sub
 
End Module</langsyntaxhighlight>
{{out}}
<pre>Silence-Dogood.</pre>
Line 1,523:
{{libheader|Wren-dynamic}}
{{libheader|wren-seq}}
<langsyntaxhighlight ecmascriptlang="wren">import "io" for File
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)</langsyntaxhighlight>
 
{{out}}
Line 1,585:
=={{header|zkl}}==
{{trans|C++}}
<langsyntaxhighlight lang="zkl">class FlyBy{
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") });
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">input:=getUserInput();
// our code pad is: http://paulo-jorente.de/text/theRaven.txt
FlyBy.decode("theRaven.txt",input);</langsyntaxhighlight>
{{out}}
<pre>
1,480

edits