Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to run the procedure given by the user?

Status
Not open for further replies.

kamileo

Programmer
Jul 15, 2010
6
PL
I would like to do the program in Prolog that allows its user to execute any procedure he wants to in that way:
1. The program reads from the keyboard the procedure that the user wants to execute (it's simple).
2. After that the Prolog sholud run that procedure. For example: user writes "some(thing)" and presses Enter. Now my program should execute in Prolog procedure some(thing). The problem is that I have no idea how to do it...

Regards,
Kamil

 
You should go to the help page for the 'call' predicate.

Type help(call). at the Prolog prompt.

Or type help. and go to:

Built-in predicates
|
|
Meta-call predicates

... and perhaps you will find there more useful stuff ... but I think 'call' will do the job for you
 
Something like that :
?- read(A), term_to_atom(A, At), sub_atom(At, 0, 4, X, Y), term_to_atom(Y, At1), call(At1).
|: (func :- X is 6 + 4, write(X), nl).
10
A = (func:-_G1024 is 6+4,write(_G1024),nl),
At = 'func:-_G1024 is 6+4,write(_G1024),nl',
X = 32,
Y = func,
At1 = func.
You have to write the code that gives you the len of the head of the clause !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top