Prolog- Appending a list of lists -


my database follows format:

aminotodna (amincoacid, [dna sequence]).

here few examples database:

aminotodna(a,[g,c,a]). aminotodna(a,[g,c,c]). aminotodna(a,[g,c,g]). aminotodna(a,[g,c,t]). aminotodna(c,[t,g,c]). aminotodna(c,[t,g,t]). aminotodna(d,[g,a,c]). aminotodna(d,[g,a,t]). aminotodna(e,[g,a,a]). aminotodna(e,[g,a,g]). aminotodna(f,[t,t,c]). aminotodna(f,[t,t,t]). 

some aminoacids have multiple dna sequences. here question, in given list of amino acids example [d,c,e,f], how can append dna sequences , give combinations, have more 1 sequence.

if 2 it, it'd be

listamino(x,y) :-     aminotodna(x,l),     aminotodna(y,m),     append(l,m,z),     print(z). 

hitting ; gives combinations.

i've tired doing list, attempt, , didnt work:

listamino([]). listamino([h|t]) :-     aminotodna(h,l),     aminotodna(t,m),     append(l,m,x),     print(x).  listamino(t). 

when describing lists prolog, consider using dcg notation convenience , clarity. example, using subset of examples, first use dcg rules describe correspondence (note using name makes sense in directions):

amino_dna(a) --> [g,c,a]. amino_dna(a) --> [g,c,c]. amino_dna(c) --> [t,g,c]. amino_dna(c) --> [t,g,t]. 

an again use dcg rules describe concatenation of such lists:

aminos([]) --> []. aminos([a|as]) --> amino_dna(a), aminos(as). 

sample query:

?- phrase(aminos([a,c]), as). = [g, c, a, t, g, c] ; = [g, c, a, t, g, t] ; = [g, c, c, t, g, c] ; etc. 

no append/3, no additional variables, no additional arguments, no nonsense. use !


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 -

css - Can I use the :after pseudo-element on an input field? -