ICLP12-SWI25 - SWI

advertisement
Jan Wielemaker
VU University
Amsterdam
2012-09-05
ICLP-2012
1
Contents

Viewpoint

A brief history of SWI-Prolog

The Prolog landscape

The place of Prolog in IT infrastructure

The Prolog software community
2012-09-05
ICLP-2012
2
Viewpoint

Logic programming

Programming languages

Prolog

2012-09-05

Prolog implementations

Prolog usage

Prolog community (user and developers)
Used TPLP special issue on Prolog
implementations
ICLP-2012
3
A brief history of SWI-Prolog



2012-09-05
1983 D. L. Bowen, L. M. Byrd, and WF.
Clocksin. “A portable Prolog compiler”
1986 I wrote a virtual machine based on
this paper
1987 Use in European KADS project,
replacing Quintus. Distributed using FTP
ICLP-2012
4
Success in KADS





2012-09-05
Bi-directional Prolog ↔ C interface allowed
for better integration to PCE (graphics)
Quintus compatibility on `as needed' basis
to support the project
Fast compiler, lazy loading (autoload)
Fast saved-state (based on `undump') and
reload of modified code using ?- make.
Command-line editing and completion
ICLP-2012
5
Yet another Prolog
(not to br confused YAP)

Satisfied our needs

We had full control

… but, nothing unique that was not added
to commercial systems within weeks
→ Released



2012-09-05
FTP
Academic `non-commercial use'
No need to fill out forms
ICLP-2012
6
Educational

Free of hassle (download, compile, use)

Supports popular academic Unix machines

Resource friendly

Compliant with primitives in textbooks
2012-09-05
ICLP-2012
7
The Carrot: quick release model


2012-09-05
Input

Contributions (mostly portability)

Bug reports

Functionality requests
Output

Fast response

Updated source on FTP, ranging from
hours to a week
ICLP-2012
8
The middle ages (1988-2001)

New libraries, bugfixes, etc.

ISO part-I

Port to Windows 95/NT3.5

Quality (CVS, test suite)

2012-09-05
But … we missed lots of Prolog research
(parallel, CLP, ...)
ICLP-2012
9
2001: License

GNU libreadline conflicts with noncommercial-use license

FSF: remove libreadline or change SWIProlog license
→ SWI-Prolog moved to LGPL

2012-09-05
Started http://www.swi-prolog.org
ICLP-2012
10
2003: CLP


After Mumbai ICLP, together with Tom
Schrijvers and Bart Demoen
Copy of `dynamic attributed variables' as
proposed by Demoen and implemented for
hProlog

Leuven CHR, coroutining

Markus Triska started pure Prolog clp(fd)
2012-09-05
ICLP-2012
11
2003.. Web support

Multi-threading

Unicode

Atom garbage collection

SGML/XML

HTTP Server and client libraries

RDF libraries and store
2012-09-05
ICLP-2012
12
Commercial involvement


2012-09-05
Contributions

JPL, the Java interface

Quality checks and bug fixes
Sponsored development

Unbounded integers and rationals (GMP)

SSL interface

Memory management

PlDoc, PlUnit

IF/Prolog portability layer
ICLP-2012
13
Success


Right time

Early hassle-free Prolog for education

Early port to Windows (students)
Model


Technical

2012-09-05
Quick release cycle: 2 weeks for
development, 6 months for stable version
Interface, do-what-I-mean, robustness,
interfaces
ICLP-2012
14
Failure



2012-09-05
Trying to do `everything'
Packages often rely on undocumented
SWI-specific extensions, making it hard to
reuse them
Improving

Development APIs (share with PDT)

Modularized I/O and OS interface (YAP)

Modularize (GIT) repository
ICLP-2012
15
Part-II
The Prolog landscape
2012-09-05
ICLP-2012
16
Is Prolog in BAD shape?

Ohloh (http://www.ohloh.net/)
Language
Lines of code in projects
Prolog
652,576
Erlang
20,217,024
Haskell
6,636,372
Lisp
2012-09-05
19,657,199
ICLP-2012
17
Is Prolog in BAD shape?


2012-09-05
Discontinued in many Dutch universities or
moved to a `language overview course'
Hard to convince our (PhD) students to use
it, even for RDF because

Perceived as `hard to learn'

No modern (IDE) tools

No library for X, Y and Z (you name it)

``An irrelevant language from the past''

``I always programmed in (often) Java''
ICLP-2012
18
Some often heard reasons

(Early) fragmentation of the language

No programmers/No jobs


2012-09-05
Logic programming/Prolog is unsuitable as
a general purpose language
Failed standardization
ICLP-2012
19
Fragmentation?
#Implementations (source: OpenDirectory)
70
60
50
40
30
20
10
0
Prolog
2012-09-05
Lisp
Scheme
ICLP-2012
Haskell
C
20
No programmers?
Language
vWorks expertise
Java
StackOverflow questions
18,700
286.290
Prolog
453
1845
Lisp
545
2068
Erlang
46
2587
Haskell
115
7854
2012-09-05
ICLP-2012
21
Books
Source: Amazon (UK)
6
5
4
3
2
1
0
1986
1988
1990
1992
1994
1996
1998
2000
2002
2004
2006
2008
2010
2012
1985
1987
1989
1991
1993
1995
1997
1999
2001
2003
2005
2007
2009
2011
2012-09-05
ICLP-2012
22
The Gartner Hype Cycle
Explained
2012-09-05
ICLP-2012
23
Part III
The place of Prolog in IT infrastructure
2012-09-05
ICLP-2012
24
General Purpose
vs Logic server


`General purpose'

Missing language features (e.g.,
destructive assignment)

Needs graphics, Web, DB, etc.,
interfaces
`Logic server'

Needs language interfaces

Suffers from object/relational impedance
mismatchhttp://en.wikipedia.org/wiki/Objectrelational_impedance_mismatch
2012-09-05
ICLP-2012
25
Logic server

Native (Amzi!)

JVM based (Jinni, Minerva, Jekejeke, …)

Successor


2012-09-05
BinProlog → Jinni
IF/Prolog → Minerva
ICLP-2012
26
Embedding is popular


2012-09-05
SWI-Prolog has interfaces for C (native),
C++ (native and contributed), Java, C#,
Python, Perl (contributed)
113 projects on GitHUB combine Prolog
with:
ICLP-2012
27
SWI-Prolog: `glue'

2012-09-05
Prolog is good at `glue' due to

Dynamic nature (incl. typing)

Flexible dynamically typed data
representation makes it simple to
represent data from external systems

Natural mapping of tabular data

Interactive development environment

Rules, DSLs, ...
ICLP-2012
28
Some realized `glue' (for SWI)

Databases (ODBC)

RDF

XML/SGML/HTML

R (statistical computing)

HTTP Server library

Spatial reasoning (geos library)

OpenGL, OSC, MIDI, Gtk, Matlab, ...
2012-09-05
ICLP-2012
29
Prolog as primary language
(SecuritEase)
2012-09-05
ICLP-2012
30
Conclusion


2012-09-05
`Logic server' seems a more natural and
easier to sell first option
Provided with well designed `glue', Prolog
is also attractive as primary application
language, including scripting
ICLP-2012
31
Part IV
The Prolog software community
2012-09-05
ICLP-2012
32
Comparing models
Implementation
Maintenance
Progress Shared
API
Stable
API
Independent
development
duplicate
duplicate
++
--
-
Shared
design
duplicate
duplicate
+++
na.
na.
Shared
specification
duplicate
duplicate*
--
+++
+++
Forked
specification
duplicate
duplicate
+++
++
+
Forked code
single
duplicate
++++
++
+
Shared code
single
shared
++
++++
++
* Stability of specification makes duplicates easier to handle
2012-09-05
ICLP-2012
33
Forking (Unix wars)
Source: Wikipedia
2012-09-05
ICLP-2012
34
Distributions (Linux)
2012-09-05
ICLP-2012
35
Summary



Shared standards are good but slow. Fits
poorly in a culture of innovation.
Shared code leads to

Reuse (stand on the shoulders of giants)

Fast innovation
Sharing needs a common ground
And, where do we stand?
2012-09-05
ICLP-2012
36
Independent Development

Various module systems


Operating system access


File system, networking
Interfaces

2012-09-05
Predicate based ↔ name based
DB, Graphics, C, Java, C#, ...
ICLP-2012
37
Shared design

WAM

Garbage collectors

Tabled evaluation

Attributed variables
2012-09-05
ICLP-2012
38
Shared specification

2012-09-05
ISO standard
ICLP-2012
39
Forked specification



2012-09-05
Quintus module system (SICStus, Ciao,
YAP, SWI)
hProlog Dynamic attributed vars (SWI,
YAP, XSB)
SWI Thread API (YAP, XSB)
ICLP-2012
40
Forked code

DEC10 library (forked many times)

clp(q,r)

Draxler's Prolog → SQL compiler

SWI I/O and OS access (YAP, close to shared)

SWI XML/SGML (XSB)

SWI PlUnit (SICStus)

Parts of XSB tabling (YAP)?
2012-09-05
ICLP-2012
41
Shared Prolog components

Logtalk (many)

CHR (hProlog, SWI, XSB, YAP, B-Prolog, SICStus, Ciao)
2012-09-05
ICLP-2012
42
Requirements for sharing

Common ground for

Core Prolog
(++)

Prolog extensions (attvar,tabling) (+)

Structuring (modules, objects)

Interface to non-Prolog resources (–)
(+/-)
http://www.cs.unipr.it/~bagnara/Papers/Prolog-FLI-survey

2012-09-05
Always remaining issues → need work-around

Conditional compilation
(++)

ICLP-2012
Macro expansion
43
Comparision of FLI
Syst./Charac.
B-Prolog
Bin
Ciao
Eclipse
GNU
SICStus
SWI
XSB
YAP
Glue code
m
m
b
m
b
b
m(b)
b
m
Int. style
f
l
f
f
f
p
p
p
f
Term constr.
t
b
b
b
b
b
b/t
t
b
Non-det.
n
n
s
n
y
n
y
n
y
Exceptions
n
n
y
n
y
y
y
n
n
C to Prolog
r
r
r
y
r
r
r
y
r
(De)Init
n
n
i
n
n
b
b
n
n
Compilation
m
m
a
m
m
e
m
a
m
Linking
s
s
d
b
s
b
b
s
d
m: manual, f: functional, p: procedural, l: low level, s: static, d: dynamic, b: both
http://www.cs.unipr.it/~bagnara/Papers/Prolog-FLI-survey
2012-09-05
ICLP-2012
44
Progress (Foreign)


2012-09-05
FLI emulations

SICStus ↔ SWI (Alpino, XPCE)

YAP ← SWI (SWI packages)

YAP ← Bprolog (PRISM)
Reuse SWI I/O and OS builtins in YAP

In part based on FLI emulation

Also emulated low-level SWI FLI
ICLP-2012
45
Prolog Commons

Goal: arrive at a shared Prolog library

Minimal shared module support

Shared document and annotation model


2012-09-05
Ciao effort
Website, GIT repo
ICLP-2012
46
YAP/SWI
`dialect' framework
:- expects_dialect(X) says

Text is written for X

Loads dialect(X) (= library(dialect/X))

Defines built-ins of X not in target

Rewrites conflicting built-ins using macros

Rewrites module API using macros

Pushes X-compatible library
2012-09-05
ICLP-2012
47
Dialects implemented

YAP


BProlog, Commons, hProlog, SWI-Prolog
SWI

YAP, BIM, hProlog, Commons, Ciao,
IF/Prolog
`As-needed' basis
2012-09-05
ICLP-2012
48
Dialect applied (SWI)


2012-09-05
Alpino (now maintained as portable code)

500Klines, C,C++,Tcl/Tk

SICStus → SWI
Prosyn (ported)

1Mlines, C,C++ (Windows MFC)

IF/Prolog → SWI

Replaced MFC with web-GUI, other C
with pure Prolog code
ICLP-2012
49
Dialect Applied (YAP)

Many of SWI's extension packages

PRISM
2012-09-05
ICLP-2012
50
Commons ↔ Dialect

Shared spec/code

Slow to start

Must be useable

Use each others
code

Immediate result

`As needed'
I. Use commons as a `dialect'
II. Slowly, a comprehensive commons can
act as shared library for many projects
2012-09-05
ICLP-2012
51
Distribution: Pack


2012-09-05
Simple directory with

File pack.pl containing meta-data

Sub-dir prolog that is added to the library

Optional configure[.in], makefile[.in] for
foreign parts
http://www.swi-prolog.org/pack/list
ICLP-2012
52
Conclusions


2012-09-05
Prolog was hyped and its community was
fragmented. There are signs indicating
Prolog reached the enlightenment phase:

New books get published again

Compatibility and portable applications
are becoming more common

Stability and compiling improved much
(Paulo Moura, CICLOPS)
Sharing resources (libraries, applications,
tutorials, books, …) is important
ICLP-2012
53
Next steps (also open.pl)

Organize new `commons' meetings to

Bootstrap the common library/dialect

Establish a common Prolog ↔ C binding

Establish macro expansion

A package distribution format

Implement the dialect emulation

Share!
2012-09-05
ICLP-2012
54
Download