| Did you know ... | Search Documentation: |
| Pack starlog -- LIST_DUAL_EXPRESSIONS.md |
Complete `[A:...a] is [b:...B] and [A•a:c] is [b•B:c]` with any combination of :, •, [], arithmetic expression or &, and any configuration.
This implementation adds support for list dual expressions without the append operator (&). This enables powerful bidirectional constraint solving for patterns where both sides of is are lists containing concatenation expressions.
Unlike existing patterns that use the append operator &, this feature works with direct list comparisons:
?- [A:a] is [b:B]. A = b, B = a.
Elements can contain nested concatenation expressions mixing different operators:
?- [(A•a):c] is [(b•B):c]. A = b, B = a.
Lists can have multiple elements, each with their own concat expressions:
?- [A•q, x] is [p•q, x]. A = p. ?- [A•a, B•b] is [p•a, r•b]. A = p, B = r.
Nested concatenations are fully supported:
?- [A:x:y] is [p:x:y]. A = p. ?- [((A•a):b):c] is [((p•a):b):c]. A = p.
[A:a] is [b:B] % Basic dual [a:A] is [B:b] % Reversed [A:x] is [p:x] % Matching suffix [x:A] is [x:p] % Matching prefix
[A•a] is [b•B] % Basic dual [a•A] is [B•b] % Reversed [A•x] is [p•x] % Matching suffix [x•A] is [x•p] % Matching prefix
[(A•a):c] is [(b•B):c] % Atom then string [(A:a)•c] is [(b:B)•c] % String then atom [((A•a):b):c] is [((p•a):b):c] % Deeply nested
[A•q, x] is [p•q, x] % One concat, one literal [A•a, B•b] is [p•a, r•b] % Multiple concats [A•a, x, y] is [p•a, x, y] % Concat with literals
[A:x:y] is [p:x:y] % String chain [A•x•y] is [p•x•y] % Atom chain
The feature adds a new detection predicate is_list_dual_expr_with_concat/2 that checks:
&): or •)The solver solve_list_dual_expr/3 works as follows:
string_concat_dual or atom_concat_dual)The existing concat_dual/5 predicate handles various patterns:
(A + b) = (p + b) → A = p(a + B) = (a + q) → B = q
(var(A), nonvar(B), nonvar(C), nonvar(D)) ->
(call(ConcatPred, C, D, Result),
atom_concat(A, B, Result))
This enables solving patterns like (A + a) = (p + q) by computing p + q = pq and then solving A + a = pq.
Extract components from strings/atoms with known patterns:
extract_prefix(Input, Prefix) :-
[Prefix:"_suffix"] is [Input].
Solve multiple concatenation equations simultaneously:
?- [A:"_x", B:"_y"] is ["prefix_x", "other_y"]. A = "prefix", B = "other".
Verify that complex nested expressions match:
?- [((a•b):c)] is [((a•b):c)]. true.
Combine atom and string operations in a single expression:
?- [(Name•"@"):Domain] is [(user•"@"):example_com]. Name = user, Domain = example_com.
Comprehensive test suite with 23 tests covering:
This feature integrates seamlessly with existing Starlog functionality:
(A:a) is (b:B)
See demo_list_dual_expressions.pl for comprehensive demonstrations of all patterns.
Constraints are paired position-wise. If lists have different lengths or incompatible patterns, the system gracefully degrades to standard compilation.
The implementation maintains linear complexity with respect to:
→ A = p`[x:A] is [x:B] needs one of A or B to be knownPotential extensions:
This implementation completes the requirement for list dual expressions, enabling powerful pattern matching and constraint solving capabilities while maintaining full backward compatibility with existing Starlog features.