54
2012-09-05 ICLP-2012 1 Jan Wielemaker VU University Amsterdam

2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

Embed Size (px)

Citation preview

Page 1: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

2012-09-05 ICLP-2012 1

Jan WielemakerVU UniversityAmsterdam

Page 2: 2012-09-05 ICLP-20121 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

Page 3: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 4: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 5: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 6: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 7: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 8: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 9: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 10: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 11: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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)

Page 12: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 13: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 14: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 15: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 16: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

2012-09-05 ICLP-2012 16

Part-II

The Prolog landscape

Page 17: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Compilers

Puzzles

Applications

Reasoning

Extensions

Page 18: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 19: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 20: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

2012-09-05 ICLP-2012 20

Fragmentation?

Prolog Lisp Scheme Haskell C0

10

20

30

40

50

60

70

#Implementations (source: OpenDirectory)

Page 21: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 22: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

2012-09-05 ICLP-2012 22

Books

19851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120120

1

2

3

4

5

6Source: Amazon (UK)

Page 23: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

2012-09-05 ICLP-2012 23

The Gartner Hype Cycle Explained

Page 24: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

2012-09-05 ICLP-2012 24

Part III

The place of Prolog in IT infrastructure

Page 25: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

mismatchhttp://en.wikipedia.org/wiki/Object-relational_impedance_mismatch

Page 26: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

2012-09-05 ICLP-2012 26

Logic server

Native (Amzi!) JVM based (Jinni, Minerva, Jekejeke, …)

Successor BinProlog → Jinni IF/Prolog → Minerva

Page 27: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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:

Perl Java

Ruby C

Haskell Scala

Erlang Python

C# Common Lisp

Clojure VimL

PHP C++

JavaScript Objective-C

OCaml F#

Emacs Lisp Shell

Scheme Racket

Lua Groovy

Page 28: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 29: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 30: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

2012-09-05 ICLP-2012 30

Prolog as primary language(SecuritEase)

Page 31: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 32: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

2012-09-05 ICLP-2012 32

Part IV

The Prolog software community

Page 33: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

2012-09-05 ICLP-2012 33

Comparing modelsImplementation Maintenance Progress Shared

APIStable

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

Page 34: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

2012-09-05 ICLP-2012 34

Forking (Unix wars)

Source: Wikipedia

Page 35: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

2012-09-05 ICLP-2012 35

Distributions (Linux)

Page 36: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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?

Page 37: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 38: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

2012-09-05 ICLP-2012 38

Shared design

WAM Garbage collectors Tabled evaluation Attributed variables

Page 39: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

2012-09-05 ICLP-2012 39

Shared specification

ISO standard

Page 40: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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)

Page 41: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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)?

Page 42: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

2012-09-05 ICLP-2012 42

Shared Prolog components

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

Page 43: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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 (+)

Page 44: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 45: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 46: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 47: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 48: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 49: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 50: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

2012-09-05 ICLP-2012 50

Dialect Applied (YAP)

Many of SWI's extension packages PRISM

Page 51: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 52: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 53: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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

Page 54: 2012-09-05 ICLP-20121 Jan Wielemaker VU University Amsterdam

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!