Luxembourg National Day Code Drop: A replacement for must_be/2, a dict prettyprinter and assorted stuff

It’s actually one day late for a Luxembourg National Day Code Drop, but good enough.

This was an astonishing amount of work, I had to hammer my way out of this one, took … months? Yes, months.

We have a number of READMEs. The one for the must_be/2 replacement is out of synch with the code at this point in time.

General README for the whole pack.

Extensive test cases exist.

A pack is available (check out the general README above).

Major elements

checks.pl

A more powerful replacement for the venerable must_be/2. The predicates provided by checks.pl are used throughout other code.

README_checks.md

You can write things like:

check_that(X,[break(var),hard(stringy),soft(nonempty_stringy)]).

Which accepts a var, then throws if X is not “stringy” (atom or string) and then fails if X is empty.

If you don’t like to throw and want to switch to “soft” behaviour programmatically:

check_that(X,[break(var),tuned(stringy),soft(nonempty_stringy)],Tuned).

Instantiate Tuned to soft to fail on test violation, or hard to throw.

(Is it fast? Probably not that fast, so one would probably want to compile-out the “hard”, exception throwing checks which should never be triggered in well-working code)

dict_pp.pl

An SWI-Prolog dict prettyprinter, which can also deal with dicts-within-dicts.

README_dict_pp.md

?- dict_pp(various{w: 0.25984759, ww: 1.4587598, www: 643764856, wwww: 400},
           _{border:true}).
+----------------+
|    various     |
+----------------+
|w    : 0.259848 |
|ww   : 1.458760 |
|www  : 643764856|
|wwww : 400      |
+----------------+
true.

Minor elements mostly in support of dict_pp.pl

These are a grabbag:

stringy_morph.pl

A “logical” mapper between atoms and SWI-Prolog strings and “list representations”
of character sequences, i.e. “proper lists of char” and “proper lists of code”.

Provides replacement for the predicates
atom_string/2,
atom_codes/2,
string_chars/2,
string_codes/2.

README_stringy_morph.md

I already posted an announcement about this little predicate set a bit earlier this year.

space_stringy.pl

Create or accept atoms or strings made only of the SPACE character (Unicode code point 0x20).

README_space_stringy.md

stringy_and_charylist_type.pl

Analysis of “stringy” (atom or string) and “chary” (lists of chars or codes) terms.

README_stringy_and_charylist_type.md

stringy_concat.pl

Concantenate several “stringy” terms (atoms or strings) to a single “stringy” term.
A front-end to the corresponding SWI-Prolog predicates.

README_stringy_concat.md

stringy_length.pl

Determine the length of a “stringy” term (atom or string). A front-end to the corresponding SWI-Prolog predicates, but also provides or accepts type information.

README_stringy_length.md

stringy_justify.pl

Justify text left, right or center in a field of a given width. This is an ingredient of the dict prettyprinter.

README_stringy_justify.md

stringy_overwrite.pl

Overwrite background text with foreground text. This is an ingredient of the dict prettyprinter.

README_stringy_overwrite.md

safe_format.pl

A simple predicate fronting format/3, but able to survive a mistake in the number or type of arguments without throwing. Strongly useful in any code which may not have been given 100% coverage.

README_safe_format.md (README TO BE DONE)

meta_helpers.pl

Various meta-predicate meant to make code writing and especially reading easier.
Only semi-useful.

README_meta_helpers.md (README TO BE DONE)

dict_settings.pl

A very small set of predicates that are meant to use a dict as an options container, possibly providing defaults for missing options.

README_dict_settings.md (README TO BE DONE)

4 Likes

Thans Jan.

Your libraries do not use this feature of SWI-Prolog.

Actually they do - print_error_message.pl hooks into prolog:print_error_message//1 to generate text for the toplevel. As is the local custom.