Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Styla: a lightweight open source Prolog-in-Scala

52 views
Skip to first unread message

Paul Tarau

unread,
Feb 2, 2012, 12:13:19 PM2/2/12
to
Styla is a fairly complete Prolog interpreter written in Scala,
derived from Kernel Prolog (see Fluents: A Refactoring of Prolog for
Uniform Reflection and Interoperation with External Objects in
CL'2000).

The genuinely open sourced (Apache license) code is hosted at:

http://code.google.com/p/styla/

and it is designed with simplicity and extensibility in mind - hoping
it would be useful to people experimenting with new Prolog extensions
or alternative logic programming languages.

Among the features not found in most Prologs, first class Logic
Engines - and a generic view of everything as Fluents (TermSinks and
TermSources) that abstract away iteration over various data types,
including answers produced by Logic Engines.

Here are some limitations, most things not on this list and expected
from a Prolog system should work.

- toplevel goals that a not conjunctions should be parenthesized
- operators are all fixed and xfx, but they match the default
priorities of
most Prologs' operators - see examples in progs/
- no gui or networking - Scala can do all that better

Take a look at prolog.Main for the start-up sequence - that gives a
glimpse of how to embed it into a Scala or Java program.

To add a new built-ins, just clone the closest match in
prolog.builtins and drop it in the same directory - the runtime system
will instantly recognize it.

Use the script "compile" to recompile the system with scalac "run" to
run it with scala and jrun to run it with java (possibly edit for path
info in this case).

The file prolog/fluents/Lib.scala embeds Prolog code that is present
at start-up. New Prolog code that you want part of the default
libraries can be added there.

Enjoy,

Paul Tarau

Jan Burse

unread,
Feb 2, 2012, 3:11:27 PM2/2/12
to
Paul Tarau schrieb:
> Styla is a fairly complete Prolog interpreter written in Scala,
> derived from Kernel Prolog (see Fluents: A Refactoring of Prolog for
> Uniform Reflection and Interoperation with External Objects in
> CL'2000).
>
> The genuinely open sourced (Apache license) code is hosted at:
>
> http://code.google.com/p/styla/
>
> and it is designed with simplicity and extensibility in mind - hoping
> it would be useful to people experimenting with new Prolog extensions
> or alternative logic programming languages.

Does the implementation make heavy use of some language
features from Scala which are for example not already
present in Java? I saw some pattern matching. What else?

Bye

Paul Tarau

unread,
Feb 3, 2012, 11:01:44 AM2/3/12
to
It uses a few functional programming goodies - maps, folds etc. as
well as implicit type conversions between thing like array and lists,
arbitrary length integers and decimals - handled much more elegantly
in Scala than in Java.

Also, Scala has a few nice IO abstractions that merge file operations
and iterators - some of the goals of the original Kernel Prolog
(written in Java) from which Styla has been derived.

And not to forget "poor man's DCGs" - Styla uses Scala's combinator
parsers
for syntax.

Paul

P.S. By the way, Kernel Prolog has been repackaged as an open source
Google code project at: http://code.google.com/p/kernel-prolog/
just in case someone is interested to play with it.

Paul Tarau

unread,
Feb 3, 2012, 11:40:27 AM2/3/12
to
On Feb 2, 2:11 pm, Jan Burse <janbu...@fastmail.fm> wrote:
Styla uses indeed a few Scala goodies not available in Java:

- higher order functions, maps, folds, case classes etc.
- combinator parsers - "poor man's DCGs" :-)
- Scala's elegant implicit conversions between
lists, arrays, sequences etc.
- Scala's arbitrary length integers and decimals (with
a natural syntax, in contrast to Java)
- Scala's """...""" strings - for regexps and to embed
Prolog code directly in Scala classes
- a few IO abstractions available in Scala that
view things like file operations as iterators -
a natural match for the original Fluents of the
Java-based Kernel Prolog from which Styla was derived

Paul

P.S. the latest version of Kernel Prolog is now an
open source Google project at:

http://code.google.com/p/kernel-prolog/

0 new messages