Let's try some literate programming. From Don Knuth's original idea, thru Norman Ramsey's noweb reformulation, by way of Jonathan Aquino's Python version, which I tweaked to accept Markdown input and added a few new features.
$ ./noweb.py -R 'outer function' lp_hacks.md | python
Hello world
inner function
def _inner(x):
print(x)
That function above will be called by this function below.
outer function
#*inner function*#
def _outer(x):
_inner(x)
_outer("Hello world")
People have put a lot of work into Prolog. There must be something to it. I know Ross King used it in his Robot scientist project. It seems to be an ideal computational environment for exercises in first-order logic.
To exercise some of the stuff below, you can run the "root" chunk below by installing SWI Prolog and then typing
./noweb.py -R root lp_hacks.md | bash
root
./noweb.py -R 'try some prolog' lp_hacks.md > foo.pl
# enumerate solutions non-interactively
swipl -f foo.pl -g "forall((Goal=sibling(X,Y),call(Goal)),(write(Goal),nl))." -t halt.
try some prolog
mother_child(trude, sally).
father_child(tom, sally).
father_child(tom, erica).
father_child(mike, tom).
sibling(X, Y) :- parent_child(Z, X), parent_child(Z, Y).
parent_child(X, Y) :- father_child(X, Y).
parent_child(X, Y) :- mother_child(X, Y).