Talk:User defined pipe and redirection operators: Difference between revisions

Line 11:
 
: I don't think the task wants any of the above. Seems the goal is to define stream-like objects where each one's output can be taken up by another as input, and the task's focus is to device a mechanism to drive data through such a chain. BTW, since data flows unidirectionally, it definitely does not require coroutines, all you need to do is have the object at the output end to pull data from upstream on-demand. The problem of the task: it's asking to much. Tail, head, uniq, sort, grep, wc, file io, subshell, redirect-in, redirect-out, pipe -- it's what, reliving 40 years of unix experience in a flash? --[[User:Ledrug|Ledrug]] 02:04, 13 September 2011 (UTC)
 
Adhere to the syntax of the specific language where required, eg the use of brackets and names of operators.
 
I had to use the operator "=:" instead of a "|" char as the pipe character has a special (and fixed) meaning in Algol68.
 
Here is the "''Sample shell script''", but rewritten in Algol.
<lang algol68>PR READ "prelude/general.a68" PR
 
MODE REC = STRING;
FORMAT rec fmt = $g$;
 
PR READ "Coroutine_pipe_operators.a68" PR
PR READ "Coroutine_pipe_utilities.a68" PR
 
FLEX[0]STRING aa;
 
cat (
head(4,) < List_of_computer_scientists.lst,
cat("List_of_computer_scientists.lst" =: grep(ALGOL,) =: tee("ALGOL_pioneers.lst"),
tail(4,"List_of_computer_scientists.lst")
) =: sort =: uniq =: tee("the_important_scientists.lst") =: grep "aa" >> aa;
 
printf(($"Pioneer: ", $" "g$, aa, $l$))
</lang>
I have almost finished, and hope it will take less then 300 lines of code.
 
''' So far:'''
<pre>
$ wc -l *Coroutine_pipe*s.a68
174 Coroutine_pipe_operators.a68
58 Coroutine_pipe_utilities.a68
20 test_Coroutine_pipe_operators.a68
252 total
</pre>
 
This task should be OK in python, especially the operators, and also Ada. I figure the GNU C has a fair chance. C++ should be able to hangle the operator overloading.
 
I'm not familiar enough with other languages to make any comment. (Ocaml can do any thing! (apparently))
 
BTW: Here is a complete implementation of "''tail''":
<lang algol68>PROC tail yield rec = (INT n, CONJUNCTION args, YIELDREC yield)VOID:
FOR argn FROM LWB args TO UPB args DO
INSTREAM rec gen = args[argn];
CASE rec gen IN
(FILENAME name): IF LWB args = UPB args THEN yield("==> "+name+" <==") FI
ESAC;
[0:n-1]REC window; INT window end := -1;
# FOR REC rec IN # cat(rec gen)(#) DO #
## (REC rec)VOID:
window[(window end+:=1) MOD n]:= rec
# OD #);
done:
FOR line FROM window end-n+1 TO window end DO
IF line>=0 THEN
yield(window[line MOD n])
FI
OD
OD;
 
PROC tail = (INT n, CONJUNCTION args)GENREC:
tail yield rec(n, args ,);
 
# Define an optional monadic TAIL OPerator #
OP TAIL = (INT n)MANYTOONE: tail(n,);</lang>
 
Note that this "''tail''" implementation requires just one argument "n", keeping things simple to satisfy the use of tail in the "''Sample shell script''". I'm not asking for reinvention of head/tail etc, just enough to run the "''sample shell script''", basically a proof of concept the each particular language.
 
[[User:NevilleDNZ|NevilleDNZ]] 02:55, 13 September 2011 (UTC)