Did you know ... Search Documentation:
Packs (add-ons) for SWI-Prolog

Package "predicate_streams"

Title:Implement your own Abstract Predicate Streams
Rating:Not rated. Create the first rating!
Latest version:1.1.118
SHA1 sum:9be3bb4ca1cc46fe478b515f5a5eff773a79946b
Author:Douglas R. Miles <logicmoo@gmail.com>
Maintainer:TeamSPoon https://github.com/TeamSPoon/
Packager:TeamSPoon/LogicMoo https://github.com/TeamSPoon/
Home page:https://github.com/TeamSPoon/predicate_streams
Download URL:https://github.com/TeamSPoon/predicate_streams/releases/*.zip

Reviews

No reviews. Create the first review!.

Details by download location

VersionSHA1#DownloadsURL
0.0.1e8b677dfcc5ed68f101b95e6e79493daf0a2471d1https://github.com/TeamSPoon/predicate_streams.git
0.0.2753711ff6c0e909a4940fe719e7bdd861cf4f8f31https://github.com/TeamSPoon/predicate_streams.git
0.0.36e46bee4f77fd8026ddf2b5bf112715e47a97a9d1https://github.com/TeamSPoon/predicate_streams.git
0.0.421eebf663b4d2bc4d75289bdffe4a25bcfaa29561https://github.com/TeamSPoon/predicate_streams.git
1.1.113c5ac0aa9a97b4b42c0777450c6dd984b33b04e411https://github.com/TeamSPoon/predicate_streams.git
1.1.1154d92395ac7e7ab0c555ad772a590a845f8059a931https://github.com/TeamSPoon/predicate_streams.git
1.1.1176bf8a1063dfdbcdda5d8b70ac937b38e4f37322d1https://github.com/TeamSPoon/predicate_streams.git
1.1.118561a5f08d0174c3e4fd618b3adf21eee95b8eefe1http://github.com/TeamSPoon/predicate_streams.git
6b5aa6e2b61a6cbbe92d607000608d0ef53b20131http://github.com/TeamSPoon/predicate_streams.git
8a5fc3991b8e0b2556df14b6ac59de999878a4e71https://github.com/TeamSPoon/predicate_streams.git
9be3bb4ca1cc46fe478b515f5a5eff773a79946b1http://github.com/TeamSPoon/predicate_streams.git

Implement your own Abstract Predicate Streams

18+ Years ago I remember these predicates existed as the building blocks for writing your own Sockets in some Prolog I cannot remember.

Installation using SWI-Prolog 7.1 or later:

?- pack_install('https://github.com/TeamSPoon/predicate_streams.git').

Source code available and pull requests accepted at http://github.com/TeamSPoon/predicate_streams

Example usages

?- with_output_to_predicate({}/[X]>>assert(saved_output(X)),
     (write("hi there"),nl,writeln("how are you?"))),
     listing(saved_output/1).

saved_output("hi there\n").
saved_output("how are you?\n").
?- with_input_from_predicate(=('hello.\n'), read(World)).
World = hello.

@ BUG

% this works
?- call(({}/[X]>>(repeat,X='Y')),Y).
Y = 'Y' ;
Y = 'Y' ;
Y = 'Y' ;
Y = 'Y' ;
Y = 'Y' ;
Y = 'Y' .

% but not this ?
?- with_input_from_predicate(({}/[X]>>(repeat,X='YN')),(get_char(C0),get_char(C1),get_char(C2),get_char(C3))).
C0 = 'Y',
C1 = 'N',
C2 = C3, C3 = end_of_file.

expected
C0 = C2, C1 = C3,
C2 = 'Y',
C3 = 'N'.

% Auto presses Y Multiple times
?- with_input_from_predicate({}/[X]>>X='YYYYYYYYYYYYYYYYYYYYYYYY', poor_interactive_goal).


?- with_error_to_predicate(write,threads).
... writes thread info to stdout instead of stderr...
?- with_output_to_predicate(print_as_html_pre,
    (writeln("hi there"),writeln("how are you?"))).

<pre>hi there
</pre>
<pre>how are you?
</pre>

Some TODOs

Document this pack! Write tests

BSD 2-Clause License

Copyright (c) 2017, Douglas Miles <logicmoo@gmail.com> and TeamSPoon All rights reserved.

Not obligated to maintain a git fork just to contribute

Dislike having tons of forks that are several commits behind the main git repo?

Be old school - Please ask to be added to TeamSPoon and Contribute directly ! Still, we wont stop you from doing it the Fork+PullRequest method

Contents of pack "predicate_streams"

Pack contains 9 files holding a total of 25.7K bytes.