Splitting list based on conditional atoms in prolog -


i have list

x = [-n,-b,-s,hello,world] 

the output require

z1 = [-n,-b,-s] z2 = [hello,world] 

if string begins - should part of z1 list, else part of z2 list.

could provide me basic intuition implement this?.

with library(apply) , library(yall) it's immediate:

 ?- partition([e]>>(e = - _), [-n,-b,-s,hello,world], n, p). n = [-n, -b, -s], p = [hello, world]. 

to implement in old,plain prolog, visit list , 'cons' element in desired list:

divide_dashed([], [], []). divide_dashed([-e|r], [-e|ds], ps) :- !, divide_dashed(r, ds, ps). divide_dashed([e|r], ds, [e|ps]) :- divide_dashed(r, ds, ps). 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -