Prolog "atoms"
Admin User, created Apr 06. 2025
/**
* Warranty & Liability
* To the extent permitted by applicable law and unless explicitly
* otherwise agreed upon, XLOG Technologies AG makes no warranties
* regarding the provided information. XLOG Technologies AG assumes
* no liability that any problems might be solved with the information
* provided by XLOG Technologies AG.
*
* Rights & License
* All industrial property rights regarding the information - copyright
* and patent rights in particular - are the sole property of XLOG
* Technologies AG. If the company was not the originator of some
* excerpts, XLOG Technologies AG has at least obtained the right to
* reproduce, change and translate the information.
*
* Reproduction is restricted to the whole unaltered document. Reproduction
* of the information is only allowed for non-commercial uses. Selling,
* giving away or letting of the execution of the library is prohibited.
* The library can be distributed as part of your applications and libraries
* for execution provided this comment remains unchanged.
*
* Restrictions
* Only to be distributed with programs that add significant and primary
* functionality to the library. Not to be distributed with additional
* software intended to replace any components of the library.
*
* Trademarks
* Jekejeke is a registered trademark of XLOG Technologies AG.
*/
runner_file(calculate, atoms, 'XLOG 1.1 atoms').
/****************************************************************/
/* Atom I/O */
/****************************************************************/
/* get_atom(A, O) */
runner_pred(get_atom, 2, calculate, atoms, 'XLOG 1.1.2').
runner_case(get_atom, 2, calculate, atoms, 'XLOG 1.1.2, XLOG 1') :-
with_text_from('abc\r\ndef.', get_atom(X, [stop(0'.)])),
X == 'abc\ndef.'.
runner_case(get_atom, 2, calculate, atoms, 'XLOG 1.1.2, XLOG 2') :-
with_text_from('abc\r\ndef.', get_atom(X, [stop(0'.), compress(false)])),
X == 'abc\r\ndef.'.
runner_case(get_atom, 2, calculate, atoms, 'XLOG 1.1.2, XLOG 3') :-
with_text_from('abc\r\ndef.', get_atom(X, [stop(0'.), compress(false), max(5)])),
X == 'abc\r\n'.
runner_case(get_atom, 2, calculate, atoms, 'XLOG 1.1.2, XLOG 4') :-
with_text_from('abc', get_atom(X, [stop(0'.), compress(false), max(5)])),
X == abc.
runner_case(get_atom, 2, calculate, atoms, 'XLOG 1.1.2, XLOG 5') :-
with_text_from('abc\r\ndef\n', get_atom(X, [])),
X == 'abc\n'.
runner_case(get_atom, 2, calculate, atoms, 'XLOG 1.1.2, XLOG 6') :-
with_text_from('abc\rdef\n', get_atom(X, [])),
X == 'abc\n'.
/****************************************************************/
/* Term Atom */
/****************************************************************/
/* term_atom(X, Y) */
runner_pred(term_atom, 2, calculate, atoms, 'XLOG 1.1.3').
runner_case(term_atom, 2, calculate, atoms, 'XLOG 1.1.3, XLOG 1') :-
term_atom(1 < 2, A),
(A == '1 < 2'; A == '1<2').
runner_case(term_atom, 2, calculate, atoms, 'XLOG 1.1.3, XLOG 2') :-
term_atom('$VAR'(1), A),
A == ''$VAR'(1)'.
runner_case(term_atom, 2, calculate, atoms, 'XLOG 1.1.3, XLOG 3') :-
term_atom('Foo', A),
A == ''Foo''.
runner_case(term_atom, 2, calculate, atoms, 'XLOG 1.1.3, XLOG 4') :-
T is pi, term_atom(T, A),
(A == '3.141592653589793'; A == '3.1415926535897931').
runner_case(term_atom, 2, calculate, atoms, 'XLOG 1.1.3, XLOG 5') :-
term_atom(T, '1+2*3'),
T == 1+2*3.
runner_case(term_atom, 2, calculate, atoms, 'XLOG 1.1.3, XLOG 6') :-
term_atom(T, 'X is pi', [variable_names(L)]),
T = (A is pi), L = ['X' = B], A == B.
/****************************************************************/
/* UTC Time Atoms */
/****************************************************************/
/* atom_time(S, F, T, L) mode (-, +, +, +) */
runner_pred(sys_utctime_format , 3, calculate, atoms, 'XLOG 1.1.4').
runner_case(sys_utctime_format , 3, calculate, atoms, 'XLOG 1.1.4, XLOG 1') :-
atom_time(X, '%d/%m/%Y', 1699965488687, [face(utc)]),
X == '14/11/2023'.
runner_case(sys_utctime_format , 3, calculate, atoms, 'XLOG 1.1.4, XLOG 2') :-
atom_time(X, '%d.%m.%Y %H:%M', 1699965488687, [face(utc)]),
X == '14.11.2023 12:38'.
runner_case(sys_utctime_format , 3, calculate, atoms, 'XLOG 1.1.4, XLOG 3') :-
atom_time(X, '%a, %d %b %Y %H:%M:%S', 1727128257073, [face(utc)]),
X = 'Mon, 23 Sep 2024 21:50:57'.
runner_case(sys_utctime_format , 3, calculate, atoms, 'XLOG 1.1.4, XLOG 4') :-
atom_time(X, '%%-%%', 0, [face(utc)]),
X == '%-%'.
runner_case(sys_utctime_format , 3, calculate, atoms, 'XLOG 1.1.4, XLOG 5') :-
catch(atom_time(1699965488687, '%d.%m.%Y %H:%M', _, [face(utc)]), error(E,_), true),
E == type_error(atom, 1699965488687).
/* atom_time(S, F, T, L) mode (+, +, -, +) */
runner_pred(sys_utctime_parse, 3, calculate, atoms, 'XLOG 1.1.5').
runner_case(sys_utctime_parse, 3, calculate, atoms, 'XLOG 1.1.5, XLOG 1') :-
atom_time('14/11/2023', '%d/%m/%Y', X, [face(utc)]),
X = 1699920000000.
runner_case(sys_utctime_parse, 3, calculate, atoms, 'XLOG 1.1.5, XLOG 2') :-
atom_time('14.11.2023 12:38', '%d.%m.%Y %H:%M', X, [face(utc)]),
X = 1699965480000.
runner_case(sys_utctime_parse, 3, calculate, atoms, 'XLOG 1.1.5, XLOG 3') :-
catch(atom_time('14/11/2023 12:38', '%d.%m.%Y %H:%M', _, [face(utc)]), error(E,_), true),
E == syntax_error(illegal_date).
runner_case(sys_utctime_parse, 3, calculate, atoms, 'XLOG 1.1.5, XLOG 4') :-
atom_time('Mon, 23 Sep 2024 21:50:57', '%a, %d %b %Y %H:%M:%S', X, [face(utc)]),
X == 1727128257000.
runner_case(sys_utctime_parse, 3, calculate, atoms, 'XLOG 1.1.5, XLOG 5') :-
catch(atom_time('Mo, 23 Sep 2024 21:50:57', '%a, %d %b %Y %H:%M:%S', _, [face(utc)]), error(E,_), true),
E == syntax_error(illegal_date).
runner_case(sys_utctime_parse, 3, calculate, atoms, 'XLOG 1.1.5, XLOG 6') :-
atom_time('MON, 23 Sep 2024 21:50:57', '%a, %d %b %Y %H:%M:%S', X, [face(utc)]),
X == 1727128257000.
runner_case(sys_utctime_parse, 3, calculate, atoms, 'XLOG 1.1.5, XLOG 7') :-
catch(atom_time('foo 1234 bar', 'foo %i bar', _, [face(utc)]), error(E,_), true),
E == domain_error(time_format, 'foo %i bar').
runner_case(sys_utctime_parse, 3, calculate, atoms, 'XLOG 1.1.5, XLOG 8') :-
catch(atom_time(_, '%d.%m.%Y %H:%M', '14/11/2023', [face(utc)]), error(E,_), true),
E == type_error(integer, '14/11/2023').