TransWikia.com

How to insert member list with menu driven prolog program?

Stack Overflow Asked by Fury on November 24, 2020

The Question is-

Write a menu driven PROLOG program to implement various operations on List such as- membership

My ans was –

main :-
    nl,
    writeln(">   Enter a selection followed by a period."), nl,
    writeln(">   1. Run a query"), nl,
    writeln(">   2. Exit"), nl, nl,
    read(Choice),
    run_opt(Choice),main.

run_opt(1) :-
    writeln(">   Enter list"), nl,
    read(L),
    member(X,[L]).


run_opt(2) :- writeln("Goodbye"), nl.

run_opt(_) :- writeln("Invalid option"), nl.

member(X,[X|_]).
member(X,[_|TAIL]):-
  member(X,TAIL).

This above program has problem and i can’t insert member with menu driven insertion, like i do this below without menu driven directly–

member(X,[X|_]).
member(X,[_|TAIL]):-
member(X,TAIL).

and the above program correctly executes when i put–

member(X,[1,2,3]).

and it displays members as-

X = 1
X = 2
X = 3

So, i need to do that thing with menu driven but i cant pass the list member in prolog.
Thanks in advance.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP