trealla-prolog / trealla

A compact, efficient Prolog interpreter written in plain-old C.
MIT License
252 stars 11 forks source link

Apropos reading/writing. Trying to read from a named pipe: #559

Closed infradig closed 2 days ago

infradig commented 2 days ago
          Apropos reading/writing. Trying to read from a named pipe:

$ mkfifo /tmp/treafo

%%% test_matrix_det_fifo.pl example %%% : main :- open('/tmp/treafo', read, S), matread(S, , [alias(foo1)]), : %%%

$ cat test_matrix_det.mat > /tmp/treafo & $ tpl test_matrix_det_fifo.pl 1.0 % Should print 34637561460.0? ?-

Originally posted by @flexoron in https://github.com/trealla-prolog/trealla/issues/558#issuecomment-2198868681

infradig commented 2 days ago
$ cat samples/test_matrix_fifo_det.pl 
:- initialization(main).

% Should print 34637561460.0

main :-
    open('/tmp/treafo', read, S),
    mat_read(S, _, [alias(foo1)]),
    close(S),
    mat_lup_det(foo1, Det),
    write(Det), nl.
$ 
$ mkfifo /tmp/treafo
$ cat samples/test_matrix_det.mat > /tmp/treafo && tpl -g halt samples/test_matrix_fifo_det.pl 
34637561460.0
$
flexoron commented 2 days ago

I don't get this. 'cat' hangs until a reader (tpl) does open and read. The other way around also doesn't work: $ tpl samples/test_matrix_fifo_det.pl % waits for input

In another terminal: $ cat samples/test_matrix_det.mat > /tmp/treafo $ Now tpl prints 1.0

infradig commented 2 days ago

Ok, I must have had data in the fifo from fooling around. I now get 1.0

flexoron commented 2 days ago

Now I get 34637561460.0 Cool format string. Great!