ICLP12-SWI25 - SWI-Prolog

cavalcadejewelSoftware and s/w Development

Nov 18, 2013 (3 years and 8 months ago)

152 views

2012
-
09
-
05

ICLP
-
2012

1

Jan Wielemaker

VU University

Amsterdam

2012
-
09
-
05

ICLP
-
2012

2

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

3

Viewpoint


Logic programming


Programming languages


Prolog


Prolog implementations


Prolog usage


Prolog community (user and developers)


Used TPLP special issue on Prolog
implementations

2012
-
09
-
05

ICLP
-
2012

4

A brief history of SWI
-
Prolog


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

2012
-
09
-
05

ICLP
-
2012

5

Success in KADS


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

2012
-
09
-
05

ICLP
-
2012

6

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


FTP


Academic `non
-
commercial use'


No need to fill out forms

2012
-
09
-
05

ICLP
-
2012

7

Educational


Free of hassle (download, compile, use)


Supports popular academic Unix machines


Resource friendly


Compliant with primitives in textbooks

2012
-
09
-
05

ICLP
-
2012

8

The Carrot: quick release model


Input


Contributions (mostly portability)


Bug reports


Functionality requests


Output


Fast response


Updated source on FTP, ranging from
hours to a week

2012
-
09
-
05

ICLP
-
2012

9

The middle ages (1988
-
2001)


New libraries, bugfixes, etc.


ISO part
-
I


Port to Windows 95/NT3.5


Quality (CVS, test suite)


But … we missed lots of Prolog research
(parallel, CLP, ...)

2012
-
09
-
05

ICLP
-
2012

10

2001: License


GNU libreadline conflicts with non
-
commercial
-
use license


FSF: remove libreadline or change SWI
-
Prolog license

→ SWI
-
Prolog moved to LGPL


Started
http://www.swi
-
prolog.org

2012
-
09
-
05

ICLP
-
2012

11

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

12

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

13

Commercial involvement


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

2012
-
09
-
05

ICLP
-
2012

14

Success


Right time


Early hassle
-
free Prolog for education


Early port to Windows (students)


Model


Quick release cycle: 2 weeks for
development, 6 months for stable version


Technical


Interface, do
-
what
-
I
-
mean, robustness,
interfaces

2012
-
09
-
05

ICLP
-
2012

15

Failure


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

2012
-
09
-
05

ICLP
-
2012

16

Part
-
II



The Prolog landscape

2012
-
09
-
05

ICLP
-
2012

17

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

19,657,199

2012
-
09
-
05

ICLP
-
2012

18

Is Prolog in BAD shape?


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''

2012
-
09
-
05

ICLP
-
2012

19

Some often heard reasons


(Early) fragmentation of the language


No programmers/No jobs


Logic programming/Prolog is unsuitable as
a general purpose language


Failed standardization

2012
-
09
-
05

ICLP
-
2012

20

Fragmentation?

Prolog
Lisp
Scheme
Haskell
C
0
10
20
30
40
50
60
70
#Implementations (source: OpenDirectory)

2012
-
09
-
05

ICLP
-
2012

21

No programmers?

Language

vWorks expertise

StackOverflow questions

Java

18,700

286.290

Prolog

453

1845

Lisp

545

2068

Erlang

46

2587

Haskell

115

7854

2012
-
09
-
05

ICLP
-
2012

22

Books

1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
0
1
2
3
4
5
6
Source: Amazon (UK)

2012
-
09
-
05

ICLP
-
2012

23

The Gartner Hype Cycle
Explained

2012
-
09
-
05

ICLP
-
2012

24

Part III



The place of Prolog in IT infrastructure

2012
-
09
-
05

ICLP
-
2012

25

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
mismatch
http://en.wikipedia.org/wiki/Object
-
relational_impedance_mismatch

2012
-
09
-
05

ICLP
-
2012

26

Logic server


Native (Amzi!)


JVM based (Jinni, Minerva, Jekejeke, …)


Successor


BinProlog → Jinni


IF/Prolog → Minerva

2012
-
09
-
05

ICLP
-
2012

27

Embedding is popular


SWI
-
Prolog has interfaces for C (native),
C++ (native and contributed), Java, C#,
Python, Perl (contributed)


113 projects on GitHUB combine Prolog
with:

2012
-
09
-
05

ICLP
-
2012

28

SWI
-
Prolog: `glue'


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, ...

2012
-
09
-
05

ICLP
-
2012

29

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

30

Prolog as primary language

(SecuritEase)

2012
-
09
-
05

ICLP
-
2012

31

Conclusion


`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

2012
-
09
-
05

ICLP
-
2012

32

Part IV



The Prolog software community

2012
-
09
-
05

ICLP
-
2012

33

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

34

Forking (Unix wars)

Source: Wikipedia

2012
-
09
-
05

ICLP
-
2012

35

Distributions (Linux)

2012
-
09
-
05

ICLP
-
2012

36

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

37

Independent Development


Various module systems


Predicate based ↔ name based


Operating system access


File system, networking


Interfaces


DB, Graphics, C, Java, C#, ...

2012
-
09
-
05

ICLP
-
2012

38

Shared design


WAM


Garbage collectors


Tabled evaluation


Attributed variables

2012
-
09
-
05

ICLP
-
2012

39

Shared specification


ISO standard

2012
-
09
-
05

ICLP
-
2012

40

Forked specification


Quintus module system (SICStus, Ciao,
YAP, SWI)


hProlog Dynamic attributed vars (SWI,
YAP, XSB)


SWI Thread API (YAP, XSB)

2012
-
09
-
05

ICLP
-
2012

41

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

42

Shared

Prolog components


Logtalk (many)


CHR (
hProlog, SWI, XSB, YAP, B
-
Prolog, SICStus, Ciao
)

2012
-
09
-
05

ICLP
-
2012

43

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


Always remaining issues → need work
-
around


Conditional compilation





(++)


Macro expansion







(+)

2012
-
09
-
05

ICLP
-
2012

44

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

Comparision of FLI

http://www.cs.unipr.it/~bagnara/Papers/Prolog
-
FLI
-
survey

m
: manual,
f
: functional,
p
: procedural,
l
: low level,
s
: static,
d
: dynamic,
b
: both

2012
-
09
-
05

ICLP
-
2012

45

Progress (Foreign)


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

2012
-
09
-
05

ICLP
-
2012

46

Prolog Commons


Goal: arrive at a shared Prolog library


Minimal shared module support


Shared document and annotation model


Ciao effort


Website, GIT repo

2012
-
09
-
05

ICLP
-
2012

47

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

48

Dialects implemented


YAP


BProlog, Commons, hProlog, SWI
-
Prolog


SWI


YAP, BIM, hProlog, Commons, Ciao,
IF/Prolog

`As
-
needed' basis

2012
-
09
-
05

ICLP
-
2012

49

Dialect applied (SWI)


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

2012
-
09
-
05

ICLP
-
2012

50

Dialect Applied (YAP)


Many of SWI's extension packages


PRISM

2012
-
09
-
05

ICLP
-
2012

51

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

52

Distribution: Pack


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

2012
-
09
-
05

ICLP
-
2012

53

Conclusions


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

2012
-
09
-
05

ICLP
-
2012

54

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!