I'm having some strange (or not so strange) problems defining variables in SWI-Prolog. Example:
I'd like to do something like below:
:- initialization(main).
main :-
X = listing(main),
write(X).
but it's simply printing "listing(main)"
I'm having some strange (or not so strange) problems defining variables in SWI-Prolog. Example:
I'd like to do something like below:
:- initialization(main).
main :-
X = listing(main),
write(X).
but it's simply printing "listing(main)"
What you are doing with X = listing(...)
is creating a term, which later you are printing with write.
It seems you want to access the code of main. The thing you are looking for is clause/2
:
clause(:Head, ?Body)
True if Head can be unified with a clause head and Body with the corresponding clause body. Gives alternative clauses on backtracking. For facts, Body is unified with the atom true.
Example:
main :- clause(main, X), write(X).
?- main.
clause(main,_G2381),write(_G2381)
true.
maybe, using another casual predicate instead of main/0...