Running Prolog code in the JVM

Last edited: 1 Oct 2019 - What's Changed? - Desktop view - HomePage

This page describes a BSF (Bean Scripting Framework) engine for JLog, a Prolog-in-Java system. JLog is a full-featured Prolog interpreter that can be run as an applet, an application or embedded through an API. You can download the full package, which includes JLog-1.3.6, at It's licensed under the GPL.

BSF enables a Java host program to call scripts or programs written in other languages in a language-neutral way. That means that a BSF-enabled application can a) call scripts and programs written in other languages without knowing in advance in which language they might be (embedding), and b) that any language for which a BSF engine is available can be used to script a BSF-enabled Java application (scripting). Currently, BSF integration is available for JavaScript?, XSLT, Jython, Python, Ruby, ObjectScript?, NetRexx?, TCL, Groovy and now for Prolog. BSF has been released under the Apache License and can be found at It's also included in the download above.

The JLog/BSF integration library (or BSF engine) was developed by myself. JLog was developed by Glendon Holst, and can be found at It's also licensed under the GPL.

Sections in this document:


JLogBSFEngine? defines a number of Prolog predicates that can be used for interactions between both languages.


The following is a list of all examples that come with the distribution, with notes on how to run them and what they demonstrate.

% ant fib -Dn=15
Buildfile: build.xml
% ant script
Buildfile: build.xml
	[echo] prop=42
	[echo] prop2=53
	Sun Jul 31 18:50:36 CEST 2005

<bsf:scriptlet language="prolog">
	f2c(Start, End) :-
		Start =< End,
		bsf_lookup('out', OUT),
		bsf_static('Math', MATH),
		bsf_invoke(_, OUT, 'print', ['<tr><td>']),
		bsf_invoke(_, OUT, 'print', [Start]),
		bsf_invoke(_, OUT, 'print', ['</td><td>']),
		T is (Start-32) * 5/9,
		bsf_invoke(T1, MATH, 'round', [T]),
		bsf_invoke(_, OUT, 'print', [T1]),
		bsf_invoke(_, OUT, 'println', ['</td></tr>']),
		Start1 is Start + 10,
		f2c(Start1, End).
	f2c(30, 100).

  Restrictions and Problems

This section lists some of the restrictions one should be aware of.