Commit Graph

632 Commits

Author SHA1 Message Date
Markus Triska
bd75e9c184 more elegant solution for parsing numeric arguments, using a DCG 2021-11-16 18:25:35 +01:00
Markus Triska
23df16ecf9 mention the format("~s", [Ls]) pattern and new library(pio) predicates 2021-11-16 18:20:58 +01:00
Mark Thom
75b01d5021 Merge pull request #1082 from pmoura/fix_format_predicates_missing_numbervars_option_on_w_and_q_formats
Fix the format/2-3 predicates missing the numbervars(true) option in the ~w and ~q formats
2021-11-13 00:05:26 -05:00
Mark Thom
297f126f66 Merge pull request #1078 from triska/pio_improvements
Various improvements for pure output
2021-11-13 00:03:57 -05:00
Markus Triska
57877107d8 use functional notation for all meta_predicate/1 directives 2021-11-11 19:29:32 +01:00
Markus Triska
e9b4a99c8f FIXED: meta_predicate/1 directive for call_nth/2.
This addresses #1021.
2021-11-11 19:26:27 +01:00
Paulo Moura
7ea20d9ce9 Fix the format/2-3 predicates missing the numbervars(true) option in the ~w and ~q formats 2021-11-08 22:00:02 +00:00
Markus Triska
3045f327d5 FIXED: instantiation errors for alias(Var) in open/4 options
This addresses #1030.
2021-11-08 22:41:04 +01:00
Markus Triska
2d1f182c49 FIXED: instantiation errors for type(Var) in open/4 options
This addresses #1030.
2021-11-08 22:37:46 +01:00
Markus Triska
0677f51717 add motivation and comments about library(pio) predicates 2021-11-08 22:18:30 +01:00
Markus Triska
a9bfeb0e96 use newly available library predicate read_n_chars/3 2021-11-08 21:51:03 +01:00
Markus Triska
a0a01b8ba7 ADDED: library(format): DCG nonterminal portray_clause_//1, in analogy to format_//2. 2021-11-07 17:47:05 +01:00
Markus Triska
e32215e19a express format/3 and portray_clause/2 in terms of phrase_to_stream/2 2021-11-07 17:47:05 +01:00
Markus Triska
893fb0e3cc ADDED: phrase_to_stream/2, writing a list of characters to a stream. 2021-11-07 17:44:45 +01:00
Mark Thom
8457a19792 Merge pull request #1071 from triska/read_n_chars
ADDED: read_n_chars/3, reading N characters from a stream.
2021-11-07 09:40:03 -05:00
Mark Thom
0b2638b201 Merge pull request #1070 from triska/open_stream
ENHANCED: open/4 to allow opening a stream by specifying stream(S).
2021-11-07 09:39:41 -05:00
Markus Triska
52af955463 import also partial_string/3 (used in #1071) 2021-11-04 18:50:40 +01:00
Markus Triska
09e886db0b ADDED: read_n_chars/3, reading N characters from a stream. 2021-11-04 18:36:27 +01:00
Markus Triska
f668640e3d move error handling to Prolog by using the new '$first_non_octet'/2 2021-11-04 18:35:22 +01:00
Markus Triska
afcd44deaa ENHANCED: open/4 to allow opening a stream by specifying stream(S).
This allows switching standard output to binary, using for example:

  ?- current_output(S0), open(stream(S0), write, S, [type(binary)]).

format/3 can then be used to write binary data to S. This is needed
for example when piping binary data to other programs.

This addresses #614, please read the discussion for more information.

The current implementation is very preliminary: Specifically, it works
by destructively modifiying the parameters of the underlying stream,
making it no longer usable in its original mode. Currently, if the
type of standard output is set to binary, then the toplevel no longer
works. Therefore, after writing binary output to standard output,
the program should either halt, or set the stream type back to text.
2021-11-04 18:33:40 +01:00
Markus Triska
8c8c21c63b use partial_string/1 for much quicker test 2021-11-04 00:12:00 +01:00
Markus Triska
55dabbe16a use '$first_non_octet'/2 for much faster domain check 2021-11-04 00:12:08 +01:00
Markus Triska
320ee072e6 ENHANCED: Much faster Base64 encoding/decoding, using partial_string/1 for a quick check. 2021-11-03 22:07:20 +01:00
Adrián Arroyo Calle
6a0f638d40 Disable check of atom and leverage to open/4 the domain_error 2021-10-29 23:52:08 +02:00
Adrián Arroyo Calle
2480c6633c Disable check of atom and leverage to open/4 the domain_error 2021-10-29 23:51:30 +02:00
Adrián Arroyo Calle
44dd9ae9fb Go back and accept only list of chars 2021-10-15 17:22:15 +02:00
Adrián Arroyo Calle
3f4d62952a Accept atom or shell 2021-10-14 22:52:29 +02:00
Adrián Arroyo Calle
391cda919f Implement shell/1 and shell/2 2021-10-11 22:35:05 +02:00
Markus Triska
ded4a75b9c use round brackets for meta_predicate declarations
This is because meta_predicate is not a standard operator.
2021-09-04 22:02:17 +02:00
Markus Triska
9e75eb35a0 ADDED: Rudimentary version of phrase_to_file/2 in library(pio)
See #691 for more information.
2021-09-04 21:13:51 +02:00
Markus Triska
9e13f18463 ENHANCED: Domain error non_empty_list for empty arguments, addressing #1024.
Example:

    ?- format("~d", []).
    %@ caught: error(domain_error(non_empty_list,[]),format_//2)
2021-08-15 12:29:28 +02:00
Markus Triska
9d3f3eb013 ENHANCED: format_string domain error for invalid radix in format string
This addresses #1024.

Example:

    ?- format("hello ~0r!", [12]).
    %@ caught: error(domain_error(format_string,"~0r"),format_//2)
2021-08-14 20:04:07 +02:00
Markus Triska
78c2f19e72 ENHANCED: If N is omitted in ~Nr or ~NR, it defaults to 8.
This is for compatibility with Quintus, SICStus and GNU Prolog,
addressing #1024.

Example:

    ?- format("~r", [10]).
    %@ 12   true.
2021-08-14 13:48:21 +02:00
Markus Triska
bf9654e138 ADDED: ... //0, describing an arbitrary number of elements
This is a very versatile nonterminal. For instance, repeated elements:

    ?- phrase((...,[E],...,[E],...), "hello!!").
    %@    E = l
    %@ ;  E = !
    %@ ;  false.
2021-07-03 09:54:01 +02:00
Mark Thom
4decd1d784 Merge pull request #996 from triska/master
address #995: wrong results for popcount/1
2021-06-22 11:56:56 -06:00
Markus Triska
3e7cd24814 address #995: wrong results for popcount/1
Many thanks to @notoria and @flexoron for very useful test cases!
2021-06-21 21:19:37 +02:00
Mark Thom
3e0bece53a Merge pull request #993 from triska/master
ADDED: popcount(+Integer)
2021-06-18 18:13:30 -06:00
Regan-Koopmans
f5eadb2957 981 Prefer must_be/2 2021-06-18 08:22:43 +02:00
Markus Triska
ee393c66dd ADDED: popcount(+Integer)
Example:

    ?- X #= popcount(3+5).
       X = 1.

This builds on #986 provided by @Regan-Koopmans. Many thanks!
2021-06-17 20:18:36 +02:00
Regan-Koopmans
72a7765b58 981 Reimplement as library system call 2021-06-17 12:10:25 +02:00
Markus Triska
066f740819 check for correct domain of integers in reifiable expressions also in the expanded code
This is to preserve domain errors instead of failing silently. Example:

   ?- 5 #> 3 #<==> 2.
   %@ caught: error(domain_error(clpz_reifiable_expression,2),unknown(2)-1)
2021-06-03 22:57:58 +02:00
Markus Triska
fc8d33a98a ENHANCED: Goal expansion for reified constraints.
Used in package precautionary by @dcnorris.
2021-06-03 20:26:44 +02:00
Mark Thom
87ef3519d9 Merge pull request #972 from pmoura/add_pid_predicate
Add pid/1 predicate to the os library
2021-05-19 14:09:21 -06:00
Mark Thom
9002c33046 leave the expansion of incomplete goals in meta-predicates to call/N (#967, #970) 2021-05-19 14:07:46 -06:00
Paulo Moura
b9ad6f4fd2 Add pid/1 predicate to the os library 2021-05-18 20:05:30 +01:00
Paulo Moura
58555d598b Add rename_file/2 predicate to the files library 2021-05-18 18:08:30 +01:00
Mark Thom
0eeae24049 Merge pull request #968 from pmoura/add_make_directory_path_predicate
Add make_directory_path/1 predicate to the files library
2021-05-18 10:26:06 -06:00
Paulo Moura
eeac3bc436 Add delete_directory/1 predicate to the files library 2021-05-18 08:41:19 +01:00
Paulo Moura
bdebc7f32e Add make_directory_path/1 predicate to the files library 2021-05-18 00:21:11 +01:00
Paulo Moura
0e263dd753 Fix current_predicate/1 predicate error checking 2021-05-16 23:49:21 +01:00