1,626 karma · joined Jun 7, 2018 (8y ago) · 350 submissions
comment 3y ago · link · parent
comment 3y ago · link · parent
comment 3y ago · link · parent
rle2([], []).
rle2([H],[[H, add1(zero)]]).
rle2([H | T], [[H, CountPlus1] | More]) :-
Count = add1(_),
CountPlus1 = add1(Count),
rle2(T, [[H, Count] | More]).
rle2([H | T], [[H, add1(zero)], [Element, Count] | More]) :-
Count = add1(_),
dif(Element, H),
rle2(T, [[Element, Count] | More]).
?- rle2([1,1,1,2,2,3],X), rle2(Y,X).
X = [[1, add1(add1(add1(zero)))], [2, add1(add1(zero))], [3, add1(zero)]],
Y = [1, 1, 1, 2, 2, 3] ;
false.
It even works in the completely general case: ?- rle2(X,Y).
X = Y, Y = [] ;
X = [_A],
Y = [[_A, add1(zero)]] ;
X = [_A, _A],
Y = [[_A, add1(add1(zero))]] .
As I understand it, Prolog itself is CLP(H), that is CLP over the Herbrand terms (that is, atoms and functors and stuff). CLP(FD) just extends the capability with numbers (FD = finite domains). Although I do sort of understand how you'd consider it not "pure" Prolog, I don't see it as that different especially with things like `dif/2` in Prolog which is a constraint just like any other.comment 3y ago · link · parent
I think "pragmatic therefore non-logical" versus "ivory tower therefore useless" is a false dichotomy. In my experience it's nearly impossible to make green cuts, and once you know a few tricks and rules of thumb, you can get pretty far writing logical code.
comment 3y ago · link · parent
It's kind of unfortunate IMO that most oldskool Prolog code out there is peppered with cuts and (->)/2 since it propagates a ton of bad habits.
Regarding the RLE problem, I posted a logical solution without cuts: https://news.ycombinator.com/item?id=35632344
comment 3y ago · link · parent
:- 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.comment 3y ago · link · parent
I still love the language, but I think there's a point where every learner realizes it's not as beautiful and ideal as they once thought.
comment 3y ago · link · parent
I've also been using it while writing Common Lisp, and I'm not sure if it's just because it's a more obscure language, but it commonly produces nonsensical code, recommends functions that don't exist or work differently than it thinks they do, or produces non-idiomatic weird stuff.
It also falls apart when writing z80 assembly, again just generating nonsense. It really is a cool tool though, and I use it to get me steered in the correct direction. I've seen other people mention that it can identify unknown unknowns, and I concur it's an amazing tool for that. We'll see if with more specialized training on programming-related datasets if it can get better, I wouldn't write off the possibility. It won't be stealing your job in its current state, though.
comment 3y ago · link · parent
comment 3y ago · link · parent
comment 3y ago · link · parent
Epic 4k HD photo, high res and epic, cool extra awesome photorealistic 5k or 6k, realistic, in the style of a really good photographer.
Nah I'm just playing, your company looks pretty cool, I just think a dedicated job for coming up with prompts (which is only going to become easier anyway with better ways to control output) is silly.comment 3y ago · link · parent