Question: WRITE IN PROLOG, MAKE SURE PASSES ALL TESTS BELOW Define the relation my_assoc that takes an atom A and an association list ALIST and binds
WRITE IN PROLOG, MAKE SURE PASSES ALL TESTS BELOW
Define the relation my_assoc that takes an atom A and an association list ALIST and binds R to the value associated with A in ALIST. If there is no association for A, it fails. Prolog does not have association lists, but we can invent thema little different than they are in Lisp. An association list is a list of key/value pairs where the key [always a symbol] is followed by the value, so the length of an ALIST is always even. An association list is of the form [key_1,value_1,key_2,value_2], key_n,value_n] Examples:
my_assoc(a,[],R). false
my_assoc(a,[a,b,c,e,f,b],R). R=b
my_assoc(c,[a,b,c,e,f,b],R). R=e
my_assoc(f,[a,b,c,e,f,b],R). R=b
my_assoc(b,[a,b,c,e,f,b],R). false
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
