bakaq / constrained.pl

Provides generalized versions of common Prolog predicates using constraints to make them more flexible and declarative.
The Unlicense
8 stars 2 forks source link

length_c/2 #14

Closed UWN closed 1 year ago

UWN commented 1 year ago
?- length_c(L,N), L = N.
   L = N, clpz:(L in 0..sup), unexpected.
?- L=[_|_],length_c(L,N).
   L = [_A], N = 1   % not much of a constraint
;  L = [_A,_B], N = 2
;  L = [_A,_B,_C], N = 3
;  ... .

(It seems you need a more principled approach. You seem to attack too many items at once.)

bakaq commented 1 year ago

You seem to attack too many items at once.

I'm doing whatever is more fun (I just wanted to see if functor_c/3 was possible), and whatever has the greatest impact (length_c/2 has already been useful in one of my programs to not only eliminate var/1 and (->)/2 that where needed to reorder predicates to make it work in many directions, but also increase performance).

I agree that I've been all over the place recently, but it has been a very fun journey.

bakaq commented 1 year ago

Both of those queries now give more sensible answers:

?- length_c(L, N), L = N.
   false.
?- L=[_|_], length_c(L,N).
   L = [_C|_A], constrained:length_c(_A,_B), constrained:list_c(_A), clpz:(_B in 0..sup), clpz:(_B+1#=N), clpz:(N in 1..sup), constrained:integer_c(N).
bakaq commented 1 year ago

I think this can already be closed, right?