| Did you know ... | Search Documentation: |
| Pack starlog -- DUAL_EXPRESSION_FIX.md |
The issue addressed was:
Please make [A&[x]&[y]&[z]] is [[p]&[x]&[y]&[z]]. A = [p] ; not hang afterwards.
When using dual Starlog expressions with nested list appends, the system could hang during backtracking, particularly when using predicates like findall/3 that attempt to find all solutions.
% This would hang with findall before the fix findall(A, starlog_call(([A&[x]&[y]&[z]] is [[p]&[x]&[y]&[z]])), Solutions).
The hang occurred because:
append(A,[x],T1), % A is unbound - generates infinite solutions! append(T1,[y],T2), append(T2,[z],Result), LHS = [Result], LHS = RHS, append([p],[x],R1), append(R1,[y],R2), append(R2,[z],RResult), RHS = [RResult]
append(A,[x],T1) with A unbound generates infinite solutions through backtracking:
The fix reorders the goals to execute the more ground side first and reverses the less ground side's pre-goals to ensure proper constraint propagation:
% New order: append([p],[x],R1), % RHS pre-goals first (more ground) append(R1,[y],R2), append(R2,[z],RResult), RHS = [RResult], % RHS result goal LHS = RHS, % Unification LHS = [Result], % LHS result goal - now Result is constrained! append(T2,[z],Result), % LHS pre-goals in REVERSE - most constrained first append(T1,[y],T2), append(A,[x],T1) % Now when we reach this, T1 is already constrained
append(T2,[z],Result) first where Result is already bound to [p,x,y,z], we constrain T2 = [p,x,y]. Then append(T1,[y],T2) with T2 bound constrains T1 = [p,x]. Finally append(A,[x],T1) with T1 bound constrains A = [p].The fix was verified with comprehensive tests:
% Test 1: Exact problem statement ?- starlog_call(([A&[x]&[y]&[z]] is [[p]&[x]&[y]&[z]])). A = [p]. % ✓ Works correctly % Test 2: No hang with findall ?- findall(A, starlog_call(([A&[x]&[y]&[z]] is [[p]&[x]&[y]&[z]])), Solutions). Solutions = [[p]]. % ✓ Single solution, no infinite backtracking % Test 3: Multiple nested appends ?- starlog_call(([A&[1]&[2]&[3]&[4]] is [[r]&[1]&[2]&[3]&[4]])). A = [r]. % ✓ Works with longer chains
starlog_expand.pl - Core fix implementationtests/test_dual_expression_fix.pl - Comprehensive test suite for the fixThis fix ensures that the problem statement requirement is fully met:
A = [p]