Prolog: using the sort/2 predicate

Posted by Øyvind Hauge on Stack Overflow See other posts from Stack Overflow or by Øyvind Hauge
Published on 2012-11-15T16:52:58Z Indexed on 2012/11/15 17:00 UTC
Read the original article Hit count: 221

So I'm trying to get rid of the wrapper clause by using the sort library predicate directly inside split. What split does is just generating a list of numbers from a list that looks like this: [1:2,3:2,4:6] ---split--> [1,2,3,2,4,6]. But the generated list contains duplicates, and I don't want that, so I'm using the wrapper to combine split and sort, which then generates the desired result: [1,2,3,4,6].

I'd really like to get rid of the wrapper and just use sort within split, however I keep getting "ERROR: sort/2: Arguments are not sufficiently instantiated." Any ideas? Thanks :)

split([],[]).
split([H1:H2|T],[H1,H2|NT]) :-
    split(T,NT).

wrapper(L,Processed) :- 
    split(L,L2),
    sort(L2,Processed).

© Stack Overflow or respective owner

Related posts about prolog

Related posts about predicate