Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions calc.cpp

This file was deleted.

5 changes: 0 additions & 5 deletions calc.pl

This file was deleted.

20 changes: 19 additions & 1 deletion pl2cpp.plx
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,26 @@ rewritten in C++. As before, it is compiled by
swipl-ld -o calc -goal true calc.cpp calc.pl
\end{code}

The Prolog file is simple:

\begin{code}
calc(String) :-
term_string(Expr, String),
A is Expr,
writeln(A).
\end{code}

The C part of the application parses the command line options,
initialises the Prolog engine, locates the \verb$calc/1$ predicate and calls
it. The code is in \figref{calccpp}.

\begin{figure}
\begin{code}
#include <string>
#include <SWI-cpp2.h>

int main(int argc, char **argv) {
int
main(int argc, char **argv) {

PlEngine e(argv[0]);

Expand All @@ -265,6 +280,9 @@ int main(int argc, char **argv) {
return PlWrap<int>(q.next_solution()) ? 0 : 1;
}
\end{code}
\caption{C++ source for the calc application}
\label{fig:calccpp}
\end{figure}

\section{Sample code}
\label{sec:cpp2-sample-code}
Expand Down