Commit Graph
449 Commits
Author SHA1 Message Date
Markus Triska a5e72679bc prioritize type errors over instantiation errors
Example:

    ?- must_be(chars, [a,X,cc]).
       error(type_error(character,cc),can_be/2).

See https://github.com/mthom/scryer-prolog/pull/1474#issuecomment-1126664368
2022-05-14 09:53:21 +02:00
Markus Triska 15cc916333 FIXED: can_be(chars, [a,X]), i.e., if variables occur as elements
This should simplify 2f3de51e55 and
other cases like it.
2022-05-14 08:39:20 +02:00
Mark Thom 2f3de51e55 remove non-determinism in number_chars/2 and numbercodes/2 (#1473) 2022-05-13 18:38:58 -06:00
Mark Thom cea1353fbb use must_be(chars) in number_chars/2 (#1470) 2022-05-12 01:09:06 -06:00
Markus Triska d58dd7cc91 ADDED: sign/1 2022-05-05 22:51:49 +02:00
Markus Triska 7e06abebd5 remove comment that seems no longer valid 2022-05-05 22:51:49 +02:00
Mark Thom 0f502fff84 compact lists of characters to partial strings in read_term_from_heap (#1452, #1453) 2022-05-03 19:12:16 -06:00
Mark Thom 23c4e935b4 Merge pull request #1436 from triska/must_be_term
ADDED: can_be(term, ...) and must_be(term, ...)
2022-04-26 13:31:43 -06:00
Markus Triska eea83d9474 ADDED: can_be(term, ...) and must_be(term, ...)
This terminology is a bit harder to understand than that of the other
type checks.

Scryer Prolog comprises two individually consistent but incompatible
notions of terms, namely terms and rational trees (which are also
called "cyclic terms"). This leads to a confusion in terminology,
because cyclic terms are not terms in the former sense even though
they also contain the word "term" in their name.

This terminological confusion is not restricted to terms: We also find
it for example in the notion of lists. Lists are defined inductively:

    - The empty list (written as "" or [], called 'nil') is a list.
    - A term with principal functor '.'/2 is a list if its second argument
      is a list.

Note that a list may contain cyclic terms as elements, and still be
called a list. However, if we post:

    ?- Ls = [_|Ls].

then Ls is not a list, because it does not fit the inductive
definition. Still, it is sometimes referred to as a "cyclic list" or
"circular list", even though it is not a list. Even Prolog
implementors that aim for strict conformance to the Prolog ISO
standard and are deeply familiar with the standard use this
terminology when talking about such terms, see for example:

    https://github.com/ichiban/prolog/pull/198

Consequently, must_be(list, Ls) raises a *type error* in this case.

Terms are distinguished from cyclic terms completely analogously. This
leads to the counterintuitive consequence that *cyclic lists are not
terms*. The reason for this apparent contradiction in terminology is
the mutual incompatibility of different notions of terms. The notion
of "term" precludes rational trees, similar to the notion of "list"
which precludes cyclic lists.

We therefore introduce:

    * must_be(term, Term)
      - raises an instantiation error if Term contains variables (since
        it could still become a rational tree)
      - raises a type error if Term is a rational tree

    * can_be(term, Term)
      - raises a type error if Term is a rational tree

Note that using the notion of "cyclic term" and "acyclic term" in this
terminology would not be a good idea, because this confusion is
precisely what we want to eliminate: must_be(term, Term) should be
usable as a test that reliably determines whether Term can be treated
as a term with the logical properties we expect from terms.

This addresses #1428.
2022-04-20 22:15:32 +02:00
Mark Thom 9d5264c5a3 very minor optimizations 2022-04-17 20:10:13 -06:00
Mark Thom 7595ec16e5 instantiate Module in definition of retract/1 (#1392) 2022-04-13 20:31:16 -06:00
Mark Thom d644a3996e use '$call' all throughout setup_call_cleanup/3 2022-04-12 17:27:48 -06:00
Mark Thom 00eab4d415 print errors as goals (#1408) 2022-04-09 14:01:48 -06:00
Markus Triska 1fa8a0a969 ENHANCED: more memory efficient call_nth/2 (#1264)
I hope that this will allow more extensive tests of Scryer Prolog. Enjoy!
2022-04-02 17:42:45 +02:00
Markus Triska f7e31fceac as --> is 2022-03-30 21:33:46 +02:00
Adrián Arroyo Calle 6798b22b49 http_open/3 with headers and data 2022-03-28 20:38:55 +02:00
Adrián Arroyo Calle 3acbe2a418 http_open/3 with method option 2022-03-28 20:38:52 +02:00
Markus Triska 1a7992e524 ENHANCED: use newly available must_be(chars, ...), which is very fast 2022-03-26 19:09:54 +01:00
Mark Thom 895b02b641 improve length/2 (#1325) 2022-03-15 18:43:57 -06:00
Markus Triska 69e52d1ed8 ENHANCED: call_nth(Goal, 0) now fails, correct error for N < 0.
This addresses #1307.
2022-03-07 23:38:30 +01:00
Paulo Moura 0532f51cc2 Fix querying the values of the bounded and max_arity flags 2022-03-07 00:30:35 +00:00
Paulo Moura 495168e7bb Fix halt/1 built-in predicate for ISO Prolog Core standard compliance 2022-03-06 21:33:49 +00:00
Markus Triska c6264cf098 ADDED: library(simplex), for solving linear programming problems. 2022-03-06 21:49:52 +01:00
Mark Thom 2d19243b3b Merge branch 'rebis-dev' into 0.9.0 release
Test / build (macos-10.15, beta) (push) Has been cancelled
Test / build (macos-10.15, stable) (push) Has been cancelled
Test / build (ubuntu-20.04, beta) (push) Has been cancelled
Test / build (ubuntu-20.04, stable) (push) Has been cancelled
2022-03-06 09:45:05 -07:00
Mark Thom 0c19c56909 mark variables in ArithmeticEvaluator (#690) 2022-03-05 17:57:10 -07:00
Mark Thom de35baadf3 use must_be(chars) in read_from_chars/2 (#1305) 2022-03-05 17:39:13 -07:00
Mark Thom d7a3ed2d4a change domain_error(integer, ..) to type_error(integer, ..) in random.pl (#1310) 2022-03-05 17:39:13 -07:00
Mark Thom d4d135f2a9 fix unexpected error in length/2 (#1303) 2022-02-27 11:38:48 -07:00
Mark Thom 96faad1c01 add proper error throwing for call_with_inference_limit/3 (#1296) 2022-02-27 11:38:44 -07:00
Markus Triska 8fb673e93e use newly available get_n_chars/3 from library(charsio) 2022-02-23 00:03:36 +01:00
Mark Thom 55d8de1b23 delay callable errors in control predicates (#1282) 2022-02-19 00:59:59 -07:00
Mark Thom 68ac92a616 don't unify module-qualified variables to ! (#1281) 2022-02-14 18:46:15 -07:00
Mark Thom 60dd47c696 add missing fact to beginning of tmember_t/3 (#1275) 2022-02-11 17:25:01 -07:00
Mark Thom e62875ac90 tag length/2 as the source of finite_memory errors in list.pl (#1259) 2022-01-31 18:08:00 -07:00
Mark Thom 0d653a2ce6 improve '$skip_max_list'/4 and length/2 (#1023, #110) 2022-01-29 12:47:26 -07:00
Mark Thom 142ddcd57a use expand_goal directly for existential-qualified goals in all-solutions predicates (#1246) 2022-01-26 17:34:36 -07:00
Mark Thom e6c4ecfc10 lazily throw exceptions of dcg_body from goal-expanded phrase/{2,3} (#1244) 2022-01-22 14:55:18 -07:00
Mark Thom 8df346f377 expand phrase/{2,3} using dcg_body whenever possible 2022-01-21 08:10:55 -07:00
Mark Thom 1854338ff4 throw errors from phrase/{2,3} where expected (#1220) 2022-01-19 20:19:47 -07:00
Mark Thom 11b96875e0 streamline and fix phrase/{2,3} (#1237) 2022-01-19 20:07:15 -07:00
Mark Thom 59992c8af2 remove number/3 from arithmetic.pl (#1170) 2022-01-18 17:38:45 -07:00
Mark Thom 3ebf8d5db9 clear alias in close before resetting the stream to null (#1231) 2022-01-17 17:58:14 -07:00
Mark Thom 413f797155 Merge pull request #1228 from triska/charsio-read-renames
MODIFIED: Rename two predicates in library(charsio)
2022-01-17 17:03:46 -07:00
Markus Triska 516ed1fd5b ENHANCED: library(crypto): Retain a compact internal representation of the ciphertext throughout decryption.
This allows efficient decryption also of very large files and long
strings.

It is usually highly advisable to stick to common and portable library
predicates such as append/3. However, since append/3 does not yet
recognize this opportunity for improvement, I apply it manually in
this case, so that also very large files can be efficiently decrypted
using the compact internal string representation.

Without this change, decrypting a 1 GB file takes 48 GB of RAM,
whereas with this change, it only takes 2 GB (one for the string, one
for its copy with the appended tag).
2022-01-17 23:02:56 +01:00
Jos De Roo 1a4f8f992b Update clpz.pl
While running with scryer-prolog the resource control file should be ~/.scryerrc
2022-01-17 22:35:31 +01:00
Markus Triska 23adfef281 MODIFIED: library(charsio): read_n_chars/3 is now called get_n_chars/3
This is because "read" is associated with general Prolog terms.
2022-01-17 20:37:55 +01:00
Markus Triska 20b6816562 MODIFIED: library(charsio): read_term_from_chars/2 is now called read_from_chars/2
This is for compatibility with SICStus Prolog and GNU Prolog.
2022-01-17 20:21:18 +01:00
Mark Thom d22bbc54c7 Merge pull request #1195 from triska/rebis-dev-format-U
ADDED: format specifier ~NU, using underscores to separate groups of digits
2022-01-11 22:49:38 -07:00
Mark Thom e3622e0860 improve between_/3 implementation (#1186, #1191) 2022-01-10 18:34:25 -07:00
Markus Triska 2889a4438b ADDED: format specifier ~NL to limit the number of digits per line
Example:

    %?- format("~65L", [2^1000]).
    %@ 10715086071862673209484250490600018105614048117055336074437503883_
    %@ 70351051124936122493198378815695858127594672917553146825187145285_
    %@ 69231404359845775746985748039345677748242309854210746050623711418_
    %@ 77954182153046474983581941267398767559165543946077062914571196477_
    %@ 686542167660429831652624386837205668069376   true.
2022-01-10 17:52:42 +01:00