prolog - How to loop through a list to create a specific other list -


i need define predicate parses given list looks following:

change([10,-,6], list). //send list = [item(num, 10), item(minus, _), item(num, 6)] //returns this. 

i have no idea how check if item in list 'num', or if minus or what...

change([], _). change([h|rest], list) :- "do atom here?" , transform(rest, [item(atom, h) | list] ).  

what might like?

since you're applying transformation on each list' element, change/2 should be

change([], []).  change([h|rest], [q|list]) :- qualify(h,q) change(rest, list]).  

and

qualify(n, item(num, n)) :- number(n), !. qualify(-, item(minus, _)) :- !. qualify(a, item(atom, a)).  % left unspecified, assume else atom... 

the change/2 it's maplist, , written as:

change(i, o) :- maplist(qualify, i, o). 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -