News for hackers. Stuff that matters.
Re:Why did Prolog lose steam? (2010) by superdisk on Wednesday April 19, 2023 @03:34PM (#35632344)

  :- use_module(library(clpfd)).

  rle([], []).
  rle([H],[[H, 1]]).
  rle([H | T], [[H, CountPlus1] | More]) :-
      Count #> 0,
      CountPlus1 #= Count+1,
      rle(T, [[H, Count] | More]).
  rle([H | T], [[H, 1], [Element, Count] | More]) :-
      Count #> 0,
      dif(Element, H),
      rle(T, [[Element, Count] | More]).
Even though I'm the one who was making the execution model complaint, this implementation seems to work for me.

  ?- rle([1,1,1,2,3,1,1],X), rle(Y, X).
  X = [[1, 3], [2, 1], [3, 1], [1, 2]],
  Y = [1, 1, 1, 2, 3, 1, 1] ;
  false.
Re:Why did Prolog lose steam? (2010) by ghusbands on Wednesday April 19, 2023 @05:45PM (#35633702)
I was lumping clpfd under metaprogramming, since it acts like an extra runtime or dsl and you can't use the prolog debugger to make sense of it. I'll readily admit that prolog+clpfd is very powerful; any goalpost-moving on my part is unintentional.

I found that using peano numbers got a bit further in plain prolog, but it still eventually infloops in at least one of the directions.

Re:Why did Prolog lose steam? (2010) by falsissime on Thursday April 20, 2023 @12:10PM (#35642219)
There is a minor impurity in this code: `N = 1+1, rle([a,a],[[a,N]]).` succeeds, yet `rle([a,a],[[a,N]]), N = 1+1` fails. Add `:- op(150, fx, #).` and use it like `#CountPlus1 #= #Count+1` etc.