├── cclab ├── VERSION ├── prolog │ ├── cclazy │ │ ├── COPYING │ │ ├── treeutils.pl │ │ ├── ccvmemo.pl │ │ ├── test_vmemo.pl │ │ ├── ccmemo.pl │ │ ├── test_memo.pl │ │ └── ccprob.pl │ ├── cctab │ │ ├── COPYING │ │ ├── junk.pl │ │ ├── cctab3.pl │ │ ├── cctab2.pl │ │ ├── cctab4.pl │ │ ├── cctab.pl │ │ ├── lazymath.pl │ │ ├── tabled.pl │ │ ├── cctab6.pl │ │ ├── cctab8.pl │ │ ├── machines.pl │ │ ├── cctab9.pl │ │ └── cctab5.pl │ ├── ccbeam │ │ ├── README.md │ │ ├── ccbeam1.pl │ │ ├── test_beam_nd.pl │ │ ├── ccbeam3.pl │ │ ├── test_vbeam.pl │ │ ├── ccbeam4.pl │ │ ├── test_beam.pl │ │ └── ccbeam2.pl │ ├── ccdetmem.pl │ ├── cclistm.pl │ ├── ccdcg.pl │ ├── ccmacros.pl │ ├── ccmacros2.pl │ ├── lambda2.pl │ └── lambda1.pl ├── Makefile ├── release │ ├── cclab-0.0.1.tgz │ ├── cclab-0.0.2.tgz │ ├── cclab-0.0.3.tgz │ ├── cclab-0.0.4.tgz │ ├── cclab-0.0.5.tgz │ ├── cclab-0.0.6.tgz │ ├── cclab-0.0.7.tgz │ ├── cclab-0.0.8.tgz │ ├── cclab-0.0.9.tgz │ ├── cclab-0.1.0.tgz │ ├── cclab-0.1.1.tgz │ ├── cclab-0.1.2.tgz │ ├── cclab-0.1.3.tgz │ ├── cclab-0.1.4.tgz │ └── cclab-0.1.5.tgz ├── pack.pl └── README ├── memo ├── VERSION ├── release │ ├── memo-0.3.0.tgz │ ├── memo-0.3.1.tgz │ ├── memo-0.3.2.tgz │ ├── memo-0.3.3.tgz │ ├── memo-0.3.4.tgz │ ├── memo-0.3.5.tgz │ ├── memo-0.3.6.tgz │ ├── memo-0.3.7.tgz │ ├── memo-0.4.0.tgz │ ├── memo-0.4.1.tgz │ ├── memo-0.4.2.tgz │ ├── memo-0.4.3.tgz │ ├── memo-0.5.0.tgz │ ├── memo-0.5.1.tgz │ ├── memo-0.5.2.tgz │ ├── memo-0.5.3.tgz │ ├── memo-0.6.0.tgz │ └── memo-0.6.1.tgz ├── pack.pl ├── Makefile └── examples │ └── test_memo.pl ├── pldb ├── VERSION ├── Makefile ├── release │ └── pldb-0.0.1.tgz ├── pack.pl ├── prolog │ ├── pldb_mysql.pl │ ├── pldb_sqlite.pl │ ├── pldb_postgres.pl │ ├── pldb_odbc.pl │ ├── db_aggregate.pl │ └── pldb_terms.pl └── README ├── plsc ├── VERSION ├── Makefile ├── release │ └── plsc-0.1.0.tgz ├── pack.pl └── README ├── swipe ├── VERSION ├── release │ ├── swipe-0.1.0.tgz │ ├── swipe-0.1.1.tgz │ ├── swipe-0.1.2.tgz │ ├── swipe-0.2.0.tgz │ ├── swipe-0.2.1.tgz │ ├── swipe-0.2.2.tgz │ ├── swipe-0.2.3.tgz │ ├── swipe-0.2.4.tgz │ ├── swipe-0.2.5.tgz │ └── swipe-0.2.6.tgz ├── pack.pl ├── Makefile └── README ├── callgraph ├── VERSION ├── examples │ ├── callgraph.pdf │ ├── callgraph_dot.pdf │ ├── test2.pl │ ├── testmod2.pl │ ├── testmod1.pl │ └── test.pl ├── release │ ├── callgraph-0.3.0.tgz │ ├── callgraph-0.3.1.tgz │ ├── callgraph-0.3.2.tgz │ ├── callgraph-0.3.3.tgz │ ├── callgraph-0.3.4.tgz │ ├── callgraph-0.3.5.tgz │ ├── callgraph-0.4.0.tgz │ └── callgraph-0.4.1.tgz ├── pack.pl ├── Makefile └── README ├── dcgutils ├── VERSION ├── release │ ├── dcgutils-0.0.1.tgz │ ├── dcgutils-0.0.2.tgz │ ├── dcgutils-0.0.3.tgz │ ├── dcgutils-0.0.4.tgz │ ├── dcgutils-0.0.5.tgz │ ├── dcgutils-0.0.6.tgz │ ├── dcgutils-0.0.7.tgz │ ├── dcgutils-0.0.8.tgz │ ├── dcgutils-0.0.9.tgz │ ├── dcgutils-1.0.0.tgz │ ├── dcgutils-1.0.1.tgz │ ├── dcgutils-1.0.2.tgz │ ├── dcgutils-1.0.3.tgz │ ├── dcgutils-1.0.4.tgz │ ├── dcgutils-1.0.5.tgz │ ├── dcgutils-1.0.6.tgz │ ├── dcgutils-1.0.7.tgz │ ├── dcgutils-1.0.8.tgz │ ├── dcgutils-1.1.0.tgz │ ├── dcgutils-1.1.1.tgz │ ├── dcgutils-1.1.2.tgz │ └── dcgutils-1.1.3.tgz ├── pack.pl ├── Makefile ├── README └── prolog │ └── dcg_progress.pl ├── fileutils ├── VERSION ├── release │ ├── fileutils-0.1.1.tgz │ ├── fileutils-0.1.2.tgz │ ├── fileutils-0.1.3.tgz │ ├── fileutils-0.1.4.tgz │ ├── fileutils-0.1.5.tgz │ ├── fileutils-0.2.0.tgz │ ├── fileutils-0.2.1.tgz │ ├── fileutils-0.2.2.tgz │ ├── fileutils-0.2.3.tgz │ ├── fileutils-0.2.4.tgz │ ├── fileutils-0.3.0.tgz │ ├── fileutils-0.3.1.tgz │ ├── fileutils-0.3.2.tgz │ ├── fileutils-0.3.3.tgz │ ├── fileutils-0.3.4.tgz │ └── fileutils-0.3.5.tgz ├── Makefile ├── pack.pl └── README ├── genutils ├── VERSION ├── Makefile ├── release │ ├── genutils-0.0.1.tgz │ ├── genutils-0.0.2.tgz │ ├── genutils-0.0.3.tgz │ ├── genutils-0.0.4.tgz │ ├── genutils-0.0.5.tgz │ ├── genutils-0.0.6.tgz │ ├── genutils-0.0.7.tgz │ ├── genutils-0.0.9.tgz │ ├── genutils-0.2.00.tgz │ ├── genutils-0.3.0.tgz │ ├── genutils-0.3.1.tgz │ ├── genutils-0.3.2.tgz │ ├── genutils-0.3.3.tgz │ ├── genutils-0.3.4.tgz │ ├── genutils-0.3.5.tgz │ ├── genutils-0.3.6.tgz │ ├── genutils-0.3.7.tgz │ ├── genutils-0.3.8.tgz │ └── genutils-0.3.9.tgz ├── pack.pl ├── prolog │ ├── lambdaki.pl │ ├── ccreader.pl │ ├── hostname.pl │ ├── ccenv.pl │ ├── insist.pl │ ├── clambda.pl │ ├── rbutils.pl │ ├── argutils.pl │ ├── ccref.pl │ ├── math.pl │ ├── data │ │ ├── store.pl │ │ └── pair.pl │ ├── ccnbref.pl │ └── lazy.pl └── README ├── midiutils ├── VERSION ├── Makefile ├── release │ ├── midiutils-0.0.1.tgz │ ├── midiutils-0.0.2.tgz │ └── midiutils-0.0.3.tgz ├── README ├── pack.pl └── prolog │ └── mididcg.pl ├── musicxml ├── VERSION ├── Makefile ├── release │ ├── musicxml-0.0.1.tgz │ ├── musicxml-0.0.2.tgz │ └── musicxml-0.0.3.tgz ├── README ├── pack.pl └── prolog │ └── mxml_portray.pl ├── plumdrum ├── VERSION ├── Makefile ├── release │ ├── plumdrum-0.0.1.tgz │ ├── plumdrum-0.0.2.tgz │ ├── plumdrum-0.0.3.tgz │ ├── plumdrum-0.0.4.tgz │ ├── plumdrum-0.0.5.tgz │ └── plumdrum-0.0.6.tgz ├── pack.pl └── prolog │ └── humdrum │ ├── dynam.pl │ └── reps.pl ├── sindice ├── VERSION ├── release │ ├── sindice-0.0.1.tgz │ ├── sindice-0.0.2.tgz │ ├── sindice-0.0.3.tgz │ ├── sindice-0.0.4.tgz │ ├── sindice-0.0.5.tgz │ └── sindice-0.0.7.tgz ├── pack.pl ├── Makefile └── README ├── sparkle ├── VERSION ├── release │ ├── sparkle-0.0.5.tgz │ ├── sparkle-0.0.6.tgz │ ├── sparkle-0.0.7.tgz │ ├── sparkle-0.0.8.tgz │ ├── sparkle-0.0.9.tgz │ ├── sparkle-0.1.0.tgz │ └── sparkle-0.1.1.tgz ├── pack.pl ├── Makefile └── README ├── template ├── VERSION ├── Makefile ├── pack.pl ├── README └── prolog │ └── template.pl ├── textutils ├── VERSION ├── Makefile ├── release │ └── textutils-0.0.1.tgz ├── pack.pl ├── README └── prolog │ ├── tconsole.pl │ └── docutils.pl ├── timeutils ├── VERSION ├── Makefile ├── release │ ├── timeutils-0.0.1.tgz │ ├── timeutils-0.0.2.tgz │ ├── timeutils-0.0.3.tgz │ └── timeutils-0.0.4.tgz ├── README ├── pack.pl └── prolog │ └── timedcg.pl ├── typedef ├── VERSION ├── Makefile ├── release │ ├── typedef-0.1.0.tgz │ ├── typedef-0.1.1.tgz │ ├── typedef-0.1.2.tgz │ ├── typedef-0.1.3.tgz │ ├── typedef-0.1.3.zip │ ├── typedef-0.1.4.tgz │ ├── typedef-0.1.4.zip │ ├── typedef-0.1.5.tgz │ ├── typedef-0.1.6.tgz │ ├── typedef-0.1.7.tgz │ ├── typedef-0.1.8.tgz │ └── typedef-0.1.9.tgz ├── pack.pl └── README ├── musicbrainz ├── VERSION ├── release │ ├── musicbrainz-0.5.0.tgz │ ├── musicbrainz-0.5.1.tgz │ ├── musicbrainz-0.6.0.tgz │ ├── musicbrainz-0.6.1.tgz │ ├── musicbrainz-0.6.2.tgz │ ├── musicbrainz-0.6.3.tgz │ ├── musicbrainz-0.6.4.tgz │ ├── musicbrainz-0.6.5.tgz │ ├── musicbrainz-0.6.6.tgz │ ├── musicbrainz-0.6.7.tgz │ ├── musicbrainz-0.7.0.tgz │ └── musicbrainz-0.7.1.tgz ├── pack.pl └── Makefile ├── .gitignore ├── webutils └── framework │ ├── basic.pl │ ├── base.pl │ └── kube.pl ├── README.md └── Makefile.inc /cclab/VERSION: -------------------------------------------------------------------------------- 1 | 0.1.5 2 | -------------------------------------------------------------------------------- /memo/VERSION: -------------------------------------------------------------------------------- 1 | 0.6.1 2 | -------------------------------------------------------------------------------- /pldb/VERSION: -------------------------------------------------------------------------------- 1 | 0.0.1 2 | -------------------------------------------------------------------------------- /plsc/VERSION: -------------------------------------------------------------------------------- 1 | 0.1.0 2 | -------------------------------------------------------------------------------- /swipe/VERSION: -------------------------------------------------------------------------------- 1 | 0.2.6 2 | -------------------------------------------------------------------------------- /callgraph/VERSION: -------------------------------------------------------------------------------- 1 | 0.4.1 2 | -------------------------------------------------------------------------------- /dcgutils/VERSION: -------------------------------------------------------------------------------- 1 | 1.1.3 2 | -------------------------------------------------------------------------------- /fileutils/VERSION: -------------------------------------------------------------------------------- 1 | 0.3.5 2 | -------------------------------------------------------------------------------- /genutils/VERSION: -------------------------------------------------------------------------------- 1 | 0.3.9 2 | -------------------------------------------------------------------------------- /midiutils/VERSION: -------------------------------------------------------------------------------- 1 | 0.0.3 2 | -------------------------------------------------------------------------------- /musicxml/VERSION: -------------------------------------------------------------------------------- 1 | 0.0.3 2 | -------------------------------------------------------------------------------- /plumdrum/VERSION: -------------------------------------------------------------------------------- 1 | 0.0.6 2 | -------------------------------------------------------------------------------- /sindice/VERSION: -------------------------------------------------------------------------------- 1 | 0.0.7 2 | -------------------------------------------------------------------------------- /sparkle/VERSION: -------------------------------------------------------------------------------- 1 | 0.1.1 2 | -------------------------------------------------------------------------------- /template/VERSION: -------------------------------------------------------------------------------- 1 | 0.0.1 2 | -------------------------------------------------------------------------------- /textutils/VERSION: -------------------------------------------------------------------------------- 1 | 0.0.1 2 | -------------------------------------------------------------------------------- /timeutils/VERSION: -------------------------------------------------------------------------------- 1 | 0.0.4 2 | -------------------------------------------------------------------------------- /typedef/VERSION: -------------------------------------------------------------------------------- 1 | 0.1.9 2 | -------------------------------------------------------------------------------- /musicbrainz/VERSION: -------------------------------------------------------------------------------- 1 | 0.7.1 2 | -------------------------------------------------------------------------------- /cclab/prolog/cclazy/COPYING: -------------------------------------------------------------------------------- 1 | Copyright Samer Abdallah (2017) 2 | -------------------------------------------------------------------------------- /cclab/Makefile: -------------------------------------------------------------------------------- 1 | PACKNAME=cclab 2 | include ../Makefile.inc 3 | 4 | -------------------------------------------------------------------------------- /pldb/Makefile: -------------------------------------------------------------------------------- 1 | 2 | PACKNAME=pldb 3 | include ../Makefile.inc 4 | 5 | -------------------------------------------------------------------------------- /plsc/Makefile: -------------------------------------------------------------------------------- 1 | 2 | PACKNAME=plsc 3 | include ../Makefile.inc 4 | 5 | -------------------------------------------------------------------------------- /genutils/Makefile: -------------------------------------------------------------------------------- 1 | 2 | PACKNAME=genutils 3 | include ../Makefile.inc 4 | 5 | -------------------------------------------------------------------------------- /musicxml/Makefile: -------------------------------------------------------------------------------- 1 | 2 | PACKNAME=musicxml 3 | include ../Makefile.inc 4 | 5 | -------------------------------------------------------------------------------- /plumdrum/Makefile: -------------------------------------------------------------------------------- 1 | 2 | PACKNAME=plumdrum 3 | include ../Makefile.inc 4 | 5 | -------------------------------------------------------------------------------- /timeutils/Makefile: -------------------------------------------------------------------------------- 1 | PACKNAME=timeutils 2 | include ../Makefile.inc 3 | 4 | -------------------------------------------------------------------------------- /typedef/Makefile: -------------------------------------------------------------------------------- 1 | 2 | PACKNAME=typedef 3 | include ../Makefile.inc 4 | 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .swipl_history 2 | *.aux 3 | *.log 4 | .DS_Store 5 | *.o 6 | .*.swp 7 | -------------------------------------------------------------------------------- /midiutils/Makefile: -------------------------------------------------------------------------------- 1 | 2 | PACKNAME=midiutils 3 | include ../Makefile.inc 4 | 5 | -------------------------------------------------------------------------------- /textutils/Makefile: -------------------------------------------------------------------------------- 1 | 2 | PACKNAME=textutils 3 | include ../Makefile.inc 4 | 5 | -------------------------------------------------------------------------------- /cclab/prolog/cctab/COPYING: -------------------------------------------------------------------------------- 1 | Copyright Samer Abdallah (2017) 2 | All rights reserved. 3 | -------------------------------------------------------------------------------- /template/Makefile: -------------------------------------------------------------------------------- 1 | 2 | PACKNAME= 3 | include ../Makefile.inc 4 | 5 | -------------------------------------------------------------------------------- /cclab/release/cclab-0.0.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/cclab/release/cclab-0.0.1.tgz -------------------------------------------------------------------------------- /cclab/release/cclab-0.0.2.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/cclab/release/cclab-0.0.2.tgz -------------------------------------------------------------------------------- /cclab/release/cclab-0.0.3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/cclab/release/cclab-0.0.3.tgz -------------------------------------------------------------------------------- /cclab/release/cclab-0.0.4.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/cclab/release/cclab-0.0.4.tgz -------------------------------------------------------------------------------- /cclab/release/cclab-0.0.5.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/cclab/release/cclab-0.0.5.tgz -------------------------------------------------------------------------------- /cclab/release/cclab-0.0.6.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/cclab/release/cclab-0.0.6.tgz -------------------------------------------------------------------------------- /cclab/release/cclab-0.0.7.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/cclab/release/cclab-0.0.7.tgz -------------------------------------------------------------------------------- /cclab/release/cclab-0.0.8.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/cclab/release/cclab-0.0.8.tgz -------------------------------------------------------------------------------- /cclab/release/cclab-0.0.9.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/cclab/release/cclab-0.0.9.tgz -------------------------------------------------------------------------------- /cclab/release/cclab-0.1.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/cclab/release/cclab-0.1.0.tgz -------------------------------------------------------------------------------- /cclab/release/cclab-0.1.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/cclab/release/cclab-0.1.1.tgz -------------------------------------------------------------------------------- /cclab/release/cclab-0.1.2.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/cclab/release/cclab-0.1.2.tgz -------------------------------------------------------------------------------- /cclab/release/cclab-0.1.3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/cclab/release/cclab-0.1.3.tgz -------------------------------------------------------------------------------- /cclab/release/cclab-0.1.4.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/cclab/release/cclab-0.1.4.tgz -------------------------------------------------------------------------------- /cclab/release/cclab-0.1.5.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/cclab/release/cclab-0.1.5.tgz -------------------------------------------------------------------------------- /memo/release/memo-0.3.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/memo/release/memo-0.3.0.tgz -------------------------------------------------------------------------------- /memo/release/memo-0.3.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/memo/release/memo-0.3.1.tgz -------------------------------------------------------------------------------- /memo/release/memo-0.3.2.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/memo/release/memo-0.3.2.tgz -------------------------------------------------------------------------------- /memo/release/memo-0.3.3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/memo/release/memo-0.3.3.tgz -------------------------------------------------------------------------------- /memo/release/memo-0.3.4.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/memo/release/memo-0.3.4.tgz -------------------------------------------------------------------------------- /memo/release/memo-0.3.5.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/memo/release/memo-0.3.5.tgz -------------------------------------------------------------------------------- /memo/release/memo-0.3.6.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/memo/release/memo-0.3.6.tgz -------------------------------------------------------------------------------- /memo/release/memo-0.3.7.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/memo/release/memo-0.3.7.tgz -------------------------------------------------------------------------------- /memo/release/memo-0.4.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/memo/release/memo-0.4.0.tgz -------------------------------------------------------------------------------- /memo/release/memo-0.4.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/memo/release/memo-0.4.1.tgz -------------------------------------------------------------------------------- /memo/release/memo-0.4.2.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/memo/release/memo-0.4.2.tgz -------------------------------------------------------------------------------- /memo/release/memo-0.4.3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/memo/release/memo-0.4.3.tgz -------------------------------------------------------------------------------- /memo/release/memo-0.5.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/memo/release/memo-0.5.0.tgz -------------------------------------------------------------------------------- /memo/release/memo-0.5.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/memo/release/memo-0.5.1.tgz -------------------------------------------------------------------------------- /memo/release/memo-0.5.2.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/memo/release/memo-0.5.2.tgz -------------------------------------------------------------------------------- /memo/release/memo-0.5.3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/memo/release/memo-0.5.3.tgz -------------------------------------------------------------------------------- /memo/release/memo-0.6.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/memo/release/memo-0.6.0.tgz -------------------------------------------------------------------------------- /memo/release/memo-0.6.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/memo/release/memo-0.6.1.tgz -------------------------------------------------------------------------------- /pldb/release/pldb-0.0.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/pldb/release/pldb-0.0.1.tgz -------------------------------------------------------------------------------- /plsc/release/plsc-0.1.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/plsc/release/plsc-0.1.0.tgz -------------------------------------------------------------------------------- /swipe/release/swipe-0.1.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/swipe/release/swipe-0.1.0.tgz -------------------------------------------------------------------------------- /swipe/release/swipe-0.1.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/swipe/release/swipe-0.1.1.tgz -------------------------------------------------------------------------------- /swipe/release/swipe-0.1.2.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/swipe/release/swipe-0.1.2.tgz -------------------------------------------------------------------------------- /swipe/release/swipe-0.2.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/swipe/release/swipe-0.2.0.tgz -------------------------------------------------------------------------------- /swipe/release/swipe-0.2.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/swipe/release/swipe-0.2.1.tgz -------------------------------------------------------------------------------- /swipe/release/swipe-0.2.2.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/swipe/release/swipe-0.2.2.tgz -------------------------------------------------------------------------------- /swipe/release/swipe-0.2.3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/swipe/release/swipe-0.2.3.tgz -------------------------------------------------------------------------------- /swipe/release/swipe-0.2.4.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/swipe/release/swipe-0.2.4.tgz -------------------------------------------------------------------------------- /swipe/release/swipe-0.2.5.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/swipe/release/swipe-0.2.5.tgz -------------------------------------------------------------------------------- /swipe/release/swipe-0.2.6.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/swipe/release/swipe-0.2.6.tgz -------------------------------------------------------------------------------- /callgraph/examples/callgraph.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/callgraph/examples/callgraph.pdf -------------------------------------------------------------------------------- /sindice/release/sindice-0.0.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/sindice/release/sindice-0.0.1.tgz -------------------------------------------------------------------------------- /sindice/release/sindice-0.0.2.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/sindice/release/sindice-0.0.2.tgz -------------------------------------------------------------------------------- /sindice/release/sindice-0.0.3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/sindice/release/sindice-0.0.3.tgz -------------------------------------------------------------------------------- /sindice/release/sindice-0.0.4.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/sindice/release/sindice-0.0.4.tgz -------------------------------------------------------------------------------- /sindice/release/sindice-0.0.5.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/sindice/release/sindice-0.0.5.tgz -------------------------------------------------------------------------------- /sindice/release/sindice-0.0.7.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/sindice/release/sindice-0.0.7.tgz -------------------------------------------------------------------------------- /sparkle/release/sparkle-0.0.5.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/sparkle/release/sparkle-0.0.5.tgz -------------------------------------------------------------------------------- /sparkle/release/sparkle-0.0.6.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/sparkle/release/sparkle-0.0.6.tgz -------------------------------------------------------------------------------- /sparkle/release/sparkle-0.0.7.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/sparkle/release/sparkle-0.0.7.tgz -------------------------------------------------------------------------------- /sparkle/release/sparkle-0.0.8.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/sparkle/release/sparkle-0.0.8.tgz -------------------------------------------------------------------------------- /sparkle/release/sparkle-0.0.9.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/sparkle/release/sparkle-0.0.9.tgz -------------------------------------------------------------------------------- /sparkle/release/sparkle-0.1.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/sparkle/release/sparkle-0.1.0.tgz -------------------------------------------------------------------------------- /sparkle/release/sparkle-0.1.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/sparkle/release/sparkle-0.1.1.tgz -------------------------------------------------------------------------------- /typedef/release/typedef-0.1.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/typedef/release/typedef-0.1.0.tgz -------------------------------------------------------------------------------- /typedef/release/typedef-0.1.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/typedef/release/typedef-0.1.1.tgz -------------------------------------------------------------------------------- /typedef/release/typedef-0.1.2.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/typedef/release/typedef-0.1.2.tgz -------------------------------------------------------------------------------- /typedef/release/typedef-0.1.3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/typedef/release/typedef-0.1.3.tgz -------------------------------------------------------------------------------- /typedef/release/typedef-0.1.3.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/typedef/release/typedef-0.1.3.zip -------------------------------------------------------------------------------- /typedef/release/typedef-0.1.4.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/typedef/release/typedef-0.1.4.tgz -------------------------------------------------------------------------------- /typedef/release/typedef-0.1.4.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/typedef/release/typedef-0.1.4.zip -------------------------------------------------------------------------------- /typedef/release/typedef-0.1.5.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/typedef/release/typedef-0.1.5.tgz -------------------------------------------------------------------------------- /typedef/release/typedef-0.1.6.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/typedef/release/typedef-0.1.6.tgz -------------------------------------------------------------------------------- /typedef/release/typedef-0.1.7.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/typedef/release/typedef-0.1.7.tgz -------------------------------------------------------------------------------- /typedef/release/typedef-0.1.8.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/typedef/release/typedef-0.1.8.tgz -------------------------------------------------------------------------------- /typedef/release/typedef-0.1.9.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/typedef/release/typedef-0.1.9.tgz -------------------------------------------------------------------------------- /callgraph/examples/callgraph_dot.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/callgraph/examples/callgraph_dot.pdf -------------------------------------------------------------------------------- /dcgutils/release/dcgutils-0.0.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/dcgutils/release/dcgutils-0.0.1.tgz -------------------------------------------------------------------------------- /dcgutils/release/dcgutils-0.0.2.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/dcgutils/release/dcgutils-0.0.2.tgz -------------------------------------------------------------------------------- /dcgutils/release/dcgutils-0.0.3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/dcgutils/release/dcgutils-0.0.3.tgz -------------------------------------------------------------------------------- /dcgutils/release/dcgutils-0.0.4.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/dcgutils/release/dcgutils-0.0.4.tgz -------------------------------------------------------------------------------- /dcgutils/release/dcgutils-0.0.5.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/dcgutils/release/dcgutils-0.0.5.tgz -------------------------------------------------------------------------------- /dcgutils/release/dcgutils-0.0.6.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/dcgutils/release/dcgutils-0.0.6.tgz -------------------------------------------------------------------------------- /dcgutils/release/dcgutils-0.0.7.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/dcgutils/release/dcgutils-0.0.7.tgz -------------------------------------------------------------------------------- /dcgutils/release/dcgutils-0.0.8.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/dcgutils/release/dcgutils-0.0.8.tgz -------------------------------------------------------------------------------- /dcgutils/release/dcgutils-0.0.9.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/dcgutils/release/dcgutils-0.0.9.tgz -------------------------------------------------------------------------------- /dcgutils/release/dcgutils-1.0.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/dcgutils/release/dcgutils-1.0.0.tgz -------------------------------------------------------------------------------- /dcgutils/release/dcgutils-1.0.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/dcgutils/release/dcgutils-1.0.1.tgz -------------------------------------------------------------------------------- /dcgutils/release/dcgutils-1.0.2.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/dcgutils/release/dcgutils-1.0.2.tgz -------------------------------------------------------------------------------- /dcgutils/release/dcgutils-1.0.3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/dcgutils/release/dcgutils-1.0.3.tgz -------------------------------------------------------------------------------- /dcgutils/release/dcgutils-1.0.4.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/dcgutils/release/dcgutils-1.0.4.tgz -------------------------------------------------------------------------------- /dcgutils/release/dcgutils-1.0.5.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/dcgutils/release/dcgutils-1.0.5.tgz -------------------------------------------------------------------------------- /dcgutils/release/dcgutils-1.0.6.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/dcgutils/release/dcgutils-1.0.6.tgz -------------------------------------------------------------------------------- /dcgutils/release/dcgutils-1.0.7.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/dcgutils/release/dcgutils-1.0.7.tgz -------------------------------------------------------------------------------- /dcgutils/release/dcgutils-1.0.8.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/dcgutils/release/dcgutils-1.0.8.tgz -------------------------------------------------------------------------------- /dcgutils/release/dcgutils-1.1.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/dcgutils/release/dcgutils-1.1.0.tgz -------------------------------------------------------------------------------- /dcgutils/release/dcgutils-1.1.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/dcgutils/release/dcgutils-1.1.1.tgz -------------------------------------------------------------------------------- /dcgutils/release/dcgutils-1.1.2.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/dcgutils/release/dcgutils-1.1.2.tgz -------------------------------------------------------------------------------- /dcgutils/release/dcgutils-1.1.3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/dcgutils/release/dcgutils-1.1.3.tgz -------------------------------------------------------------------------------- /genutils/release/genutils-0.0.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/genutils/release/genutils-0.0.1.tgz -------------------------------------------------------------------------------- /genutils/release/genutils-0.0.2.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/genutils/release/genutils-0.0.2.tgz -------------------------------------------------------------------------------- /genutils/release/genutils-0.0.3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/genutils/release/genutils-0.0.3.tgz -------------------------------------------------------------------------------- /genutils/release/genutils-0.0.4.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/genutils/release/genutils-0.0.4.tgz -------------------------------------------------------------------------------- /genutils/release/genutils-0.0.5.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/genutils/release/genutils-0.0.5.tgz -------------------------------------------------------------------------------- /genutils/release/genutils-0.0.6.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/genutils/release/genutils-0.0.6.tgz -------------------------------------------------------------------------------- /genutils/release/genutils-0.0.7.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/genutils/release/genutils-0.0.7.tgz -------------------------------------------------------------------------------- /genutils/release/genutils-0.0.9.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/genutils/release/genutils-0.0.9.tgz -------------------------------------------------------------------------------- /genutils/release/genutils-0.2.00.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/genutils/release/genutils-0.2.00.tgz -------------------------------------------------------------------------------- /genutils/release/genutils-0.3.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/genutils/release/genutils-0.3.0.tgz -------------------------------------------------------------------------------- /genutils/release/genutils-0.3.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/genutils/release/genutils-0.3.1.tgz -------------------------------------------------------------------------------- /genutils/release/genutils-0.3.2.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/genutils/release/genutils-0.3.2.tgz -------------------------------------------------------------------------------- /genutils/release/genutils-0.3.3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/genutils/release/genutils-0.3.3.tgz -------------------------------------------------------------------------------- /genutils/release/genutils-0.3.4.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/genutils/release/genutils-0.3.4.tgz -------------------------------------------------------------------------------- /genutils/release/genutils-0.3.5.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/genutils/release/genutils-0.3.5.tgz -------------------------------------------------------------------------------- /genutils/release/genutils-0.3.6.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/genutils/release/genutils-0.3.6.tgz -------------------------------------------------------------------------------- /genutils/release/genutils-0.3.7.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/genutils/release/genutils-0.3.7.tgz -------------------------------------------------------------------------------- /genutils/release/genutils-0.3.8.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/genutils/release/genutils-0.3.8.tgz -------------------------------------------------------------------------------- /genutils/release/genutils-0.3.9.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/genutils/release/genutils-0.3.9.tgz -------------------------------------------------------------------------------- /musicxml/release/musicxml-0.0.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/musicxml/release/musicxml-0.0.1.tgz -------------------------------------------------------------------------------- /musicxml/release/musicxml-0.0.2.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/musicxml/release/musicxml-0.0.2.tgz -------------------------------------------------------------------------------- /musicxml/release/musicxml-0.0.3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/musicxml/release/musicxml-0.0.3.tgz -------------------------------------------------------------------------------- /plumdrum/release/plumdrum-0.0.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/plumdrum/release/plumdrum-0.0.1.tgz -------------------------------------------------------------------------------- /plumdrum/release/plumdrum-0.0.2.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/plumdrum/release/plumdrum-0.0.2.tgz -------------------------------------------------------------------------------- /plumdrum/release/plumdrum-0.0.3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/plumdrum/release/plumdrum-0.0.3.tgz -------------------------------------------------------------------------------- /plumdrum/release/plumdrum-0.0.4.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/plumdrum/release/plumdrum-0.0.4.tgz -------------------------------------------------------------------------------- /plumdrum/release/plumdrum-0.0.5.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/plumdrum/release/plumdrum-0.0.5.tgz -------------------------------------------------------------------------------- /plumdrum/release/plumdrum-0.0.6.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/plumdrum/release/plumdrum-0.0.6.tgz -------------------------------------------------------------------------------- /callgraph/examples/test2.pl: -------------------------------------------------------------------------------- 1 | :- use_module(library(callgraph)). 2 | :- use_module(testmod1). 3 | :- use_module(testmod2). 4 | -------------------------------------------------------------------------------- /callgraph/release/callgraph-0.3.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/callgraph/release/callgraph-0.3.0.tgz -------------------------------------------------------------------------------- /callgraph/release/callgraph-0.3.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/callgraph/release/callgraph-0.3.1.tgz -------------------------------------------------------------------------------- /callgraph/release/callgraph-0.3.2.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/callgraph/release/callgraph-0.3.2.tgz -------------------------------------------------------------------------------- /callgraph/release/callgraph-0.3.3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/callgraph/release/callgraph-0.3.3.tgz -------------------------------------------------------------------------------- /callgraph/release/callgraph-0.3.4.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/callgraph/release/callgraph-0.3.4.tgz -------------------------------------------------------------------------------- /callgraph/release/callgraph-0.3.5.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/callgraph/release/callgraph-0.3.5.tgz -------------------------------------------------------------------------------- /callgraph/release/callgraph-0.4.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/callgraph/release/callgraph-0.4.0.tgz -------------------------------------------------------------------------------- /callgraph/release/callgraph-0.4.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/callgraph/release/callgraph-0.4.1.tgz -------------------------------------------------------------------------------- /fileutils/release/fileutils-0.1.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/fileutils/release/fileutils-0.1.1.tgz -------------------------------------------------------------------------------- /fileutils/release/fileutils-0.1.2.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/fileutils/release/fileutils-0.1.2.tgz -------------------------------------------------------------------------------- /fileutils/release/fileutils-0.1.3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/fileutils/release/fileutils-0.1.3.tgz -------------------------------------------------------------------------------- /fileutils/release/fileutils-0.1.4.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/fileutils/release/fileutils-0.1.4.tgz -------------------------------------------------------------------------------- /fileutils/release/fileutils-0.1.5.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/fileutils/release/fileutils-0.1.5.tgz -------------------------------------------------------------------------------- /fileutils/release/fileutils-0.2.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/fileutils/release/fileutils-0.2.0.tgz -------------------------------------------------------------------------------- /fileutils/release/fileutils-0.2.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/fileutils/release/fileutils-0.2.1.tgz -------------------------------------------------------------------------------- /fileutils/release/fileutils-0.2.2.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/fileutils/release/fileutils-0.2.2.tgz -------------------------------------------------------------------------------- /fileutils/release/fileutils-0.2.3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/fileutils/release/fileutils-0.2.3.tgz -------------------------------------------------------------------------------- /fileutils/release/fileutils-0.2.4.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/fileutils/release/fileutils-0.2.4.tgz -------------------------------------------------------------------------------- /fileutils/release/fileutils-0.3.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/fileutils/release/fileutils-0.3.0.tgz -------------------------------------------------------------------------------- /fileutils/release/fileutils-0.3.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/fileutils/release/fileutils-0.3.1.tgz -------------------------------------------------------------------------------- /fileutils/release/fileutils-0.3.2.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/fileutils/release/fileutils-0.3.2.tgz -------------------------------------------------------------------------------- /fileutils/release/fileutils-0.3.3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/fileutils/release/fileutils-0.3.3.tgz -------------------------------------------------------------------------------- /fileutils/release/fileutils-0.3.4.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/fileutils/release/fileutils-0.3.4.tgz -------------------------------------------------------------------------------- /fileutils/release/fileutils-0.3.5.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/fileutils/release/fileutils-0.3.5.tgz -------------------------------------------------------------------------------- /midiutils/release/midiutils-0.0.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/midiutils/release/midiutils-0.0.1.tgz -------------------------------------------------------------------------------- /midiutils/release/midiutils-0.0.2.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/midiutils/release/midiutils-0.0.2.tgz -------------------------------------------------------------------------------- /midiutils/release/midiutils-0.0.3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/midiutils/release/midiutils-0.0.3.tgz -------------------------------------------------------------------------------- /musicxml/README: -------------------------------------------------------------------------------- 1 | 2 | This package provides limited facilities for reading MusicXML files. 3 | 4 | ---++++ Simple usage 5 | 6 | -------------------------------------------------------------------------------- /textutils/release/textutils-0.0.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/textutils/release/textutils-0.0.1.tgz -------------------------------------------------------------------------------- /timeutils/release/timeutils-0.0.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/timeutils/release/timeutils-0.0.1.tgz -------------------------------------------------------------------------------- /timeutils/release/timeutils-0.0.2.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/timeutils/release/timeutils-0.0.2.tgz -------------------------------------------------------------------------------- /timeutils/release/timeutils-0.0.3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/timeutils/release/timeutils-0.0.3.tgz -------------------------------------------------------------------------------- /timeutils/release/timeutils-0.0.4.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/timeutils/release/timeutils-0.0.4.tgz -------------------------------------------------------------------------------- /fileutils/Makefile: -------------------------------------------------------------------------------- 1 | # ---------------- configuration ---------------------- 2 | PACKNAME=fileutils 3 | include ../Makefile.inc 4 | -------------------------------------------------------------------------------- /musicbrainz/release/musicbrainz-0.5.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/musicbrainz/release/musicbrainz-0.5.0.tgz -------------------------------------------------------------------------------- /musicbrainz/release/musicbrainz-0.5.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/musicbrainz/release/musicbrainz-0.5.1.tgz -------------------------------------------------------------------------------- /musicbrainz/release/musicbrainz-0.6.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/musicbrainz/release/musicbrainz-0.6.0.tgz -------------------------------------------------------------------------------- /musicbrainz/release/musicbrainz-0.6.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/musicbrainz/release/musicbrainz-0.6.1.tgz -------------------------------------------------------------------------------- /musicbrainz/release/musicbrainz-0.6.2.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/musicbrainz/release/musicbrainz-0.6.2.tgz -------------------------------------------------------------------------------- /musicbrainz/release/musicbrainz-0.6.3.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/musicbrainz/release/musicbrainz-0.6.3.tgz -------------------------------------------------------------------------------- /musicbrainz/release/musicbrainz-0.6.4.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/musicbrainz/release/musicbrainz-0.6.4.tgz -------------------------------------------------------------------------------- /musicbrainz/release/musicbrainz-0.6.5.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/musicbrainz/release/musicbrainz-0.6.5.tgz -------------------------------------------------------------------------------- /musicbrainz/release/musicbrainz-0.6.6.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/musicbrainz/release/musicbrainz-0.6.6.tgz -------------------------------------------------------------------------------- /musicbrainz/release/musicbrainz-0.6.7.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/musicbrainz/release/musicbrainz-0.6.7.tgz -------------------------------------------------------------------------------- /musicbrainz/release/musicbrainz-0.7.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/musicbrainz/release/musicbrainz-0.7.0.tgz -------------------------------------------------------------------------------- /musicbrainz/release/musicbrainz-0.7.1.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samer--/prolog/HEAD/musicbrainz/release/musicbrainz-0.7.1.tgz -------------------------------------------------------------------------------- /midiutils/README: -------------------------------------------------------------------------------- 1 | This package provides MIDI related functionality that is not dependent on any foreign libraries. 2 | 3 | ---++++ Simple usage 4 | 5 | -------------------------------------------------------------------------------- /template/pack.pl: -------------------------------------------------------------------------------- 1 | name(). 2 | version(''). 3 | author('Samer Abdallah',''). 4 | title('Title of new pack'). 5 | download(''). 6 | 7 | -------------------------------------------------------------------------------- /pldb/pack.pl: -------------------------------------------------------------------------------- 1 | name(). 2 | version(''). 3 | author('Samer Abdallah',''). 4 | title('Prolog tools for SQL databases'). 5 | download(''). 6 | 7 | -------------------------------------------------------------------------------- /genutils/pack.pl: -------------------------------------------------------------------------------- 1 | name(). 2 | version(''). 3 | author('Samer Abdallah',''). 4 | title('General miscellaneous utilities'). 5 | download(''). 6 | 7 | -------------------------------------------------------------------------------- /midiutils/pack.pl: -------------------------------------------------------------------------------- 1 | name(). 2 | version(''). 3 | author('Samer Abdallah',''). 4 | title(midiutils). 5 | download(''). 6 | requires(dcgutils). 7 | 8 | -------------------------------------------------------------------------------- /sindice/pack.pl: -------------------------------------------------------------------------------- 1 | name(). 2 | version(''). 3 | author('Samer Abdallah',''). 4 | title('Access to Sindice semantic web search engine'). 5 | download(''). 6 | -------------------------------------------------------------------------------- /timeutils/README: -------------------------------------------------------------------------------- 1 | This package provides tools for programs that deal with time. 2 | Currently there is only a small library for working in a DCG 3 | where the threaded state is a time. 4 | -------------------------------------------------------------------------------- /dcgutils/pack.pl: -------------------------------------------------------------------------------- 1 | name(). 2 | version(''). 3 | author('Samer Abdallah',''). 4 | title('DCG related utilities'). 5 | download(''). 6 | requires(genutils). 7 | 8 | -------------------------------------------------------------------------------- /fileutils/pack.pl: -------------------------------------------------------------------------------- 1 | name(fileutils). 2 | version(''). 3 | author('Samer Abdallah',''). 4 | title('Utilities for reading, writing and finding files'). 5 | download(''). 6 | -------------------------------------------------------------------------------- /typedef/pack.pl: -------------------------------------------------------------------------------- 1 | name(typedef). 2 | version(''). 3 | author('Samer Abdallah',''). 4 | title('Support for type definitions'). 5 | keywords([types]). 6 | download(''). 7 | 8 | -------------------------------------------------------------------------------- /musicbrainz/pack.pl: -------------------------------------------------------------------------------- 1 | name(). 2 | version(''). 3 | author('Samer Abdallah',''). 4 | title('Musicbrainz client library'). 5 | download(''). 6 | requires(dcgutils). 7 | 8 | -------------------------------------------------------------------------------- /textutils/pack.pl: -------------------------------------------------------------------------------- 1 | name(). 2 | version(''). 3 | author('Samer Abdallah',''). 4 | title(textutils). 5 | download(''). 6 | requires(genutils). 7 | requires(memo). 8 | 9 | -------------------------------------------------------------------------------- /timeutils/pack.pl: -------------------------------------------------------------------------------- 1 | name(). 2 | version(''). 3 | author('Samer Abdallah',''). 4 | title('Tools for temporally aware programming'). 5 | download(''). 6 | requires(dcgutils). 7 | 8 | -------------------------------------------------------------------------------- /sparkle/pack.pl: -------------------------------------------------------------------------------- 1 | name(). 2 | version(''). 3 | author('Samer Abdallah',''). 4 | title('Prolog-friendly interface to SPARQL endpoints'). 5 | download(''). 6 | requires(dcgutils). 7 | 8 | -------------------------------------------------------------------------------- /musicxml/pack.pl: -------------------------------------------------------------------------------- 1 | name(). 2 | version(''). 3 | author('Samer Abdallah',''). 4 | title('MusicXML partial reader'). 5 | download(''). 6 | requires(genutils). 7 | requires(dcgutils). 8 | 9 | -------------------------------------------------------------------------------- /plsc/pack.pl: -------------------------------------------------------------------------------- 1 | name(). 2 | version(''). 3 | author('Samer Abdallah',''). 4 | title('Interaction with Supercollider server'). 5 | download(''). 6 | requires(dcgutils). 7 | requires(plosc). 8 | 9 | -------------------------------------------------------------------------------- /callgraph/examples/testmod2.pl: -------------------------------------------------------------------------------- 1 | :- module(testmod2, [test1/0, test2/0]). 2 | :- use_module(testmod1). 3 | 4 | test1 :- 5 | pred3, 6 | forall( dyn1(A), writeln(dyn1(A))). 7 | 8 | test2 :- 9 | assert(testmod1:dyn1(b)). 10 | -------------------------------------------------------------------------------- /cclab/pack.pl: -------------------------------------------------------------------------------- 1 | name(). 2 | version(''). 3 | author('Samer Abdallah',''). 4 | title('Continuations lab'). 5 | download(''). 6 | requires(typedef). 7 | requires(dcgutils). 8 | requires(genutils). 9 | 10 | -------------------------------------------------------------------------------- /swipe/pack.pl: -------------------------------------------------------------------------------- 1 | name(). 2 | version(''). 3 | author('Samer Abdallah',''). 4 | title('Shell pipeline construction with type checking'). 5 | download(''). 6 | requires(dcgutils). 7 | requires(fileutils). 8 | 9 | -------------------------------------------------------------------------------- /plumdrum/pack.pl: -------------------------------------------------------------------------------- 1 | name(). 2 | version(''). 3 | author('Samer Abdallah',''). 4 | title('Parsing of Humdrum/Kern symbolic music file format'). 5 | download(''). 6 | requires(dcgutils). 7 | requires(fileutils). 8 | 9 | -------------------------------------------------------------------------------- /textutils/README: -------------------------------------------------------------------------------- 1 | 2 | This package provides tools for outputting text in various ways. 3 | 4 | 5 | ---++++ Speech using Mac OS X synthesiser 6 | 7 | ---++++ Formatted HTML using text mode browser 8 | 9 | ---++++ Text renderer framework 10 | 11 | 12 | -------------------------------------------------------------------------------- /plsc/README: -------------------------------------------------------------------------------- 1 | +++ plsc - Tools for talking to a Supercollider server from Prolog. 2 | 3 | This is rather unfinished - a minimal interface for starting, controlling 4 | and stopping synths is provided by sc.pl. A more complete interface 5 | is in progress in plsc.pl. 6 | 7 | -------------------------------------------------------------------------------- /webutils/framework/basic.pl: -------------------------------------------------------------------------------- 1 | :- module(basic, []). 2 | 3 | :- use_module(library(http/html_write)). 4 | :- use_module(library(http/html_head)). 5 | 6 | user:body(basic,Body) --> 7 | html_requires(weblib('styles/home.css')), 8 | html(body([ div(id(content),Body) ])). 9 | -------------------------------------------------------------------------------- /memo/pack.pl: -------------------------------------------------------------------------------- 1 | name(). 2 | version(''). 3 | author('Samer Abdallah',''). 4 | title('Persistent memoisation of deterministic predicates'). 5 | keywords([memoisation,persistency]). 6 | download(''). 7 | requires(typedef). 8 | requires(genutils). 9 | 10 | -------------------------------------------------------------------------------- /callgraph/pack.pl: -------------------------------------------------------------------------------- 1 | name(). 2 | version(''). 3 | author('Samer Abdallah',''). 4 | title('Predicate call graph visualisation'). 5 | keywords([cross_referencing,graph,visualisation,dot]). 6 | download(''). 7 | requires(fileutils). 8 | requires(dcgutils). 9 | requires(swipe). 10 | 11 | -------------------------------------------------------------------------------- /swipe/Makefile: -------------------------------------------------------------------------------- 1 | # ---------------- configuration ---------------------- 2 | 3 | # if you have multiple SWI Prolog installations or an installation 4 | # in a non-standard place, set PLLD to the appropriate plld invokation, eg 5 | # PLLD=/usr/local/bin/plld -p /usr/local/bin/swipl 6 | 7 | PACKNAME=swipe 8 | include ../Makefile.inc 9 | -------------------------------------------------------------------------------- /dcgutils/Makefile: -------------------------------------------------------------------------------- 1 | # ---------------- configuration ---------------------- 2 | 3 | # if you have multiple SWI Prolog installations or an installation 4 | # in a non-standard place, set PLLD to the appropriate plld invokation, eg 5 | # PLLD=/usr/local/bin/plld -p /usr/local/bin/swipl 6 | 7 | PACKNAME=dcgutils 8 | include ../Makefile.inc 9 | -------------------------------------------------------------------------------- /sindice/Makefile: -------------------------------------------------------------------------------- 1 | # ---------------- configuration ---------------------- 2 | 3 | # if you have multiple SWI Prolog installations or an installation 4 | # in a non-standard place, set PLLD to the appropriate plld invokation, eg 5 | # PLLD=/usr/local/bin/plld -p /usr/local/bin/swipl 6 | 7 | PACKNAME=sindice 8 | include ../Makefile.inc 9 | -------------------------------------------------------------------------------- /callgraph/Makefile: -------------------------------------------------------------------------------- 1 | # ---------------- configuration ---------------------- 2 | 3 | # if you have multiple SWI Prolog installations or an installation 4 | # in a non-standard place, set PLLD to the appropriate plld invokation, eg 5 | # PLLD=/usr/local/bin/plld -p /usr/local/bin/swipl 6 | 7 | PACKNAME=callgraph 8 | include ../Makefile.inc 9 | -------------------------------------------------------------------------------- /musicbrainz/Makefile: -------------------------------------------------------------------------------- 1 | # ---------------- configuration ---------------------- 2 | 3 | # if you have multiple SWI Prolog installations or an installation 4 | # in a non-standard place, set PLLD to the appropriate plld invokation, eg 5 | # PLLD=/usr/local/bin/plld -p /usr/local/bin/swipl 6 | 7 | PACKNAME=musicbrainz 8 | include ../Makefile.inc 9 | -------------------------------------------------------------------------------- /memo/Makefile: -------------------------------------------------------------------------------- 1 | # ---------------- configuration ---------------------- 2 | 3 | # if you have multiple SWI Prolog installations or an installation 4 | # in a non-standard place, set PLLD to the appropriate plld invokation, eg 5 | # PLLD=/usr/local/bin/plld -p /usr/local/bin/swipl 6 | 7 | PACKNAME=memo 8 | include ../Makefile.inc 9 | 10 | -------------------------------------------------------------------------------- /sparkle/Makefile: -------------------------------------------------------------------------------- 1 | # ---------------- configuration ---------------------- 2 | 3 | # if you have multiple SWI Prolog installations or an installation 4 | # in a non-standard place, set PLLD to the appropriate plld invokation, eg 5 | # PLLD=/usr/local/bin/plld -p /usr/local/bin/swipl 6 | 7 | PACKNAME=sparkle 8 | include ../Makefile.inc 9 | 10 | -------------------------------------------------------------------------------- /fileutils/README: -------------------------------------------------------------------------------- 1 | This package provides library(fileutils), some small utilities that extend 2 | SWIs built-in facilities from library(readutil) and with_output_to/2 etc. 3 | 4 | See library(fileutils) module header for more information. 5 | 6 | ### New in version 0.2.0 7 | 8 | - Moved with_temp_dir/2 from swipe package. 9 | - Added in_temp_dir/1. 10 | 11 | -------------------------------------------------------------------------------- /pldb/prolog/pldb_mysql.pl: -------------------------------------------------------------------------------- 1 | :- module(pldb_mysql,[]). 2 | :- multifile pldb:type_class/2. 3 | 4 | type_class(tinyint, numeric). 5 | type_class(smallint, numeric). 6 | type_class(mediumint, numeric). 7 | type_class(int, numeric). 8 | type_class(bigint, numeric). 9 | type_class('integer unsigned', numeric). 10 | type_class('tinyint unsigned', numeric). 11 | -------------------------------------------------------------------------------- /callgraph/examples/testmod1.pl: -------------------------------------------------------------------------------- 1 | :- module(testmod1, [pred1/0, pred2/0, pred3/0, dyn1/1]). 2 | 3 | :- dynamic dyn1/1. 4 | 5 | pred1 :- 6 | recorda(key1,head(1)), 7 | writeln(record(key1,head(1))). 8 | 9 | pred2 :- 10 | recorded(key1,head(V)), 11 | writeln(recorded(key1,head(V))). 12 | 13 | pred3 :- 14 | pred1, 15 | pred2, 16 | pred4. 17 | 18 | pred4 :- assert(dyn1(a)). 19 | 20 | -------------------------------------------------------------------------------- /typedef/README: -------------------------------------------------------------------------------- 1 | This package provides library(typedef), a small library for 2 | processing type declarations. 3 | 4 | See library(typedef) module header for more information. 5 | 6 | ---++++ Quick test 7 | 8 | This is a small test file that you can use to check if it works. 9 | == 10 | :- use_module(library(typedef)). 11 | 12 | :- type maybe(A) ---> nothing; just(A). 13 | :- type natural == nonneg. 14 | 15 | %% test(+A:natural, +B:maybe(natural)) is det. 16 | test(A,B) :- 17 | must_be(natural,A), 18 | must_be(maybe(natural),B). 19 | == 20 | -------------------------------------------------------------------------------- /memo/examples/test_memo.pl: -------------------------------------------------------------------------------- 1 | :- use_module(library(memo)). 2 | :- use_module(library(typedef)). 3 | 4 | :- type maybe(A) ---> nothing; just(A). 5 | :- volatile_memo sqrt1(+float, -maybe(float)). 6 | :- persistent_memo sqrt2( +float, -float). 7 | 8 | sqrt1(X,just(Y)) :- X>=0, !, Y is sqrt(X). 9 | sqrt1(_,nothing). 10 | 11 | % this will throw an exception if X<0 12 | sqrt2(X,Y) :- Y is sqrt(X). 13 | 14 | :- initialization 15 | db_attach('test.db',[]), % attach database for persistent memo 16 | debug(memo). % tocheck memoisation operations 17 | -------------------------------------------------------------------------------- /pldb/README: -------------------------------------------------------------------------------- 1 | This is a template for a SWI Prolog add-on package. 2 | To complete it: 3 | 1. Write something helpful in this README; 4 | 2. Edit the Makefile to give the package a name; 5 | 3. Edit the pack.pl to dependencies, keywords etc; 6 | 4. Write the code in prolog/; 7 | 5. Do a local test using 'make install'; 8 | 6. Put the whole lot on github; 9 | 7. Do a public install using 'make install-git'. 10 | 11 | ------------------------------------------------ 12 | 13 | This package provides ... 14 | 15 | ---++++ Prerequisites 16 | 17 | ---++++ Simple usage 18 | 19 | ---++++ Planned enhancements 20 | 21 | -------------------------------------------------------------------------------- /template/README: -------------------------------------------------------------------------------- 1 | This is a template for a SWI Prolog add-on package. 2 | To complete it: 3 | 1. Write something helpful in this README; 4 | 2. Edit the Makefile to give the package a name; 5 | 3. Edit the pack.pl to dependencies, keywords etc; 6 | 4. Write the code in prolog/; 7 | 5. Do a local test using 'make install'; 8 | 6. Put the whole lot on github; 9 | 7. Do a public install using 'make install-git'. 10 | 11 | ------------------------------------------------ 12 | 13 | This package provides ... 14 | 15 | ---++++ Prerequisites 16 | 17 | ---++++ Simple usage 18 | 19 | ---++++ Planned enhancements 20 | 21 | -------------------------------------------------------------------------------- /genutils/prolog/lambdaki.pl: -------------------------------------------------------------------------------- 1 | :- module(lambdaki, [ (\)/2, (\)/3, (\)/4, (^)/3, (^)/4, (^)/5 ]). 2 | % Very small lambda library (with no free variables and no checking anything) 3 | 4 | :- meta_predicate \(1,?), \(2,?,?), \(3,?,?,?). 5 | :- meta_predicate ^(?,0,?), ^(?,1,?,?), ^(?,2,?,?,?). 6 | 7 | :- set_prolog_flag(generate_debug_info, false). 8 | 9 | \(M:Hats,A1) :- copy_term(Hats,Copy), call(M:Copy,A1). 10 | \(M:Hats,A1,A2) :- copy_term(Hats,Copy), call(M:Copy,A1,A2). 11 | \(M:Hats,A1,A2,A3) :- copy_term(Hats,Copy), call(M:Copy,A1,A2,A3). 12 | 13 | ^(A1,P,A1) :- call(P). 14 | ^(A1,P,A1,A2) :- call(P,A2). 15 | ^(A1,P,A1,A2,A3) :- call(P,A2,A3). 16 | -------------------------------------------------------------------------------- /genutils/README: -------------------------------------------------------------------------------- 1 | This package provides general utilities. 2 | 3 | ---++++ listutils 4 | 5 | * take/3 and drop/3, take_while/3 and drop_while/3 6 | * rep/3 for build a list by repeating an element 7 | * cons/3 and decons/3 8 | * print_list/1, printq_list/1, print_numbered_list/1 9 | 10 | ---++++ termutils 11 | 12 | * with_status_line/1 13 | Provides an environment where messages printed with status/2 appear 14 | over each other on one line. The environment makes sure that when 15 | a shorter line is printed after a longer one, the remaining characters 16 | are erased. 17 | 18 | ---++++ pairs 19 | 20 | Tools for working with X-Y terms. 21 | 22 | -------------------------------------------------------------------------------- /cclab/prolog/cctab/junk.pl: -------------------------------------------------------------------------------- 1 | 2 | % weird failure driven EM! 3 | :- meta_predicate em(+,0,+,-), em(+,0,+,+,-). 4 | 5 | em(Graph, Goal, P0, P2) :- 6 | graph_stats(Graph, Goal, P, LP, Stats), 7 | nb_setval(emp, P0), 8 | repeat, 9 | nb_getval(emp,P), 10 | stats_to_params(Stats,P2), 11 | format('Log prob = ~g\n',[LP]), 12 | nb_setval(emp,P2). 13 | 14 | % broken aggregation based graph inversion 15 | invert_graph(IGraph, InvGraph) :- 16 | bagof(Q-QCs, bagof(QC, IGraph^q_context(IGraph,Q,QC), QCs), InvGraph). 17 | 18 | q_context(InsideG, QBetaQ, qc(Pe,P)) :- 19 | member(soln(P,_,Expls), InsideG), 20 | member(Expl-Pe, Expls), 21 | member(QBetaQ, Expl). 22 | 23 | -------------------------------------------------------------------------------- /genutils/prolog/ccreader.pl: -------------------------------------------------------------------------------- 1 | :- module(ccreader, [ run_reader/3, ask/2 ]). 2 | 3 | /** Essentially, direct style reader monad. 4 | 5 | */ 6 | :- use_module(library(delimcc), [p_reset/3, p_shift/2]). 7 | 8 | :- set_prolog_flag(generate_debug_info, false). 9 | 10 | ask(Pr,X) :- p_shift(Pr,X). 11 | 12 | :- meta_predicate run_reader(+,0,?). 13 | 14 | %% run_reader(+Pr:prompt, +P:pred, X:A) is det. 15 | % Run P in an context that allows read/2 to be used to access X. 16 | run_reader(Prompt, Goal, X) :- 17 | p_reset(Prompt, Goal, Status), 18 | cont_reader(Status, Prompt, X). 19 | 20 | cont_reader(done,_,_). 21 | cont_reader(susp(X,Cont), Prompt, X) :- run_reader(Prompt, Cont, X). 22 | 23 | -------------------------------------------------------------------------------- /genutils/prolog/hostname.pl: -------------------------------------------------------------------------------- 1 | :- module(hostname, [hostname/1]). 2 | /** Get hostname 3 | 4 | This module provides just one predicate to access the machine hostname. 5 | It first looks in the HOSTNAME environment variable. If this is unsuccessful, 6 | it call the system hostname command once and keeps the result for reuse. 7 | 8 | TODO: what happens if the calling hostname fails? 9 | */ 10 | 11 | user:term_expansion(hostname(_),hostname(H)) :- 12 | ( getenv('HOSTNAME',H) -> true 13 | ; setup_call_cleanup(open(pipe('hostname -s'),read,S), 14 | read_line_to_codes(S,Codes), 15 | close(S)), 16 | atom_codes(H,Codes) 17 | ), 18 | debug(hostname, 'Found hostname: "~w"', [H]). 19 | 20 | hostname(_). 21 | -------------------------------------------------------------------------------- /pldb/prolog/pldb_sqlite.pl: -------------------------------------------------------------------------------- 1 | :- module(pldb_sqlite,[]). 2 | 3 | :- use_module(library(prosqlite)). 4 | :- use_module(library(pldb_core)). 5 | 6 | pldb:dbh_connect(sqlite(File,Opts),sqlite(Con)) :- sqlite_connect(File,Con,[ext('')|Opts]). 7 | pldb:dbh_disconnect(sqlite(Con)) :- sqlite_disconnect(Con). 8 | pldb:dbh_table(sqlite(Con),Table) :- sqlite_current_table(Con,Table). 9 | pldb:dbh_table_column(sqlite(Con),Table,Col,Type) :- sqlite_table_column(Con,Table,Col,data_type(N)), downcase_atom(N,Type). 10 | pldb:dbh_query_affected(sqlite(Con),Statement,N) :- sqlite_query(Con,Statement,row(N)). 11 | pldb:dbh_query_row(sqlite(Con),Statement,Row) :- sqlite_query(Con,Statement,Row). 12 | pldb:dbh_query_all(sqlite(Con),Statement,Rows) :- findall(Row, sqlite_query(Con,Statement,Row), Rows). 13 | -------------------------------------------------------------------------------- /template/prolog/template.pl: -------------------------------------------------------------------------------- 1 | /* Part of template 2 | Copyright 2015 Samer Abdallah 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | -------------------------------------------------------------------------------- /callgraph/examples/test.pl: -------------------------------------------------------------------------------- 1 | :- use_module(library(callgraph)). 2 | 3 | /* 4 | Use these to test callgraph. 5 | */ 6 | 7 | 8 | %% test_pdf is det. 9 | % Writes callgraph.pdf in the current directry. 10 | test_pdf :- 11 | module_dotpdf(callgraph,[method(unflatten([fl(4),c(4)]))]). 12 | 13 | %% test_dot is det. 14 | % Writes callgraph.dot in the current directry. 15 | test_dot :- 16 | module_dot(callgraph,[]). 17 | 18 | test_multi :- 19 | modules_dotpdf([callgraph,dot],[method(unflatten([fl(4),c(4)]))],callgraph_dot). 20 | 21 | %% test_xdot is det. 22 | % Writes callgraph.dot in the current directry and then 23 | % calls xdot to display it. Will bork if xdot not present. 24 | % Pack gvterm includes xdot, but you should probably get the 25 | % latest version from http://code.google.com/p/jrfonseca/wiki/XDot 26 | test_xdot :- 27 | test_dot, 28 | shell('xdot callgraph.dot'). 29 | -------------------------------------------------------------------------------- /cclab/prolog/ccbeam/README.md: -------------------------------------------------------------------------------- 1 | This directory contains implementations which use beam search to explore 2 | the results of memoisied probabilistic effects. This is in contrast 3 | with cclazy which produces a lazy search tree, and cctab, which runs an 4 | exhaustive search. 5 | 6 | One approach to a beam or agenda based search would be to take the lazy 7 | search tree and go through expanding nodes, adding them to the agenda a 8 | 'threads', and choosing the next thread to explore based on some priority 9 | based policy. 10 | 11 | Another is to skip the lazy tree and add new threads to the agenda as 12 | soon as they are created - that's the plan here. 13 | 14 | ccbeam1 - priority queue with no memoisation 15 | ccbeam2 - with memoisation of binary predicates, no limit on number of threads 16 | ccbeam3 - memoisation of any arity goal 17 | ccbeam4 - using Prolog nondeterminism instead of dist/fail_ 18 | -------------------------------------------------------------------------------- /genutils/prolog/ccenv.pl: -------------------------------------------------------------------------------- 1 | :- module(ccenv, [ run_env/1, env_new/2, env_get/2, env_set/2, env_app/2, env_upd/3 ]). 2 | /** Delimited context providing environment with mutable name-value map */ 3 | 4 | :- use_module(library(data/env), [init_env//0, get_key//2, set_key//2, upd_key//3]). 5 | :- use_module(library(ccstate), [run_state/4, app/2]). 6 | 7 | :- meta_predicate run_env(0), env_app(+,2). 8 | 9 | %% run_env(+P:pred) is det. 10 | % Run P inside a run_state/4 with the prompt set to =|env|=, providing 11 | % an environment containing mutable key-value mappings. 12 | run_env(Goal) :- 13 | init_env(_,S), 14 | run_state(env, Goal, S, _). 15 | 16 | env_new(R,X) :- app(env, ins_key(R,X)). 17 | env_get(R,X) :- app(env, get_key(R,X)). 18 | env_set(R,X) :- app(env, set_key(R,X)). 19 | env_app(R,P) :- app(env, upd_key(R,X,Y)), call(P,X,Y). 20 | env_upd(R,X,Y) :- app(env, upd_key(R,X,Y)). 21 | 22 | -------------------------------------------------------------------------------- /genutils/prolog/insist.pl: -------------------------------------------------------------------------------- 1 | :- module(insist, [insist/1,insist/2, insist/3]). 2 | /** Tools for enforcing conditions 3 | 4 | This module provides what are usually called assertions in 5 | other languages, but of course the word 'assert' is already taken 6 | in Prolog. insist/1 and insist/2 can be used to wrap any goal 7 | that is not allowed to fail. 8 | */ 9 | 10 | :- meta_predicate insist(0,:), insist(0), insist(+,0,:). 11 | 12 | insist(G) :- insist(G,failed(G)). 13 | insist(G,Ex) :- call(G) -> true; throw(Ex). 14 | insist(det,G,Ex) :- insist(G,Ex). 15 | insist(multi,G,Ex) :- call(G) *-> true; throw(Ex). 16 | 17 | user:goal_expansion(insist(G),X) :- user:goal_expansion(insist(G,failed(G)),X). 18 | user:goal_expansion(insist(G,Ex),(G->true;throw(Ex))). 19 | user:goal_expansion(insist(det,G,Ex),X) :- user:goal_expansion(insist(G,Ex),X). 20 | user:goal_expansion(insist(multi,G,Ex),(G*->true;throw(Ex))). 21 | -------------------------------------------------------------------------------- /sindice/README: -------------------------------------------------------------------------------- 1 | This package provides an interface to the Sindice semantic web search engine. 2 | 3 | ---++++ Simple usage 4 | 5 | The simplest way to use this module is to call si_with_result/5. The last 6 | argument is an ordinary Prolog goal that will be called with the 4th argument 7 | bound to the URI of a search result stored in a temporary named graph. 8 | Progress is bound to a term Current/Total which says how far through the 9 | result set we are. Multi-page result sets are managed transparently. 10 | 11 | == 12 | ?- use_module(library(sindice)). 13 | ?- si_with_result(keyword(coltrane),[],Progress,Res,si_facet(Res,Facet)). 14 | ?- si_with_result(keywords([coltrane,monk]),[fields([cache])],Progress,Res,si_facet(Res,cache(Cache))). 15 | == 16 | 17 | ---++++ Planned enhancements 18 | 19 | * A query language similar to that implemented in lucene.pl (part of the musicbrainz package). 20 | * A means to load and query the cache URL corresponding to a search result. 21 | 22 | -------------------------------------------------------------------------------- /genutils/prolog/clambda.pl: -------------------------------------------------------------------------------- 1 | :- module(clambda, [run_lambda_compiler/1, clambda/2]). 2 | /** Compiled lambdas */ 3 | :- use_module(library(delimcc), [p_reset/3, p_shift/2]). 4 | 5 | clambda(Lambda, Pred) :- p_shift(clambda, compile(Lambda,Pred)). 6 | 7 | :- meta_predicate run_lambda_compiler(0). 8 | run_lambda_compiler(Goal) :- run(Goal, []). 9 | run(Goal,Used) :- p_reset(clambda, Goal, Status), cont(Status, Used). 10 | 11 | cont(done,Used) :- maplist(retractall, Used). 12 | cont(susp(compile(lambda(Args, Body), clambda:dpred(I)), Cont), Used) :- 13 | flag(clambda, I, I+1), Head =.. [dpred, I|Args], 14 | assert(Head :- Body), run(Cont, [Head | Used]). 15 | 16 | % cclause(Head, Body) :- p_shift(clambda, compile(Head, Body)). 17 | % clambda(lambda(Args, Body), clambda:dpred(I)) :- 18 | % flag(clambda, I, I+1), Head =.. [dpred, I|Args], 19 | % cclause(Head, Body). 20 | 21 | % cont(done,Used) :- maplist(retractall, Used). 22 | % cont(susp(compile(Head, Body), Cont), Used) :- assert(Head :- Body), run(Cont, [Head | Used]). 23 | -------------------------------------------------------------------------------- /genutils/prolog/rbutils.pl: -------------------------------------------------------------------------------- 1 | :- module(rbutils, [rb_fold/4, rb_get/4, rb_upd/5, rb_app/4, rb_add/4, rb_upd_or_ins/4, rb_app_or_new/5]). 2 | :- use_module(library(rbtrees)). 3 | :- reexport(library(rbtrees)). 4 | 5 | :- meta_predicate rb_app(+,2,+,-), rb_app_or_new(+,2,1,+,-). 6 | 7 | rb_upd(K,V1,V2,T1,T2) :- rb_update(T1,K,V1,V2,T2). 8 | rb_app(K,P,T1,T2) :- rb_apply(T1,K,P,T2). 9 | rb_add(K,V,T1,T2) :- rb_insert_new(T1,K,V,T2). 10 | rb_get(K,V,T,T) :- rb_lookup(K,V,T). 11 | % rb_app_or_new(K,P,Q,T1,T2) :- rb_apply_or_create(T1,K,P,Q,T2). 12 | rb_app_or_new(K,P,Q) --> (rb_add(K,V) -> {call(Q,V)}; rb_app(K,P)). 13 | rb_upd_or_ins(K,update(V1,V2)) --> rb_upd(K,V1,V2), !. 14 | rb_upd_or_ins(K,insert(V)) --> rb_add(K,V). 15 | 16 | user:goal_expansion(rb_add(K,V,T1,T2),rb_insert_new(T1,K,V,T2)). 17 | user:goal_expansion(rb_upd(K,V1,V2,T1,T2),rb_update(T1,K,V1,V2,T2)). 18 | user:goal_expansion(rb_app(K,P,T1,T2),rb_apply(T1,K,P,T2)). 19 | user:goal_expansion(rb_get(K,V,T1,T2),(T2=T1, rb_lookup(K,V,T1))). 20 | % user:goal_expansion(rb_app_or_new(K,P,Q,T1,T2),rb_apply_or_create(T1,K,P,Q,T2)). 21 | -------------------------------------------------------------------------------- /webutils/framework/base.pl: -------------------------------------------------------------------------------- 1 | :- module(base, []). 2 | 3 | /** Enables use of Base CSS framework 4 | */ 5 | 6 | :- use_module(library(http/html_write)). 7 | :- use_module(library(http/html_head)). 8 | :- use_module(library(htmlutils)). 9 | 10 | :- set_prolog_flag(double_quote,string). 11 | 12 | user:file_search_path(base,weblib(base)). 13 | 14 | http:location( base, weblib(base), []). 15 | 16 | user:head(base(_),Head) --> !, 17 | html(head([ meta([name(viewport), content("width-device-width,initial-scale=1")]) 18 | | Head ])). 19 | 20 | user:body(base(Nav),Body) --> !, 21 | { setting(htmlutils:appname, AppName) }, 22 | use_font("Open Sans",opensans), 23 | html_requires(base('style.css')), 24 | html_requires(base('js/modernizr.js')), 25 | 26 | html(body([ div(class([row,clear,container]), 27 | [ div(class("col col-2"),[]) 28 | , div(class("col col-10"),Body) 29 | ]) 30 | ])). 31 | 32 | 33 | button_link(Ref,Content) --> 34 | html(a([class(['pure-button','pure-button-primary']),href(Ref)],Content)). 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | prolog 2 | ====== 3 | 4 | Pure Prolog libraries 5 | 6 | callgraph - Predicate dependency graph generation 7 | cclab - Playing with delimited continuations 8 | dcgutils - DCG utilities 9 | fileutils - I/O and file-system utilities 10 | genutils - Miscellaneous utilities 11 | memo - volatile and persistent memoisation of deterministic predicates. 12 | midiutils - Working with MIDI messages 13 | musicbrainz - Musicbrainz web service client 14 | musicxml - MusicXML reader 15 | plumdrum - Humdrum symbolic music format reading 16 | swipe - Shell pipeline construction 17 | sparkle - Prolog-friendly SPARQL client 18 | sindice - Sindice semantic web index client 19 | textutil - Tools for outputting text in different ways 20 | timeutils - Working with time 21 | typedef - Simple framework supporting algebraic type declarations. 22 | webutils - Web-related utilities 23 | 24 | template - template pack directory 25 | 26 | -------------------------------------------------------------------------------- /genutils/prolog/argutils.pl: -------------------------------------------------------------------------------- 1 | :- module(argutils, 2 | [ sumargs/2 3 | , addargs/3 4 | ]). 5 | 6 | sumargs(Term,Total) :- 7 | functor(Term,_,N), sumargs(N,Term,0,Total). 8 | 9 | sumargs(0,_,S,S) :- !. 10 | sumargs(N,Term,S1,S3) :- 11 | succ(M,N), arg(N,Term,X), S2 is S1+X, 12 | sumargs(M,Term,S2,S3). 13 | 14 | 15 | %% addargs( +Term, +Args, -NewTerm) is det. 16 | % 17 | % Add an extra argument to a term, eg 18 | % == 19 | % ?- addargs(spam(fish,cake),spoon,T). 20 | % T = spam(fish,cake,spoon). 21 | % true. 22 | % == 23 | addargs(Term,Args,NewTerm) :- 24 | var(NewTerm) -> 25 | (Term=..L, 26 | append(L,Args,LL), 27 | NewTerm=..LL) 28 | ; 29 | (NewTerm=..LL, 30 | append(L,Args,LL), 31 | Term=..L). 32 | 33 | % functor(S1,F,A), arg(N,S1,X1), 34 | % functor(S2,F,A), arg(N,S2,X2), 35 | % phrase(P,X1,X2), 36 | % foreach((arg(I,S1,X),I\=N), arg(I,S2,X)). 37 | 38 | % reinstatevars(Bindings,'$VAR'(Name),Var) :- member(Name=Var,Bindings), !. 39 | % reinstatevars(_,Atomic,Atomic) :- atomic(Atomic), !. 40 | % reinstatevars(Bindings,Term1,Term2) :- 41 | % Term1 =.. [F | Args1], 42 | % maplist(reinstatevars(Bindings),Args1,Args2), 43 | % Term2 =.. [F | Args2]. 44 | -------------------------------------------------------------------------------- /cclab/prolog/ccdetmem.pl: -------------------------------------------------------------------------------- 1 | :- module(ccdetmem, [memo/3, memo/2]). 2 | 3 | /** Recursive but deterministic memoisation, functional style. 4 | 5 | This module provides memoisation as an effect. It must be used inside 6 | ccstate:run_ref/1, as this provides mutable references as an effect. 7 | The predicate to be memoised must be passed to memo/2 or memo/3, which 8 | will return a metacallable term. 9 | */ 10 | 11 | :- use_module(library(ccstate), [ref_new/2, ref_get/2, ref_app/2]). 12 | 13 | :- meta_predicate memo(2,-,-). 14 | 15 | %% memo(+P:pred(+A,-B), -Q:pred(+A,-B), -D:pred(list(pair(A,B)))) is det. 16 | %% memo(+P:pred(+A,-B), -Q:pred(+A,-B)) is det. 17 | memo(P, Q) :- memo(P,Q,_). 18 | memo(P, ccdetmem:mem_call(P,R), ccdetmem:mem_dump(R)) :- 19 | empty_assoc(T), 20 | ref_new(T,R). 21 | 22 | %% mem_call(+P:pred(+A,-B), +R:ref(assoc(A,B)), +X:A, -Y:B) is det. 23 | mem_call(P,R,X,Y) :- 24 | ref_get(R,Tab), 25 | ( get_assoc(X,Tab,Y) -> true 26 | ; call(P,X,Y), 27 | ref_app(R,tab_add(X,Y)) 28 | ). 29 | 30 | %% mem_dump(+R:ref(assoc(A,B)), -Pairs:list(pair(A,B))) is det. 31 | mem_dump(R,Pairs) :- 32 | ref_get(R,Tab), 33 | assoc_to_list(Tab,Pairs). 34 | 35 | tab_add(K,V,T1,T2) :- put_assoc(K,T1,V,T2). 36 | -------------------------------------------------------------------------------- /swipe/README: -------------------------------------------------------------------------------- 1 | This package provides a mechanism for construction Unix shell 2 | pipelines by the composition of terms representing primitive Unix 3 | processes. Each process is given a type and the compositon mechanism 4 | checks that the types of processes combined in to a pipeline match 5 | correctly 6 | 7 | ---+++ Simple usage 8 | 9 | == 10 | :- use_module(library(swipe)). 11 | 12 | % define grep as a command taking a stream of T to a stream of T. 13 | % Argument specified with @/1, so will be escaped properly for bash. 14 | swipe:def(grep(Pattern), sh($T >> $T,"grep ~s",[@Pattern])). 15 | 16 | % define sort with type stream of T to stream of T 17 | swipe:def(sort, sh($T >> $T,"sort")). 18 | 19 | % pipe contents from file spec =|library('swipe.pl')|= (ie using 20 | % file search path mechanism) as type =|pl|= into grep and sort, 21 | % with output to stdout. 22 | :- run(library('swipe.pl')^pl :> grep(module) >> sort). 23 | == 24 | 25 | ---+++ Change history 26 | 27 | ---++++ Version 0.1.0 28 | 29 | * Changed pipe/2 to command/2. 30 | * Added command/3 to return the inferred type of a pipeline. 31 | * Added with_pipe_output/3 and with_pipe_input/3. 32 | * Now depends on fileutils pack. 33 | 34 | ---++++ Version 0.2.0 35 | 36 | * Moved with_temp_dir/2 to fileutils pack. 37 | -------------------------------------------------------------------------------- /pldb/prolog/pldb_postgres.pl: -------------------------------------------------------------------------------- 1 | :- module(pldb_postgres,[]). 2 | 3 | :- use_module(library(dcg_core)). 4 | :- use_module(library(dcg_codes)). 5 | 6 | :- multifile pldb:typed_value, pldb:type_decode/3. 7 | 8 | pldb:typed_value(T,V) --> {is_geometric(T)}, !, "'",geo(T,V),"'". 9 | 10 | pldb:type_decode(F,X,P) :- is_geometric(F), !, atom_codes(X,C), phrase(geo(F,P),C,[]). 11 | 12 | geo( point, point(A,B)) --> paren((pldb:float(A), comma, pldb:float(B))). 13 | geo( lseg, linesegment(P1,P2)) --> paren(( geo(point,P1), comma, geo(point,P2))). 14 | geo( lseg, line(P1,P2)) --> sqbr(((geo(point,P1), comma, geo(point,P2)))). 15 | geo( line, line(P1,P2)) --> sqbr(((geo(point,P1), comma, geo(point,P2)))). 16 | geo( box, box(P1,P2)) --> geo(point,P1), comma, geo(point,P2). 17 | geo( circle, circle(P,R)) --> "<", geo(point,P), comma, pldb:float(R), ">". 18 | geo( path, path(closed,PX)) --> paren(seqmap_with_sep(comma, geo(point), PX)). 19 | geo( path, path(open,PX)) --> sqbr(seqmap_with_sep(comma, geo(point), PX)). 20 | geo( polygon, polygon(PX)) --> paren(seqmap_with_sep(comma, geo(point), PX)). 21 | 22 | is_geometric(point). 23 | is_geometric(lseg). 24 | is_geometric(path). 25 | is_geometric(box). 26 | is_geometric(circle). 27 | is_geometric(polygon). 28 | is_geometric(line). 29 | 30 | -------------------------------------------------------------------------------- /cclab/prolog/cclistm.pl: -------------------------------------------------------------------------------- 1 | :- module(cclistm, [run_list/2, choose/2]). 2 | /** Nondeterminism as list monad 3 | Provides nondeterministic choice as an effect using delimited 4 | continuations. The nondeterministic computation is refied as a 5 | list of possible answers, like the Haskell List monad. 6 | 7 | Use run_list/{1,2} to bracket a computation and use choose/2 (not 8 | Prolog nondeterministic constructs!) to make a nondeterministic choice. 9 | */ 10 | 11 | :- use_module(library(delimcc)). 12 | :- use_module(library(lambda1)). 13 | 14 | :- meta_predicate run_list(1,-), run_list(1,-,?). 15 | 16 | %% run_list(+P:pred(-A), -X1:list(A)) is det. 17 | %% run_list(+P:pred(-A), X1:list(A), X2:list(A)) is det. 18 | % Calls unary predicate P in a context where choose/2 provides 19 | % nondeterministic choice as an effect. run_list/3 produces 20 | % results as a difference list. 21 | run_list(P,Xs) :- run_list(P,Xs,[]). 22 | run_list(P) --> 23 | {p_reset(nondet, call(P, X), Status)}, 24 | cont_list(Status, X). 25 | 26 | cont_list(done, X) --> [X]. 27 | cont_list(susp(Ys-Y, Cont), X) --> foldl(expand1(\Y^X^Cont), Ys). 28 | 29 | expand1(K, Y) --> run_list(call(K, Y)). 30 | 31 | %% choose(+Ys:list(A), -Y:A) is det. 32 | % Nondeterministic choice as a control effect, not as Prolog nondeterminism. 33 | choose(Ys,Y) :- p_shift(nondet, Ys-Y). 34 | -------------------------------------------------------------------------------- /dcgutils/README: -------------------------------------------------------------------------------- 1 | This package provides DCG related utilities. 2 | It is organised into several modules: 3 | 4 | * library(dcg_core) 5 | Provides predicates which can be used in DCGs where the threaded 6 | state variable can be of any type, not just lists of terminals as 7 | with applications to grammars in the linguistic sense. 8 | * library(dcg_codes) 9 | Utilities for DCGs over sequences of character codes, ie, grammars 10 | in the linguistic sense. Note that only some of these can be used 11 | for both parsing and generation. The rules for writing Prolog values 12 | of various types can only be used for generation. 13 | * library(dcg_macros) 14 | Provides goal expansions for some of the mapping predicates in 15 | library(dcg_core), similar to those in library(apply_macros). 16 | * library(dcg_progress) 17 | Sequencing predicates that show progress information, for slow-running 18 | processes on sequences. 19 | * library(dcg_pair) 20 | Operators for working with DCGs over pair states. 21 | * library(dcg_shell) 22 | Provides a top-level read-eval-print loop similar to the Prolog top-level, 23 | but for running DCG goals and managing the current 'state'. 24 | * library(snobol) 25 | A collection of SNOBOL inspired pattern matching predicates. 26 | 27 | ---++++ Prerequisites 28 | 29 | SWI Prolog version at least 7.1.18 to get call_dcg/3. 30 | 31 | ---++++ Simple usage 32 | 33 | ---++++ Planned enhancements 34 | 35 | -------------------------------------------------------------------------------- /musicxml/prolog/mxml_portray.pl: -------------------------------------------------------------------------------- 1 | :- module(mxml_portray, []). 2 | /** Provides pretty portrayal of notes and chords 3 | 4 | Chords are portrayed as Root Triad [Extensions] [/Bass]. 5 | Alterables (ie things that can have sharps and flats) get nice Unicode sharps and flats. 6 | */ 7 | 8 | :- use_module(library(listutils), [rep/3]). 9 | :- use_module(library(mxml_chords), [ triad/1, ivals/3 ]). 10 | 11 | user:portray(a(N,A)) :- 12 | integer(A), atomic(N), 13 | accidentals(A,Chars,Sep), 14 | ( number(N) 15 | -> format('~s~w~w', [Chars,Sep,N]) 16 | ; format('~w~s', [N,Chars]) 17 | ). 18 | 19 | user:portray(chord(R,B,Is)) :- 20 | ivals(Triad, Is, Exts), triad(Triad), !, 21 | format('~p ~w', [R,Triad]), 22 | maplist(space_print, Exts), 23 | ( R=B -> true 24 | ; write('/'), print(B) 25 | ). 26 | 27 | space_print(X) :- format(' ~p',[X]). 28 | 29 | bip(N,N,sharp) :- N>0. 30 | bip(N,M,flat) :- N<0, M is -N. 31 | 32 | accidentals(0, [], ''). 33 | accidentals(N, Chars, ' ') :- bip(N,M,S), sign(S,C), rep(M,C,Chars). 34 | 35 | sign(ascii, sharp, #). 36 | sign(ascii, flat, b). 37 | sign(uni, sharp, ♯). 38 | sign(uni, flat, ♭). 39 | sign(uni, natural, ♮). 40 | sign(uni, double_flat, 𝄫). 41 | sign(uni, double_sharp, 𝄪). 42 | sign(uni, crotchet, ♩). 43 | sign(uni, quaver, ♪). 44 | sign(uni, two_quavers, ♫). 45 | sign(uni, two_semiquavers, ♬). 46 | 47 | sign(Name,Char) :- sign(uni,Name,Char). 48 | -------------------------------------------------------------------------------- /pldb/prolog/pldb_odbc.pl: -------------------------------------------------------------------------------- 1 | :- module(pldb_odbc,[]). 2 | 3 | :- use_module(library(odbc)). 4 | :- use_module(library(pldb_core)). 5 | 6 | pldb:dbh_connect(odbc(DSN,Opts),odbc(Con)) :- odbc_connect(DSN,Con,Opts). 7 | pldb:dbh_disconnect(odbc(Con)) :- odbc_disconnect(Con). 8 | pldb:dbh_table(odbc(Con),Table) :- odbc_current_table(Con,Table). 9 | pldb:dbh_query_row(odbc(Con),Statement,Row) :- odbc_query(Con,Statement,Row). 10 | pldb:dbh_query_all(odbc(Con),Statement,Results) :- odbc_query(Con,Statement,Results,[findall(Row,Row)]). 11 | pldb:dbh_query_affected(odbc(Con),Statement,N) :- odbc_query(Con,Statement,affected(N)). 12 | % pldb:dbh_table_column(odbc(Con),Table,Col,Type) :- odbc_table_column(Con,Table,Col,type(Type)). 13 | pldb:dbh_table_column(odbc(Con),Table,Col,Type) :- 14 | odbc_get_connection(Con,dbms_name(DBMS)), 15 | odbc:table_column(Con,Table,Col,Info), 16 | arg(6,Info,TypeName), 17 | ( dbms_sql_type(DBMS,TypeName,Info,Type) -> true 18 | ; odbc:sql_type(TypeName,Info,Type) 19 | ). 20 | 21 | dbms_sql_type('SQLite', TypeName,_, Type) :- downcase_atom(TypeName,X), atom_to_term(X,Type,[]). 22 | dbms_sql_type('PostgreSQL', bpchar, Info, char(N)) :- odbc:column_facet(precision(N),Info). 23 | dbms_sql_type(_, varchar, Info, varchar(N)) :- odbc:column_facet(precision(N),Info). 24 | dbms_sql_type(_, char, Info, char(N)) :- odbc:column_facet(precision(N),Info). 25 | 26 | -------------------------------------------------------------------------------- /cclab/prolog/cctab/cctab3.pl: -------------------------------------------------------------------------------- 1 | :- module(cctab, [run_tabled/1, cctabled/1]). 2 | 3 | :- use_module(library(delimcc), [pr_reset/3, pr_shift/2]). 4 | :- use_module(library(ccstate), [run_nb_state/3, set/1, get/1]). 5 | :- use_module(library(lambda1)). 6 | :- use_module(tabled, []). 7 | 8 | head_to_variant(Head, Variant) :- 9 | copy_term_nat(Head, Variant), 10 | numbervars(Variant, 0, _). 11 | 12 | :- meta_predicate cctabled(0). 13 | cctabled(Head) :- pr_shift(tab, handler(Head)). 14 | 15 | handler(Head, K, Ans) :- 16 | term_variables(Head,Y), KY= \Y^K, 17 | get(Tabs1), 18 | head_to_variant(Head, Variant), 19 | ( rb_update(Tabs1, Variant, tab(Solns,Ks), tab(Solns,[KY|Ks]), Tabs2) 20 | -> set(Tabs2), 21 | member(Y, Solns), 22 | call(K, Ans) 23 | ; rb_insert_new(Tabs1, Variant, tab([],[]), Tabs2), 24 | set(Tabs2), 25 | producer(Variant, \Y^Head, KY, Ans) 26 | ). 27 | 28 | producer(Variant, Generate, KP, Ans) :- 29 | call(Generate, Y1), 30 | get(Tabs1), 31 | rb_update(Tabs1, Variant, tab(Solns1, Ks), tab(Solns2, Ks), Tabs2), 32 | \+member(Y1, Solns1), Solns2 = [Y1|Solns1], 33 | set(Tabs2), 34 | member(K,[KP|Ks]), 35 | call(K,Y1,Ans). 36 | 37 | :- meta_predicate run_tabled(0), run_tabled(0,-). 38 | run_tabled(Goal) :- run_tabled(Goal,_). 39 | run_tabled(Goal, FinalTables) :- 40 | rb_empty(Tables), 41 | term_variables(Goal, Ans), 42 | run_nb_state(pr_reset(tab, \Ans^Goal, Ans), Tables, FinalTables). 43 | 44 | -------------------------------------------------------------------------------- /cclab/prolog/ccdcg.pl: -------------------------------------------------------------------------------- 1 | :- module(ccdcg, [run_dcg/3, run_prefix/2]). 2 | /* Playing with continuation based DCGs 3 | */ 4 | :- use_module(library(delimcc)). 5 | 6 | run_dcg(P) --> 7 | {p_reset(prefix, P, Status)}, 8 | cont_dcg(Status). 9 | 10 | cont_dcg(done) --> []. 11 | cont_dcg(susp(match(X),K)) --> [X], run_dcg(K). 12 | 13 | run_prefix(_,[]) :- !. 14 | run_prefix(P,L) :- 15 | p_reset(prefix, P, Status), 16 | cont_prefix(Status,L). 17 | 18 | cont_prefix(done,[]). 19 | cont_prefix(susp(match(X),K),[X|T]) :- run_prefix(K,T). 20 | 21 | :- meta_predicate +(2). 22 | +Lab :- call(Lab,Vals,[]), member(T,Vals), p_shift(prefix,match(T)). 23 | 24 | % grammars using match/1 effect 25 | % No left recursion! 26 | 27 | s :- np, vp. 28 | 29 | np :- +d, nom 30 | % ; np, pp 31 | ; +pn. 32 | 33 | vp :- +iv 34 | ; +tv, np 35 | ; +dv, np, np 36 | % ; vp, pp 37 | ; +mv, s. 38 | 39 | nom :- +n 40 | ; +adj, nom. 41 | 42 | pp :- +p, np. 43 | 44 | % specify preterminals as DCG that spits out alternatives 45 | user:term_expansion(Lab | Body, Clause) :- 46 | dcg_translate_rule(Lab --> Body, Clause). 47 | 48 | % preterminal declarations 49 | adj | [hot,cold,thin,fat,disgusting,lovely]. 50 | pn | [alice, bob, cuthbert, delia, edna]. 51 | d | [the,a,some,my]. % ,every,no]. 52 | mv | [knew,thought,believed,said]. 53 | dv | [gave,made,baked]. 54 | tv | [saw, ate, hated, baked, liked, walked, ran, loved, caught]. 55 | iv | [lived, worked]. 56 | n | [dog,telescope,man,cat,mat,cake,box,floor,face,pie,moose,pyjamas,park]. 57 | p | [with,on,under,in,without,by]. 58 | -------------------------------------------------------------------------------- /cclab/prolog/ccmacros.pl: -------------------------------------------------------------------------------- 1 | :- module(ccmacros, [op(1150,fx,cctable)]). 2 | /** Term expansions to support tabling 3 | 4 | This module implements a shallow program transformation to support 5 | tabling. Predicates decalared `cctabled` are renamed (by a appending 6 | a '#' to their given name) and the original predicate name defined 7 | as a metacall of the renamed predicate via cctable/1, which is 8 | assumed to be available in the module where the tabled precicate 9 | is defined. 10 | */ 11 | 12 | :- op(1150,fx,cctable). 13 | 14 | %% cctable(PredSpecfiers) is det 15 | % Declare predicates in PredSpecifiers (a comma separated list of Name/Arity 16 | % predicate specifier) as tabled. 17 | system:term_expansion((:- cctable(Specs)), Clauses) :- 18 | foldl_clist(expand_cctab, Specs, Clauses, []). 19 | 20 | foldl_clist(P,(A,B)) --> !, call(P,A), foldl_clist(P,B). 21 | foldl_clist(P,A) --> call(P,A). 22 | 23 | expand_cctab(Name//Arity) --> !, 24 | {A2 is Arity+2}, 25 | expand_cctab(Name/A2). 26 | expand_cctab(Name/Arity) --> 27 | { functor(Head, Name, Arity), head_worker(Head, Worker)}, 28 | [ (:- discontiguous('$cctabled'/1)) 29 | , '$cctabled'(Head) 30 | , (Head :- cctabled(Worker)) 31 | ]. 32 | 33 | prolog:rename_predicate(M:Head, M:Worker) :- 34 | '$flushed_predicate'(M:'$cctabled'(_)), 35 | call(M:'$cctabled'(Head)), !, 36 | head_worker(Head, Worker). 37 | 38 | head_worker(Head, Worker) :- 39 | Head =.. [H|As], atom_concat(H,'#',W), 40 | Worker =.. [W|As]. 41 | 42 | % work around for broken rb_in/3 43 | cctab:goal_expansion(rb_in(K,V,T), (rbtrees:rb_in(KK,V,T),K=KK)). 44 | -------------------------------------------------------------------------------- /cclab/prolog/ccmacros2.pl: -------------------------------------------------------------------------------- 1 | :- module(ccmacros, [op(1150,fx,cctable)]). 2 | /** Term expansions to support tabling 3 | 4 | This module implements a shallow program transformation to support 5 | tabling. Predicates decalared `cctabled` are renamed (by a appending 6 | a '#' to their given name) and the original predicate name defined 7 | as a metacall of the renamed predicate via cctable/1, which is 8 | assumed to be available in the module where the tabled precicate 9 | is defined. 10 | */ 11 | 12 | :- op(1150,fx,cctable). 13 | 14 | %% cctable(PredSpecfiers) is det 15 | % Declare predicates in PredSpecifiers (a comma separated list of Name/Arity 16 | % predicate specifier) as tabled. 17 | system:term_expansion((:- cctable(Specs)), Clauses) :- 18 | foldl_clist(expand_cctab, Specs, Clauses, []). 19 | 20 | foldl_clist(P,(A,B)) --> !, call(P,A), foldl_clist(P,B). 21 | foldl_clist(P,A) --> call(P,A). 22 | 23 | expand_cctab(Name//Arity) --> !, 24 | {A2 is Arity+2}, 25 | expand_cctab(Name/A2). 26 | expand_cctab(Name/Arity) --> 27 | { functor(Head, Name, Arity), head_worker(Head, Worker)}, 28 | [ (:- discontiguous('$cctabled'/1)) 29 | , '$cctabled'(Head) 30 | , (Head :- cctabled(Head,Worker)) 31 | ]. 32 | 33 | prolog:rename_predicate(M:Head, M:Worker) :- 34 | '$flushed_predicate'(M:'$cctabled'(_)), 35 | call(M:'$cctabled'(Head)), !, 36 | head_worker(Head, Worker). 37 | 38 | head_worker(Head, Worker) :- 39 | Head =.. [H|As], atom_concat(H,'#',W), 40 | Worker =.. [W|As]. 41 | 42 | % work around for broken rb_in/3 43 | cctab:goal_expansion(rb_in(K,V,T), (rbtrees:rb_in(KK,V,T),K=KK)). 44 | -------------------------------------------------------------------------------- /genutils/prolog/ccref.pl: -------------------------------------------------------------------------------- 1 | :- module(ccref, [ run_ref/1, ref_new/2, ref_get/2, ref_set/2, ref_app/2, ref_app_ref/2, ref_maybe_app_ref/2, ref_upd/3 ]). 2 | /** Delimited context providing mutable references */ 3 | 4 | :- use_module(library(ccstate), [run_state/4, app/2]). 5 | :- use_module(library(data/store)). 6 | 7 | :- meta_predicate run_ref(0), ref_app(+,2), ref_app_ref(+,2), ref_maybe_app_ref(+,2). 8 | 9 | %% run_ref(+P:pred) is det. 10 | % Run P inside a run_state/4 with the prompt set to =|ref|=, providing 11 | % a supply of mutable references using ref_new/2, ref_get/2, ref_set/3 etc. 12 | run_ref(Goal) :- 13 | store_new(S), 14 | run_state(ref, Goal, S, _). 15 | 16 | ref_new(X,R) :- app(ref, store_add(X,R)). 17 | ref_get(R,X) :- app(ref, store_get(R,X)). 18 | ref_set(R,X) :- app(ref, store_set(R,X)). 19 | ref_app(R,P) :- app(ref, store_apply(R,P)). 20 | ref_upd(R,X,Y) :- app(ref, store_upd(R,X,Y)). 21 | 22 | %! ref_app_ref(+R:ref(A), +P:pred(+A,-P)) is det. 23 | % Use P to update contents of R, like ref_app/2, but with 24 | % references still available as a computational effect. 25 | ref_app_ref(R,P) :- app(ref, lifted_app(R,P)). 26 | 27 | lifted_app(R,P) --> 28 | store_get(R,X1), 29 | run_state(ref, call(P,X1,X2)), 30 | store_set(R,X2). 31 | 32 | %! ref_maybe_app_ref(+R:ref(A), +P:pred(+A,-maybe(A))) is det. 33 | % Call P with contents of R, with references still in context, 34 | % possibly updating R with a new value. 35 | ref_maybe_app_ref(R,P) :- app(ref, lifted_app_maybe(R,P)). 36 | 37 | lifted_app_maybe(R,P) --> 38 | store_get(R,X1), 39 | run_state(ref, call(P,X1,MX2)), 40 | ({MX2 = just(X2)} -> store_set(R,X2); []). 41 | -------------------------------------------------------------------------------- /Makefile.inc: -------------------------------------------------------------------------------- 1 | # This is a Makefile INCLUDE - it assumes that the variable PACKNAME is defined 2 | # 3 | # It also assumes that the current directory contains a file called VERSION 4 | # containing just the current version of the pack. 5 | # 6 | # It also assumes that there is a file called pack.pl with placeholders for 7 | # the version and package name. 8 | 9 | VER=$(shell cat VERSION) 10 | EMAIL=samer.abdallah.00@gmail.com 11 | PACKFILE=release/$(PACKNAME)-$(VER).tgz 12 | EPACKFILE=release\/$(PACKNAME)-$(VER).tgz 13 | ZIPFILE=release/$(PACKNAME)-$(VER).zip 14 | DOWNLOAD=https:\/\/raw.githubusercontent.com\/samer--\/prolog\/master\/$(PACKNAME)\/$(EPACKFILE) 15 | 16 | main: 17 | 18 | packdir: 19 | mkdir -p $(PACKNAME) $(PACKNAME)/prolog 20 | sed -e "s//$(VER)/g" < pack.pl | sed -e "s//$(EMAIL)/g" | sed -e "s//$(PACKNAME)/g" | sed -e "s//$(DOWNLOAD)/g" > $(PACKNAME)/pack.pl 21 | rsync -ar --delete --exclude '.*' prolog $(PACKNAME) 22 | cp -p README $(PACKNAME) 23 | cp -p ../COPYING* $(PACKNAME) 24 | 25 | pack: packdir 26 | COPYFILE_DISABLE=1 tar czf $(PACKFILE) $(PACKNAME) 27 | rm -rf $(PACKNAME) 28 | git add $(PACKFILE) 29 | 30 | zip: packdir 31 | zip -r $(ZIPFILE) $(PACKNAME) 32 | rm -rf $(PACKNAME) 33 | git add $(ZIPFILE) 34 | 35 | push: 36 | git push 37 | 38 | install: 39 | swipl -g "pack_install('$(PACKFILE)',[upgrade(true),interactive(false)]), halt" 40 | 41 | install-git: 42 | (git commit $(PACKFILE) || echo 'Local up to date') && (git push || echo 'Remote up to date') 43 | swipl -g "pack_property($(PACKNAME),download(D)), pack_install(D,[upgrade(true),interactive(false)]), halt" 44 | chmod -w $(PACKFILE) 45 | 46 | dist-clean: 47 | -------------------------------------------------------------------------------- /cclab/prolog/cctab/cctab2.pl: -------------------------------------------------------------------------------- 1 | :- module(cctab, [run_tabled/1, run_tabled/2, cctabled/1]). 2 | 3 | :- use_module(library(delimcc), [p_reset/3, p_shift/2]). 4 | :- use_module(library(ccstate), [run_nb_state/3, set/1, get/1]). 5 | :- use_module(library(rbutils)). 6 | :- use_module(library(lambda1)). 7 | :- use_module(tabled, []). 8 | 9 | head_to_variant(Head, Variant) :- 10 | copy_term_nat(Head, Variant), 11 | numbervars(Variant, 0, _). 12 | 13 | :- meta_predicate cctabled(0). 14 | cctabled(Head) :- p_shift(tab, Head). 15 | 16 | run_tab(Goal, Ans) :- 17 | p_reset(tab, Goal, Status), 18 | cont_tab(Status, Ans). 19 | 20 | cont_tab(done, _). 21 | cont_tab(susp(Head, Cont), Ans) :- 22 | term_variables(Head,Y), K= \Y^Ans^Cont, 23 | get(Tabs1), 24 | head_to_variant(Head, Variant), 25 | ( rb_update(Tabs1, Variant, tab(Solns,Ks), tab(Solns,[K|Ks]), Tabs2) 26 | -> set(Tabs2), 27 | rb_in(Y, _, Solns), 28 | run_tab(Cont, Ans) 29 | ; rb_empty(Solns), 30 | rb_insert_new(Tabs1, Variant, tab(Solns,[]), Tabs2), 31 | set(Tabs2), 32 | run_tab(producer(Variant, \Y^Head, K, Ans), Ans) 33 | ). 34 | 35 | producer(Variant, Generate, KP, Ans) :- 36 | call(Generate, Y1), 37 | get(Tabs1), 38 | rb_update(Tabs1, Variant, tab(Solns1, Ks), tab(Solns2, Ks), Tabs2), 39 | rb_insert_new(Solns1, Y1, t, Solns2), 40 | set(Tabs2), 41 | member(K,[KP|Ks]), 42 | call(K,Y1,Ans). 43 | 44 | :- meta_predicate run_tabled(0), run_tabled(0,-). 45 | run_tabled(Goal) :- run_tabled(Goal,_). 46 | run_tabled(Goal, FinalTables) :- 47 | rb_empty(Tables), 48 | term_variables(Goal, Ans), 49 | run_nb_state(run_tab(Goal, Ans), Tables, FinalTables). 50 | 51 | -------------------------------------------------------------------------------- /cclab/prolog/ccbeam/ccbeam1.pl: -------------------------------------------------------------------------------- 1 | :- module(ccbeam, [memo_prob/2, lazy_beam/2, dist/2, fail_/0]). 2 | 3 | /** Probabilistic choice with beam search to find most probable paths 4 | 5 | Simple beam search using a priority queue to manage threads. 6 | Without memoisation - nonterminating for left-recursive predicates. 7 | */ 8 | 9 | :- use_module(library(typedef)). 10 | :- use_module(library(lazy), [lazy_unfold_finite//2]). 11 | :- use_module(library(delimcc), [p_reset/3, p_shift/2]). 12 | :- use_module(library(lambda2)). 13 | :- use_module(pack(pha/prolog/library/priorityq)). 14 | 15 | :- set_prolog_flag(back_quotes, symbol_char). 16 | 17 | :- type weighted(A) ---> number - A. 18 | :- type dist(A) == list(weighted(A)). 19 | 20 | :- meta_predicate memo_prob(2,-). 21 | memo_prob(P,P). 22 | 23 | dist(Xs,X) :- p_shift(beam, dist(Xs,X)). 24 | fail_ :- p_shift(beam, dist([],_)). 25 | 26 | :- meta_predicate lazy_beam(1,-). 27 | lazy_beam(Pred,Stream) :- 28 | proc_init(1,Pred,PQ1), 29 | lazy_unfold_finite(run_beam,Stream,PQ1,_). 30 | 31 | run_beam(Ans) --> 32 | proc_remove(P, Thread), 33 | {p_reset(beam, call(Thread,Y), Status)}, 34 | cont_beam(Status, P-Y, Ans). 35 | 36 | cont_beam(done, PrX, PrX) --> []. 37 | cont_beam(susp(dist(Xs,X), Cont), Pr-Y, Ans) --> 38 | foldl(insert(0.9-10, \\X`Y`Cont, Pr), Xs), 39 | run_beam(Ans). 40 | 41 | insert(Thresh-Max, K, P0, P-X) --> 42 | proc_stats(T,N), 43 | ( {T>Thresh, N>=Max} -> {debug(ccbeam, 'Agenda is full (N=~w, T=~w)', [N,T])} 44 | ; {P1 is P0*P}, proc_insert(P1,call(K,X)) 45 | ). 46 | 47 | proc_init(P,T,P-PQ1) :- pq_empty(PQ0), pq_insert(P,T,PQ0,PQ1). 48 | proc_insert(P,Th,T1-Q1,T2-Q2) :- pq_insert(P,Th,Q1,Q2), T2 is T1+P. 49 | proc_remove(P,Th,T1-Q1,T2-Q2) :- pq_remove(P,Th,Q1,Q2), T2 is T1-P. 50 | proc_empty(_-Q) :- pq_empty(Q). 51 | proc_stats(T,S,T-Q,T-Q) :- pq_size(Q,S). 52 | 53 | -------------------------------------------------------------------------------- /textutils/prolog/tconsole.pl: -------------------------------------------------------------------------------- 1 | :- module(tconsole, 2 | [ open_output_console/1 3 | , close_output_console/1 4 | , ensure_output_console/0 5 | , output_console/1 6 | , con/1 7 | , con_exec/2 8 | , con_push/2 9 | , con_pop/1 10 | ]). 11 | 12 | :- use_module(library(threadutil)). 13 | 14 | :- dynamic output_console/1. 15 | 16 | :- meta_predicate con_exec(+,0). 17 | :- meta_predicate con_push(+,0). 18 | :- meta_predicate con(0). 19 | 20 | ensure_output_console :- output_console(_) -> true; open_output_console(_). 21 | 22 | open_output_console(Q) :- 23 | thread_create(output_console_main,Q,[detached(false)]). 24 | 25 | close_output_console(Q) :- 26 | output_console(Q), !, 27 | thread_send_message(Q,quit), 28 | thread_join(Q,_). 29 | 30 | con(G) :- output_console(Q), !, con_exec(Q,G). 31 | con_exec(Q,G) :- context_module(M), thread_send_message(Q,exec(M:G)). 32 | con_push(Q,G) :- context_module(M), thread_send_message(Q,push(M:G)). 33 | con_pop(Q) :- thread_send_message(Q,pop). 34 | 35 | output_console_main :- 36 | attach_console, 37 | thread_self(Id), 38 | setup_call_cleanup( 39 | asserta(output_console(Id)), 40 | output_console_loop(true), 41 | retract(output_console(Id))). 42 | 43 | output_console_loop(Pref) :- 44 | thread_get_message(Msg), 45 | ( Msg=quit -> true 46 | ; catch( 47 | (output_console_handle(Msg,Pref,Pref1) ->true;Pref1=Pref), 48 | Ex, (print_message(error,Ex), Pref1=Pref) 49 | ), 50 | output_console_loop(Pref1) 51 | ). 52 | 53 | output_console_handle(exec(G),P,P) :- P, G. 54 | output_console_handle(push(Q),P,(P,Q)). 55 | output_console_handle(pop,(P,_),P). 56 | 57 | remove_xterm_args :- 58 | retractall(thread_util:xterm_args(['-fg', '#000000'])), 59 | retractall(thread_util:xterm_args(['-bg', '#ffffdd'])), 60 | retractall(thread_util:xterm_args(['-sb', '-sl', 1000, '-rightbar'])). 61 | 62 | :- initialization remove_xterm_args. 63 | 64 | 65 | -------------------------------------------------------------------------------- /cclab/prolog/cctab/cctab4.pl: -------------------------------------------------------------------------------- 1 | :- module(cctab, [run_tabled/1, cctabled/1]). 2 | 3 | :- use_module(library(delimcc), [p_reset/3, p_shift/2]). 4 | :- use_module(library(ccstate), [run_nb_state/3, set/1, get/1]). 5 | :- use_module(library(rbutils)). 6 | :- use_module(library(lambda1)). 7 | :- use_module(tabled, []). 8 | 9 | head_to_variant(Head, Variant) :- 10 | copy_term_nat(Head, Variant), 11 | numbervars(Variant, 0, _). 12 | 13 | :- meta_predicate cctabled(0). 14 | cctabled(Head) :- p_shift(tab, Head). 15 | 16 | run_tab(Goal, Ans) :- 17 | p_reset(tab, Goal, Status), 18 | cont_tab(Status, Ans). 19 | 20 | cont_tab(done, _). 21 | cont_tab(susp(Head, Cont), Ans) :- 22 | term_variables(Head,Y), K= \Y^Ans^Cont, 23 | head_to_variant(Head, Variant), 24 | get(Tabs1), 25 | ( rb_upd(Variant, tab(Solns,Status1), tab(Solns,Status2), Tabs1, Tabs2) 26 | -> ( Status1=active(Ks) 27 | -> Status2=active([K|Ks]), set(Tabs2) 28 | ; Status2=complete 29 | ), 30 | rb_in(Y, _, Solns), 31 | run_tab(Cont, Ans) 32 | ; rb_empty(Solns), 33 | rb_insert_new(Tabs1, Variant, tab(Solns,active([])), Tabs2), 34 | set(Tabs2), 35 | run_tab(producer(Variant, \Y^Head, K, Ans), Ans) 36 | ). 37 | 38 | producer(Variant, Generate, KP, Ans) :- 39 | call(Generate, Y1), 40 | get(Tabs1), 41 | rb_upd(Variant, tab(Solns1, Status), tab(Solns2, Status), Tabs1, Tabs2), 42 | rb_add(Y1, t, Solns1, Solns2), 43 | set(Tabs2), 44 | Status=active(Ks), 45 | member(K,[KP|Ks]), 46 | call(K,Y1,Ans). 47 | producer(Variant, _, _, _) :- 48 | app(rb_upd(Variant, tab(Solns, _), tab(Solns, complete)), fail 49 | 50 | :- meta_predicate run_tabled(0), run_tabled(0,-). 51 | run_tabled(Goal) :- run_tabled(Goal,_). 52 | run_tabled(Goal, FinalTables) :- 53 | rb_empty(Tables), 54 | term_variables(Goal, Ans), 55 | run_nb_state(run_tab(Goal, Ans), Tables, FinalTables). 56 | 57 | -------------------------------------------------------------------------------- /genutils/prolog/math.pl: -------------------------------------------------------------------------------- 1 | :- module(math, [mul/3, sub/3, add/3, neg/2, divby/3, recip/2, log/2, exp/2, gammaln/2, 2 | max/3, equal/3, stoch/3, to_float/2, prodlist/2, map_sum/3, map_sum/4]). 3 | 4 | :- use_module(library(apply_macros)). 5 | 6 | max(X,Y,Z) :- Z is max(X,Y). 7 | divby(X,Y,Z) :- Z is Y/X. 8 | sub(X,Y,Z) :- Z is Y-X. 9 | add(X,Y,Z) :- Z is Y+X. 10 | neg(X,Y) :- Y is -X. 11 | mul(X,Y,Z) :- Z is X*Y. 12 | equal(X,Y,V) :- X=Y -> V=1; V=0. 13 | recip(X,Y) :- Y is 1/X. 14 | gammaln(X,Y) :- Y is lgamma(X). 15 | log(X,Y) :- Y is log(X). 16 | exp(X,Y) :- Y is exp(X). 17 | 18 | prodlist(L,X) :- prodlist(L,1,X). 19 | prodlist([],X,X) :- !. 20 | prodlist([A|AX],X,Z) :- Y is A*X, prodlist(AX,Y,Z). 21 | 22 | 23 | %% stoch( +X:list(nonneg), -Y:list(nonneg), -Total:nonneg) is semidet. 24 | %% stoch( +X:list(nonneg), -Y:list(nonneg)) is semidet. 25 | % 26 | % Compute normalised probability distribution from histogram counts, with total. 27 | % Fails if total is less than or equal to zero. 28 | stoch(H,P,N) :- sumlist(H,N), N>0, maplist(divby(N),H,P). 29 | 30 | %% to_float( +Expr, -FloatVal:float) is det. 31 | % Return the floating point value of Expr as evaluated 32 | % by is/2. 33 | to_float(X,Y) :- Y is float(X). 34 | 35 | %% map_sum(+P:pred(+number,+number,-number), +L1:list(number), +L2:list(number), -S:number) is det. 36 | %% map_sum(+P:pred(+number,-number), +L:list(number), -S:number) is det. 37 | % 38 | % Map P (arity N) over (N-1) supplied lists sum the resulting (Nth) list. 39 | % Provided as predicates and goal expansions. 40 | :- meta_predicate map_sum(2,+,-), map_sum(3,+,+,-). 41 | map_sum(P,X,Y,Sum) :- maplist(P,X,Y,Z), sum_list(Z,Sum). 42 | map_sum(P,X,Sum) :- maplist(P,X,Y), sum_list(Y,Sum). 43 | 44 | user:goal_expansion(map_sum(P,X,Sum), (maplist(P,X,Y), sum_list(Y,Sum))). 45 | user:goal_expansion(map_sum(P,X,Y,Sum), (maplist(P,X,Y,Z), sum_list(Z,Sum))). 46 | -------------------------------------------------------------------------------- /cclab/README: -------------------------------------------------------------------------------- 1 | # cclab - A temporary pack for playing with delimited continuations 2 | 3 | This package explores a few ways of working with SWI Prolog's delimited continuations 4 | (reset/1 and shift/1) and some applications, including tabling. 5 | 6 | There are some experimental libraries in the prolog directory: 7 | 8 | delimcc - 3 alternative interfaces to shift and reset 9 | ccstate - Backtrackable state as a control effect reified as DCG goal. 10 | Hygienic nonbacktrackable state using nb_setval and nb_getval. 11 | cclistm - Nondeterminism reified as a list (like Haskell List monad) 12 | lambda1 - Lightweight lambdas 13 | lambda2 - Lightweight lambdas, different operator precedences 14 | 15 | There are three subdirectories: 16 | 17 | ccmisc - Initial experiments with combining statefulness and nondetermism effects 18 | cclazy - Memoisation, nondeterminism and probabilistic choice reified as lazy search trees 19 | cctab - More Prolog oriented tabling experiments, using Prolog nondetermism directly 20 | 21 | 22 | ## Running tests 23 | 24 | From the shell prompt: 25 | 26 | ``` 27 | $ swipl -g 'consult(library(ccmisc/state_nondet2))' 28 | $ swipl -g 'consult(library(cctab/test_memo))' 29 | $ swipl -g 'consult(library(cctab/test_prob))' 30 | $ swipl -g 'consult(library(cctab/cctab))' 31 | ``` 32 | 33 | ## Implementation notes 34 | 35 | ### Copying continuations 36 | 37 | In order to run a continuation multiple times, or do other maniplulations, 38 | it is often necessary to copy a continuation along with any variables with which 39 | it interfaces with other parts of the program. In many cases, the pattern of 40 | copying and calling is nicely captured by the semantics of lambda terms. 41 | This is why I've included a couple of experimental minimal lambda libraries 42 | here. They are closely modelled on Ulrich Neurmerkel's lambda library, but with 43 | a little less checking and a different representation of free variables. 44 | 45 | -------------------------------------------------------------------------------- /cclab/prolog/cctab/cctab.pl: -------------------------------------------------------------------------------- 1 | :- module(cctab, [run_tabled/1, cctabled/1]). 2 | 3 | :- use_module(library(delimcc), [p_reset/3, p_shift/2]). 4 | :- use_module(library(ccstate), [run_nb_state/3, set/1, get/1]). 5 | :- use_module(library(lambda1)). 6 | :- use_module(tabled, []). 7 | 8 | 9 | head_to_variant(Head, Variant) :- 10 | copy_term_nat(Head, Variant), 11 | numbervars(Variant, 0, _). 12 | 13 | :- meta_predicate cctabled(0). 14 | cctabled(Head) :- p_shift(tab, Head). 15 | 16 | run_tab(Goal, Ans) :- 17 | p_reset(tab, Goal, Status), 18 | cont_tab(Status, Ans). 19 | 20 | cont_tab(done, _). 21 | cont_tab(susp(Head, Cont), Ans) :- 22 | term_variables(Head,Y), K= \Y^Ans^Cont, 23 | get(Tabs1), 24 | head_to_variant(Head, Variant), 25 | ( rb_update(Tabs1, Variant, tab(Solns,Ks), tab(Solns,[K|Ks]), Tabs2) 26 | -> set(Tabs2), 27 | member_set(Head, Solns), % !!! what about variabls in Solns? 28 | run_tab(Cont, Ans) 29 | ; empty_set(Solns), 30 | rb_insert_new(Tabs1, Variant, tab(Solns,[]), Tabs2), 31 | set(Tabs2), 32 | run_tab(producer(Head, Variant, Y, Cont, Ans), Ans) 33 | ). 34 | 35 | 36 | producer(Head, Variant, Y, Cont, Ans) :- 37 | copy_term(Head-Y, Head1-Y1), 38 | call(Head1), 39 | get(Tabs1), 40 | rb_update(Tabs1, Variant, tab(Solns1, Ks), tab(Solns2, Ks), Tabs2), 41 | \+member_set(Head1, Solns1), 42 | add_to_set(Head1, Solns1, Solns2), 43 | set(Tabs2), 44 | ( Head=Head1, call(Cont) 45 | ; member(K,Ks), call(K,Y1,Ans) 46 | ). 47 | 48 | 49 | :- meta_predicate run_tabled(0), run_tabled(0,-). 50 | run_tabled(Goal) :- run_tabled(Goal,_). 51 | run_tabled(Goal, FinalTables) :- 52 | rb_empty(Tables), 53 | term_variables(Goal, Ans), 54 | run_nb_state(run_tab(Goal, Ans), Tables, FinalTables). 55 | 56 | empty_set([]). 57 | member_set(Y,Ys) :- member(Y,Ys). 58 | add_to_set(Y,Ys1,[Y|Ys1]). 59 | fold_set(_,[]) --> []. 60 | fold_set(P,[X|Xs]) :- call(P,X), fold_set(P,Xs). 61 | 62 | -------------------------------------------------------------------------------- /cclab/prolog/lambda2.pl: -------------------------------------------------------------------------------- 1 | :- module(lambda2, [ (\\)/1, (\\)/2, (\\)/3, (\\)/4, (\\)/5, (\\)/6, (\\)/7 2 | , '`'/3, '`'/4, '`'/5, '`'/6, '`'/7, '`'/8 3 | , op(1000,xfy,'`') 4 | , op(1200,fx,\\) 5 | ]). 6 | 7 | /** Lambdas, like Ulrich's but with lower precedence operators 8 | Use (\\)/1 to introduce a lambda, an optional (|)/2 to separate free from bound variables, 9 | and (`)/2 to separate arguments and body, eg =| \\F|X`Y`p(X,Y,F) |=. 10 | Operator precedences are low enough not to interfere with operator terms in the 11 | arguments or free variables sections. 12 | Sadly, the position of the '|' operator spoils the nice typing. 13 | */ 14 | 15 | :- set_prolog_flag(back_quotes, symbol_char). 16 | :- set_prolog_flag(generate_debug_info, false). 17 | 18 | :- meta_predicate \\(0), \\(1,?), \\(2,?,?), \\(3,?,?,?), \\(4,?,?,?,?), \\(5,?,?,?,?,?), \\(6,?,?,?,?,?,?). 19 | :- meta_predicate `(?,0,?), `(?,1,?,?), `(?,2,?,?,?), `(?,3,?,?,?,?), `(?,4,?,?,?,?,?), `(?,5,?,?,?,?,?,?). 20 | 21 | :- op(1000,xfy,`). 22 | 23 | \\(Lambda) :- copy_lambda(Lambda,Copy), call(Copy). 24 | \\(Lambda,A1) :- copy_lambda(Lambda,Copy), call(Copy,A1). 25 | \\(Lambda,A1,A2) :- copy_lambda(Lambda,Copy), call(Copy,A1,A2). 26 | \\(Lambda,A1,A2,A3) :- copy_lambda(Lambda,Copy), call(Copy,A1,A2,A3). 27 | \\(Lambda,A1,A2,A3,A4) :- copy_lambda(Lambda,Copy), call(Copy,A1,A2,A3,A4). 28 | \\(Lambda,A1,A2,A3,A4,A5) :- copy_lambda(Lambda,Copy), call(Copy,A1,A2,A3,A4,A5). 29 | \\(Lambda,A1,A2,A3,A4,A5,A6) :- copy_lambda(Lambda,Copy), call(Copy,A1,A2,A3,A4,A5,A6). 30 | 31 | copy_lambda(M:(G|Lam), M:Copy) :- !, copy_term_nat(G-Lam,G-Copy). 32 | copy_lambda(M:Lam, M:Copy) :- copy_term_nat(Lam,Copy). 33 | 34 | `(A,B,A) :- call(B). 35 | `(A,B,A,V1) :- call(B,V1). 36 | `(A,B,A,V1,V2) :- call(B,V1,V2). 37 | `(A,B,A,V1,V2,V3) :- call(B,V1,V2,V3). 38 | `(A,B,A,V1,V2,V3,V4) :- call(B,V1,V2,V3,V4). 39 | `(A,B,A,V1,V2,V3,V4,V5) :- call(B,V1,V2,V3,V4,V5). 40 | 41 | -------------------------------------------------------------------------------- /cclab/prolog/cclazy/treeutils.pl: -------------------------------------------------------------------------------- 1 | :- module(treeutils, [tree_yield/3, convert_tree/2, maptree/3, print_tree/1, print_ltree/1, print_and_dump/3]). 2 | 3 | :- use_module(library(callutils), [mr/5]). 4 | :- use_module(library(data/tree), [print_tree/1, maptree/3]). 5 | :- use_module(library(data/pair), [snd/2]). 6 | 7 | print_and_dump(D,Memo,T) :- print_ltree(T), call(D,Memo). 8 | 9 | print_ltree(T) :- 10 | once(convert_tree(T,T1)), 11 | once(print_tree(T1)). 12 | 13 | 14 | % this handles various kinds of trees. 15 | convert_tree(leaf(X), node(l(X),[])). 16 | convert_tree(node(Subtrees), node(n, Ts)) :- 17 | maplist(convert_tree, Subtrees, Ts). 18 | convert_tree(lnode(GenSubtrees), node(N, Ts)) :- 19 | call(GenSubtrees, Subtrees), 20 | maplist(convert_tree, Subtrees, Ts), 21 | label_node(Ts,N). 22 | convert_tree(lnode(Label,GenSubtrees), node(N, Ts)) :- 23 | % writeln(expanding:Label), 24 | call(GenSubtrees, Subtrees), 25 | maplist(convert_tree, Subtrees, Ts), 26 | label_node(Ts,Label,N). 27 | 28 | convert_tree(lwnode(Label,GenSubtrees), node(N, Ts)) :- 29 | % writeln(expanding:Label), 30 | call(GenSubtrees, Subtrees), 31 | maplist(convert_wtree, Subtrees, Ts), 32 | label_node(Ts,Label,N). 33 | 34 | convert_wtree(W-T1, node(W-L,C)) :- convert_tree(T1,node(L,C)). 35 | 36 | label_node([],f). 37 | label_node([_|_],n). 38 | 39 | label_node([],L,L:f). 40 | label_node([_|_],L,L:n). 41 | 42 | tree_yield(leaf(X)) --> [X]. 43 | tree_yield(node(Subtrees)) --> foldl(tree_yield, Subtrees). 44 | tree_yield(lnode(Gen)) --> {call(Gen, Subtrees)}, foldl(tree_yield, Subtrees). 45 | tree_yield(lnode(_,Gen)) --> {call(Gen, Subtrees)}, foldl(tree_yield, Subtrees). 46 | tree_yield(lwnode(_,Gen)) --> {call(Gen, Dist)}, foldl(mr(snd,tree_yield), Dist). 47 | 48 | user:portray(node(W-L)) :- format('(~3g)─~p',[W,node(L)]). 49 | user:portray(node(L:n)) :- print(L). 50 | user:portray(node(L:f)) :- print(L), print(node(f)). 51 | 52 | user:portray(node(n)). 53 | user:portray(node(f)) :- write('|'). 54 | user:portray(node(l(X:P))) :- format('~p:~3g',[X,P]). 55 | user:portray(node(l(X))) :- write('<'), print(X). 56 | 57 | -------------------------------------------------------------------------------- /cclab/prolog/cctab/lazymath.pl: -------------------------------------------------------------------------------- 1 | :- module(lazymath, [ add/3, sub/3, mul/3, max/3, min/3, stoch/2, exp/2, log_e/2, surp/2, lse/2, pow/3, log_stoch/2 2 | , patient/3, patient/4, lazy/4, map_sum/3, map_sum/4]). 3 | 4 | :- use_module(library(math), [stoch/3]). 5 | :- use_module(library(callutils)). 6 | :- use_module(library(insist)). 7 | 8 | % lazy arithmetic predicates 9 | max(X,Y,Z) :- when(ground(X-Y), Z is max(X,Y)). 10 | min(X,Y,Z) :- when(ground(X-Y), Z is min(X,Y)). 11 | add(X,Y,Z) :- when(ground(X-Y), Z is X+Y). %{Z=X+Y}. 12 | sub(X,Y,Z) :- when(ground(X-Y), Z is Y-X). %{Z=X-Y}. 13 | mul(X,Y,Z) :- when(ground(X-Y), Z is X*Y). %{Z=X*Y}. 14 | stoch(X,Y) :- when(ground(X), insist(stoch(X,Y,_))). 15 | log_e(X,Y) :- when(ground(X), Y is log(X)). 16 | exp(X,Y) :- when(ground(X), Y is exp(X)). 17 | surp(P,LP) :- when(ground(P), LP is -log(P)). 18 | pow(1,X,X) :- !. 19 | pow(B,X,Y) :- when(ground(X), Y is X^B). 20 | log_stoch(X,Y) :- when(ground(X), log_stoch_strict(X,Y)). 21 | 22 | log_stoch_strict([_],[0]) :- !. 23 | log_stoch_strict(LogWeights,LogProbs) :- 24 | log_sum_exp(LogWeights, LogTotal), 25 | maplist((math:sub(LogTotal)), LogWeights, LogProbs). 26 | 27 | lse(Xs,Z) :- when(ground(Xs), log_sum_exp(Xs,Z)). 28 | 29 | log_sum_exp([X],X) :- !. 30 | log_sum_exp(Xs,Y) :- 31 | max_list(Xs,M), 32 | call(add_log(M)*sum_list*maplist(exp_sub(M)),Xs,Y). 33 | exp_sub(M,X,Y) :- Y is exp(X-M). 34 | add_log(M,X,Y) :- Y is M+log(X). 35 | 36 | add_exp_sub(M,X,S1,S2) :- S2 is S1 + exp(X-M). 37 | 38 | :- meta_predicate lazy(3,?,?,-), patient(2,?,-), patient(3,?,?,-). 39 | lazy(P,X,Y,Z) :- freeze(Z,call(P,X,Y,Z)). 40 | patient(P,X,Y) :- when(ground(X),call(P,X,Y)). 41 | patient(P,X,Y,Z) :- when(ground(X-Y),call(P,X,Y,Z)). 42 | user:goal_expansion(lazy(P,X,Y,Z), freeze(Z,call(P,X,Y,Z))). 43 | user:goal_expansion(patient(P,X,Y), when(ground(X),call(P,X,Y))). 44 | user:goal_expansion(patient(P,X,Y,Z), when(ground(X-Y),call(P,X,Y,Z))). 45 | 46 | :- meta_predicate map_sum(2,+,-), map_sum(3,+,+,-). 47 | map_sum(P,X,Y,Sum) :- maplist(P,X,Y,Z), sum_list(Z,Sum). 48 | map_sum(P,X,Sum) :- maplist(P,X,Y), sum_list(Y,Sum). 49 | user:goal_expansion(map_sum(P,X,Sum), (maplist(P,X,Y), sum_list(Y,Sum))). 50 | user:goal_expansion(map_sum(P,X,Y,Sum), (maplist(P,X,Y,Z), sum_list(Z,Sum))). 51 | -------------------------------------------------------------------------------- /midiutils/prolog/mididcg.pl: -------------------------------------------------------------------------------- 1 | :- module(mididcg, [ midi//3 2 | , noteon//3 3 | , noteoff//2 4 | , note//4 5 | , prog//2 6 | , prog//3 7 | , prog//4 8 | , pan//2 9 | , volume//2 10 | , tempo//1 11 | , keysig//2 12 | , timesig//1 13 | , instr//2 14 | ]). 15 | 16 | :- use_module(library(clpfd)). 17 | :- use_module(library(dcg_pair)). 18 | :- use_module(library(dcg_core), [get//1, set//1]). 19 | :- use_module(library(genmidi), [gm/4]). 20 | 21 | midi(Msg,Arg1,Arg2) --> get(T) <\> [msg(T,M,Arg1,Arg2)], {M #= Msg}. 22 | midi(Msg,Arg1) --> get(T) <\> [msg(T,M,Arg1)], {M #= Msg}. 23 | meta(Msg,Bytes) --> get(T) <\> [meta(T,M,N,Bytes)], {M #= Msg, length(Bytes,N)}. 24 | text(Type,Text) --> get(T) <\> [text(T,M,Text)], {text_type_code(M, Type)}. 25 | 26 | text_type_code(0x01, text). 27 | text_type_code(0x02, copyright). 28 | text_type_code(0x03, track_name). 29 | text_type_code(0x04, instrument). 30 | text_type_code(0x05, lyric). 31 | text_type_code(0x06, marker). 32 | text_type_code(0x07, cue). 33 | 34 | tempo(T) --> meta(0x51, [B2, B1, B0]), {divmod(T,256,Z,B0), divmod(Z,256,B2,B1)}. 35 | keysig(Sharps,major) --> meta(0x59, [Sharps, 0]). 36 | keysig(Sharps,minor) --> meta(0x59, [Sharps, 1]). 37 | timesig(Num/Denom) --> meta(0x58, [Num, DenomPower, 24, 8]), { Denom #= 2^DenomPower }. 38 | 39 | holding_time(P) --> \< get(T), call_dcg(P), \< set(T). 40 | 41 | noteon(Ch,NN,V) --> midi(144+Ch,NN,V). 42 | noteoff(Ch,NN) --> midi(128+Ch,NN,0). 43 | 44 | note(Ch,Vel,Dur,NN) --> 45 | {N1 #= NN, V1 #= Vel}, 46 | noteon(Ch,N1,V1), \< adv(Dur), 47 | noteoff(Ch,N1). 48 | 49 | prog(Ch,Prog) --> 50 | midi(192+Ch,Prog). 51 | 52 | prog(Ch,Prog,Bank) --> 53 | { MSB #= Bank // 128, 54 | LSB #= Bank mod 128 55 | }, 56 | midi(176+Ch,0,MSB), 57 | midi(176+Ch,32,LSB), 58 | prog(Ch,Prog). 59 | 60 | prog(Ch,Prog,MSB,LSB) --> 61 | midi(176+Ch,0,MSB), 62 | midi(176+Ch,32,LSB), 63 | prog(Ch,Prog). 64 | 65 | instr(Ch,Instr) --> 66 | {gm(Instr,Prog,MSB,LSB)}, 67 | prog(Ch,Prog,MSB,LSB). 68 | 69 | pan(Ch,Pan) --> midi(176+Ch,10,Pan). 70 | 71 | volume(Ch,Vol) --> midi(176+Ch,7,Vol). 72 | 73 | adv(Dur,T1,T2) :- T2 #= T1 + Dur. 74 | -------------------------------------------------------------------------------- /webutils/framework/kube.pl: -------------------------------------------------------------------------------- 1 | :- module(kube, []). 2 | 3 | /** Enables use of Kube CSS framework 4 | */ 5 | 6 | :- use_module(library(http/html_write)). 7 | :- use_module(library(http/html_head)). 8 | :- use_module(library(htmlutils)). 9 | 10 | :- set_prolog_flag(double_quote,string). 11 | 12 | http:location( kube, weblib(kube310), []). 13 | 14 | user:head(kube(_),Head) --> !, 15 | html(head([ meta([name(viewport), content("width-device-width,initial-scale=1")]) 16 | | Head ])). 17 | 18 | requirements --> 19 | html_requires("//imperavi.com/css/combined.min.css"), 20 | html_requires("//imperavi.com/js/combined.min.js"). 21 | 22 | user:body(kube(Nav),Body) --> !, 23 | { setting(htmlutils:appname, AppName) }, 24 | use_font("Source Sans Pro",sourcepro), 25 | % html_requires(kube('kube.min.css')), 26 | html_requires("//imperavi.com/css/combined.min.css"), 27 | html_requires("//imperavi.com/js/combined.min.js"), 28 | 29 | html(body(class=kubepage, 30 | [ div( class=wrap, 31 | [ nav([id=nav,class=[navbar,fullwidth]], 32 | \navmenu(AppName,Nav)) 33 | ]) 34 | , div(class=wrap, 35 | div(id=main, 36 | [ aside(id=side,nav([class=nav,id="side-nav"], 37 | \navmenu(AppName,Nav))) 38 | , div(id=area,Body) 39 | ])) 40 | , div(class=wrap, 41 | footer(id=footer, 42 | [a(href='.',AppName), nav(class=[navbar,'navbar-right'], ul(\Nav))])) 43 | ])). 44 | 45 | navmenu(AppName,Nav) --> html(ul([li(\link(root,b(AppName))),\Nav])). 46 | navmenu(Nav) --> html(nav(class=[navbar,"navbar-left"],ul(\Nav))). 47 | sidebar(Contents) --> html(aside(id=side,Contents)). 48 | 49 | button_link(Ref,Content) --> 50 | html(a([class('btn btn-small'),href(Ref)],Content)). 51 | 52 | % menu(Classes,Content) --> 53 | % html(div(class(['pure-menu', 'pure-menu-open'|Classes]), Content)). 54 | % % Add pure-menu-selected to active item 55 | % hmenu(Heading,Items) --> 56 | % menu(['pure-menu-horizontal'], [a([href='.',class="pure-menu-heading"],Heading), ul(\Items)]). 57 | 58 | % vmenu(Heading,Items) --> 59 | % menu([], [a([href='.',class="pure-menu-heading"],Heading), ul(\Items)]). 60 | -------------------------------------------------------------------------------- /cclab/prolog/cctab/tabled.pl: -------------------------------------------------------------------------------- 1 | :- module(tabled, [fib/2, pathl//0, pathr//0]). 2 | 3 | /** Test predicates for tabling 4 | NB. this module expects cctabled/1 to be imported into user. 5 | */ 6 | 7 | :- use_module(library(ccmacros)). 8 | :- persistent_history. 9 | :- cctable fib/2. 10 | 11 | fib(0,1). 12 | fib(1,1). 13 | fib(N,X) :- 14 | succ(M,N), fib(M,Y), 15 | succ(L,M), fib(L,Z), 16 | plus(Y,Z,X). 17 | 18 | edge(a,b). 19 | edge(a,c). 20 | edge(b,d). 21 | edge(c,d). 22 | edge(d,e). 23 | edge(d,f). 24 | edge(f,g). 25 | edge(N,M) :- number(N), (M is N+1; M is N-1). 26 | 27 | % four tabled transitive closures of edge/2 28 | :- cctable pathl//0, pathl1//0, pathr//0, pathr1//0. 29 | pathl --> edge; pathl, edge. 30 | pathl1 --> pathl1, edge; edge. 31 | pathr --> edge; edge, pathr. 32 | pathr1 --> edge, pathr1; edge. 33 | 34 | :- cctable ppp//0, qqq//0. 35 | ppp --> qqq, edge; edge. 36 | qqq --> ppp. 37 | 38 | % for testing handling of input and output variables in continuations. 39 | path_a(Y) :- pathl(a,X), Y=a(X). 40 | path1_a(Y) :- pathl1(a,X), Y=a(X). 41 | 42 | :- initialization debug(cctab), module(tabled). 43 | 44 | :- cctable sent//0, sent1//1. 45 | sent --> {member(A, [b,l,r])}, sent1(A). 46 | sent1(b) --> {member(W,[cool,wicked])}, [W]. 47 | sent1(l) --> sent, [not]. 48 | sent1(r) --> [really], sent. 49 | 50 | :- cctable last/2. 51 | last([X],X). 52 | last([_|Xs],X) :- last(Xs,X). 53 | 54 | 55 | % specify preterminals as DCG that spits out alternatives 56 | user:term_expansion(Lab | Body, Clause) :- 57 | dcg_translate_rule(Lab --> Body, Clause). 58 | 59 | :- meta_predicate +(2,?,?). 60 | +Lab --> [T], {call(Lab,Vals,[]), member(T,Vals)}. 61 | 62 | :- cctable s//0, np//0, vp//0, pp//0, nom//0. 63 | 64 | s --> np, vp. 65 | 66 | np --> +d, nom 67 | ; +pn 68 | ; np, pp. 69 | 70 | vp --> +iv 71 | ; +tv, np 72 | ; +dv, np, np 73 | ; vp, pp 74 | ; +mv, s. 75 | 76 | nom --> +n 77 | ; +adj, nom. 78 | 79 | pp --> +p, np. 80 | 81 | % preterminal switch declarations 82 | adj | [hot,cold,thin,fat,disgusting,lovely]. 83 | pn | [alice, bob, cuthbert, delia, edna]. 84 | d | [the,a,some,my]. % ,every,no]. 85 | mv | [knew,thought,believed,said]. 86 | dv | [gave,made,baked]. 87 | tv | [saw, ate, hated, baked, liked, walked, ran, loved, caught]. 88 | iv | [lived, worked]. 89 | n | [dog,telescope,man,cat,mat,cake,box,floor,face,pie,moose,pyjamas,park]. 90 | p | [with,on,under,in,without,by]. 91 | 92 | -------------------------------------------------------------------------------- /genutils/prolog/data/store.pl: -------------------------------------------------------------------------------- 1 | :- module( store, 2 | [ store_new/1 3 | , store_add//2 4 | , store_get//2 5 | , store_set//2 6 | , store_upd//3 7 | , store_apply//2 8 | , store_contains//2 9 | ]). 10 | 11 | :- meta_predicate store_apply(+,2,+,-). 12 | 13 | /** Supply of references to storage cells 14 | 15 | This module provides a sort of store data structure - terms 16 | can be added to the store and then accessed using a reference 17 | term which is returned by store_add//2. 18 | 19 | The type =|ref(A)|= denotes the type of store references 20 | that point to terms of type A. 21 | 22 | All predicates except store_new/1 take store input and output 23 | arguments at the end so they can easily be used in a DCG with 24 | the store as threaded state variable. 25 | */ 26 | 27 | :- use_module(library(rbtrees)). 28 | 29 | %% store_new(-H:store) is det. 30 | % Unifies H with an empty store. 31 | store_new(store(0,A)) :- rb_empty(A). 32 | 33 | %% store_add(+V:A, -R:ref(A), +H1:store, -H2:store) is det. 34 | % Add V to store and return R as a reference to it. 35 | store_add(V, N1, store(N1,T1), store(N2,T2)) :- rb_insert_new(T1,N1,V,T2), succ(N1,N2). 36 | 37 | %% store_get(+R:ref(A), -V:A, +H1:store, -H2:store) is det. 38 | % Get term refered to by reference R. 39 | store_get(Ref, V, store(N,T), store(N,T)) :- rb_lookup(Ref,V,T). 40 | 41 | %% store_contains(-R:ref(A), -V:A, +H1:store, -H2:store) is nondet. 42 | % True if store contains A under reference R. 43 | store_contains(Ref, V, store(N,T), store(N,T)) :- rb_in(Ref,V,T). 44 | 45 | %% store_set(+R:ref(A), -V:A, +H1:store, -H2:store) is det. 46 | % Update the term referred to by R to take the new values V. 47 | store_set(Ref, V, store(N,T1), store(N,T2)) :- rb_update(T1,Ref,V,T2). 48 | 49 | %% store_upd(+R:ref(A), X1:A, X2:A, +H1:store, -H2:store) is det. 50 | % Unify X1 with the value of R in H1 and replace the value 51 | % with X2 to get H2. The same effect can be achieved with store_apply//2 52 | % but this saves a metacall. 53 | store_upd(Ref, V1, V2, store(N,T1), store(N,T2)) :- rb_update(T1,Ref,V1,V2,T2). 54 | 55 | %% store_apply(+R:ref(A), Op:pred(A,A), +H1:store, -H2:store) is det. 56 | % Apply binary predicate Op to the term in the store reference by R. 57 | % The old value is replaced by the new value return by Op in its 58 | % second argument. 59 | store_apply(Ref, Op, store(N,T1), store(N,T2)) :- rb_apply(T1,Ref,Op,T2). 60 | 61 | user:portray(store(N,_)) :- format('',[N]). 62 | -------------------------------------------------------------------------------- /cclab/prolog/ccbeam/test_beam_nd.pl: -------------------------------------------------------------------------------- 1 | :- module(test_vbeam, []). 2 | 3 | :- use_module(library(data/pair), [pair/3]). 4 | :- use_module(library(ccstate), [run_nb_state/3, app/1, run_ref/1, run_env/1, env_new/2, env_app/2, env_upd/3, env_get/2]). 5 | :- use_module(library(lambda2)). 6 | :- use_module(library(ccmacros2)). 7 | :- use_module(ccbeam4). 8 | 9 | :- set_prolog_flag(back_quotes, symbol_char). 10 | 11 | 12 | :- initialization module(test_vbeam), 13 | set_prolog_flag(back_quotes, symbol_char). 14 | 15 | % ---- test programs ----- 16 | choose(Xs,X) :- 17 | length(Xs,N), P is 1/N, 18 | maplist(pair(P),Xs,Dist), 19 | dist(Dist,X). 20 | dist(Ps,Xs,X) :- 21 | maplist(pair,Ps,Xs,PXs), 22 | dist(PXs,X). 23 | 24 | test0(r(X)) :- choose([1,2,3],X). 25 | 26 | test(Z) :- 27 | dist([0.2,0.5,0.3], [1,2,3],X), 28 | dist([0.4,0.4,0.2], [a(X),b(X),c(X)],Y), 29 | dist([0.1,0.5,0.4], [Y-x, Y-y, Y-z],Z1), 30 | dist([0.3,0.4,0.3], [Z1-u, Z1-v, Z1-w],Z). 31 | 32 | markov(0,_,[]). 33 | markov(N,Y,[X|Xs]) :- 34 | succ(M,N), 35 | trans(Y,X), 36 | markov(M,X,Xs). 37 | 38 | hmm(_,0-_,[]). 39 | hmm(HMM,N-Y,[X|Xs]) :- 40 | succ(M,N), 41 | trans(Y,Z), 42 | obs(Z,X), 43 | call(HMM,M-Z,Xs). 44 | 45 | trans(_,X) :- choose([a,b],X). 46 | obs(_,X) :- choose([x,y,z],X). 47 | 48 | link(a,X) :- choose([b,c],X). 49 | link(b,d). 50 | link(c,X) :- choose([d,m],X). 51 | link(d,X) :- choose([e,f],X). 52 | link(e,g). 53 | link(f,X) :- choose([g,k],X). 54 | link(g,h). 55 | link(h,X) :- choose([i,j],X). 56 | link(k,l). 57 | 58 | 59 | link(w,X) :- dist([0.75-x,0.25-y],X). 60 | link(x,X) :- dist([0.75-v,0.25-z],X). 61 | link(y,X) :- dist([0.9-z, 0.1-v],X). 62 | % link(z,X) :- dist([0.5-t,0.5-u],X). 63 | 64 | % left and right recursive grammar 65 | :- cctable sent//1. 66 | sent(S,L1,L2) :- choose([b,l,r],A), sentx(A,S,L1,L2). 67 | sentx(b,_) --> word. 68 | sentx(r,S) --> call(S), out(not). 69 | sentx(l,S) --> out(really), call(S). 70 | 71 | word --> {choose([cool,wicked],W)}, out(W). 72 | 73 | out(X,[X|T],T). 74 | 75 | % incomplete recursive form 76 | :- cctable pathl//0, pathr//0, pp//0, qq//0. 77 | pathr --> link, {choose(['B','R'],Q)}, maybe_rec(Q,pathr). 78 | pathl --> {dist([0.6-'B',0.4-'R'],Q)}, maybe_rec(Q,pathl), link. 79 | 80 | pp --> {dist([0.6-b,0.4-r],Q)}, pp(Q). 81 | pp(b) --> link. 82 | pp(r) --> qq, link. 83 | qq --> pp. 84 | 85 | 86 | maybe_rec('B',_) --> []. 87 | maybe_rec('R',P) --> call(P). 88 | 89 | user:portray(F) :- float(F), !, format('~4g',[F]). 90 | -------------------------------------------------------------------------------- /genutils/prolog/ccnbref.pl: -------------------------------------------------------------------------------- 1 | :- module(ccnbref, [run_nb_ref/1, nbref_new/2, with_nbref/2, nbref_new/3, 2 | nbref_app/2, nbref_get/2, nbref_add_with/3]). 3 | /** Context providing allocation and release of nb_ mutable variables 4 | */ 5 | 6 | :- use_module(library(delimcc), [p_reset/3, p_shift/2]). 7 | 8 | :- meta_predicate nbref_app(+,2), nbref_add_with(+,3,+), run_nb_ref(0), with_nbref(-,0). 9 | 10 | %% run_nb_ref(+Goal:pred) is det. 11 | % Runs Goal in a delimited context supporting nbref_new/2 for allocating 12 | % a fresh name for a nonbacktrackable mutable variable. 13 | run_nb_ref(Goal) :- with_nbref(E, run(Goal, E)). 14 | 15 | run(Goal, E) :- p_reset(nbref, Goal, Status), cont(Status, E). 16 | cont(susp(X-Ref,Cont), E) :- nbref_new(E, X, Ref), run(Cont, E). 17 | cont(done, _). 18 | 19 | %% nbref_new(+V:A, -R:nbref(A)) is det. 20 | % Create a new nb_ variable initialised with value V. Must be run in the 21 | % context of run_nb_ref/1. 22 | nbref_new(X, Ref) :- p_shift(nbref, X-Ref). 23 | 24 | %% with_nbref(-E:nbenv, +Goal:pred) is det. 25 | % Runs Goal. While Goal is active, E is bound to a value which can be used 26 | % with nbref_new/3 to allocate a fresh name for a nonbacktrackable mutable 27 | % variable. E remains bound after final exit, but should not be used. 28 | with_nbref(E, Goal) :- setup_call_cleanup(setup(E), Goal, cleanup(E)). 29 | 30 | setup(E) :- gensym(nbref,ID), atom_concat(ID,'.',E), nb_setval(E, 0). 31 | cleanup(E) :- nb_getval(E, N), nb_delete(E), forall(between(1,N,I), delete(E,I)). 32 | delete(E,I) :- atomic_concat(E,I,Ref), nb_delete(Ref). 33 | 34 | %% nbref_new(+E:nbenv, +V:A, -R:nbref(A)) is det. 35 | nbref_new(E, Value, Ref) :- 36 | nb_getval(E, I), J is I+1, atomic_concat(E, J, Ref), 37 | nb_setval(Ref, Value), nb_setval(E,J). 38 | 39 | %% nbref_app(+R:ref(A), +P:pred(+A,-A)) is det. 40 | nbref_app(Ref, P) :- nb_getval(Ref, X1), call(P,X1,X2), nb_setval(Ref, X2). 41 | 42 | %% nbref_get(+R:ref(A), -V:A) is det. 43 | nbref_get(Ref, X) :- nb_getval(Ref, X). 44 | 45 | %% nbref_add_with(+R:ref(A), +P:pred(+B,+A,-A), +X:B) is det. 46 | % Helper for more efficient updating of non-backtrackable mutable data 47 | % structures. X is copied using duplicate_term/2, and P is expected to 48 | % insert it into the data structure without trailing any more data, such 49 | % that the variable can be updated using nb_linkval/2 instead of 50 | % nb_setval/2 (which would copy the whole data structure). 51 | nbref_add_with(Ref,Pred,X) :- 52 | duplicate_term(X,X1), 53 | nb_getval(Ref, Y1), call(Pred,X1,Y1,Y2), 54 | nb_linkval(Ref, Y2). 55 | -------------------------------------------------------------------------------- /cclab/prolog/cctab/cctab6.pl: -------------------------------------------------------------------------------- 1 | :- module(cctab, [run_tabled/1, run_tabled/2, cctabled/1, sanitise/2]). 2 | 3 | /* Tabling, answers not delivered to producer continuation until completion 4 | NB - this doesn't work for co-recursive predicates! See cctab5.pl for a full 5 | description of the problem. 6 | */ 7 | 8 | :- use_module(library(rbutils)). 9 | :- use_module(library(dcg_core), [out//1]). 10 | :- use_module(library(data/pair), [fst/2, fsnd/3]). 11 | :- use_module(library(callutils), [mr/5]). 12 | :- use_module(library(delimcc), [p_reset/3, p_shift/2]). 13 | :- use_module(library(ccstate), [run_nb_state/3, app/1, set/1, get/1]). 14 | :- use_module(library(lambda1)). 15 | :- use_module(tabled, []). 16 | 17 | 18 | head_to_variant(Head, Variant) :- 19 | copy_term_nat(Head, Variant), 20 | numbervars(Variant, 0, _). 21 | 22 | :- meta_predicate cctabled(0). 23 | cctabled(Head) :- p_shift(tab, Head). 24 | 25 | run_tab(Goal, Ans) :- 26 | p_reset(tab, Goal, Status), 27 | cont_tab(Status, Ans). 28 | 29 | cont_tab(done, _). 30 | cont_tab(susp(Head, Cont), Ans) :- 31 | term_variables(Head,Y), K= \Y^Ans^Cont, 32 | head_to_variant(Head, Variant), 33 | get(Tabs1), 34 | ( rb_upd(Variant, tab(Solns,Status1), tab(Solns,Status2), Tabs1, Tabs2) 35 | -> ( Status1=active(Ks) 36 | -> Status2=active([K|Ks]), set(Tabs2) 37 | ; Status2=complete 38 | ), 39 | rb_in(Y, _, Solns), 40 | run_tab(Cont, Ans) 41 | ; rb_empty(Solns), 42 | rb_insert_new(Tabs1, Variant, tab(Solns,active([])), Tabs2), 43 | set(Tabs2), 44 | run_tab(producer(Variant, \Y^Head, K, Ans), Ans) 45 | ). 46 | 47 | producer(Variant, Generate, _, Ans) :- 48 | call(Generate, Y1), 49 | app(add_soln(Variant, Y1, active(Ks))), 50 | member(K,Ks), 51 | call(K,Y1,Ans). 52 | producer(Variant, _, KP, Ans) :- 53 | app(rb_upd(Variant, tab(Solns,_), tab(Solns,complete))), 54 | rb_in(Y, _, Solns), 55 | call(KP,Y,Ans). 56 | 57 | add_soln(Variant, Y1, Status, Tabs1, Tabs2) :- 58 | rb_upd(Variant, tab(Solns1, Status), tab(Solns2, Status), Tabs1, Tabs2), 59 | rb_insert_new(Solns1, Y1, t, Solns2). 60 | 61 | :- meta_predicate run_tabled(0), run_tabled(0,-). 62 | run_tabled(Goal) :- run_tabled(Goal,_). 63 | run_tabled(Goal, FinalTables) :- 64 | rb_empty(Tables), 65 | term_variables(Goal, Ans), 66 | run_nb_state(run_tab(Goal, Ans), Tables, FinalTables). 67 | 68 | sanitise(Tabs1, Tabs2) :- rb_fold(mr(fsnd(clean_tab), out), Tabs1, Tabs2, []). 69 | clean_tab(tab(Solns,Status), Stat-Solns1) :- functor(Status,Stat,_), rb_fold(mr(fst,out), Solns, Solns1, []). 70 | 71 | 72 | -------------------------------------------------------------------------------- /cclab/prolog/ccbeam/ccbeam3.pl: -------------------------------------------------------------------------------- 1 | :- module(ccbeam, [lazy_beam/2, dist/2, fail_/0, cctabled/2]). 2 | 3 | /** Probabilistic choice with beam search to find most probable paths 4 | 5 | Simple beam search using a priority queue to manage threads. 6 | With memoisation. No limit on number of threads. 7 | Working with head goals and variants instead of binary predicates. 8 | 9 | */ 10 | 11 | :- use_module(library(rbutils)). 12 | :- use_module(library(dcg_pair)). 13 | :- use_module(library(delimcc), [p_reset/3, p_shift/2]). 14 | :- use_module(library(lambda2)). 15 | :- use_module(pack(pha/prolog/library/priorityq)). 16 | 17 | :- set_prolog_flag(back_quotes, symbol_char). 18 | 19 | :- meta_predicate cctabled(0,0). 20 | cctabled(TableAs,Head) :- p_shift(beam, tab(TableAs,Head)). 21 | dist(Xs,X) :- p_shift(beam, dist(Xs,X)). 22 | fail_ :- dist([],_). 23 | 24 | :- meta_predicate lazy_beam(0,-). 25 | lazy_beam(Goal, Prob) :- 26 | term_variables(Goal, Y), 27 | rb_empty(S1), 28 | pq_empty(PQ0), 29 | pq_insert(1,\\Y`Goal,PQ0,PQ1), 30 | unfolds_to(run_beam,Prob-Y,S1-PQ1,_). 31 | 32 | unfolds_to(Pred,X) --> 33 | call(Pred,Y), ({Y=X}; unfolds_to(Pred,X)). 34 | 35 | run_beam(WeightedAns) --> 36 | \> pq_remove(P, Thread), 37 | {p_reset(beam, call(Thread,Ans), Status)}, 38 | cont_beam(Status, P-Ans, WeightedAns). 39 | 40 | cont_beam(done, PAns, PAns) --> []. 41 | cont_beam(susp(Req, Cont), PAns1, PAns2) --> 42 | handle(Req, Cont, PAns1), 43 | run_beam(PAns2). 44 | 45 | handle(dist(Ys,Y), Cont, P-Ans) --> 46 | \> foldl(insert(\\Y`Ans`Cont, P), Ys). 47 | handle(tab(TableAs,Head), Cont, P-Ans) --> 48 | { term_variables(Head,Y), 49 | term_to_ground(Head,Variant), 50 | K = (\\Y`Ans`Cont) }, 51 | ( \< rb_trans(Variant, entry(V,PYs,Conts), entry(V,PYs,[P-K|Conts])) 52 | -> \> rb_fold(insert_(K,P),PYs) 53 | ; {rb_empty(EmptyDist)}, 54 | \< rb_add(Variant, entry(TableAs,EmptyDist,[P-K])), 55 | \> pq_insert(1,producer(Variant,\\Y`Head)) 56 | ). 57 | handle(ans(Variant,Y), _, P-_) --> 58 | \< rb_upd(Variant, entry(V,Ys,Conts), entry(V,Ys2,Conts)), 59 | ( {rb_add(Y,P,Ys,Ys2)} 60 | -> \> foldl(resume(P,Y), Conts) 61 | ; {rb_upd(Y,OldP,NewP,Ys,Ys2), NewP is max(OldP,P)}, 62 | {debug(ccbeam, 'New solutions for ~p: ~p @ ~p (prev was ~p)',[Variant,Y,P,OldP])} 63 | ). 64 | 65 | producer(Variant,Generate,_) :- call(Generate,Y), p_shift(beam, ans(Variant,Y)). 66 | insert(K, P0, P-X) --> resume(P0,P,K,X). 67 | insert_(K, P0, X-P) --> resume(P0,P,K,X). 68 | resume(P, X, P0-K) --> resume(P0,P,K,X). 69 | resume(P0,P,K,X) --> {P1 is P0*P}, pq_insert(P1,call(K,X)). 70 | 71 | term_to_ground(T, G) :- copy_term_nat(T,G), numbervars(G,0,_). 72 | -------------------------------------------------------------------------------- /cclab/prolog/ccbeam/test_vbeam.pl: -------------------------------------------------------------------------------- 1 | :- module(test_vbeam, []). 2 | 3 | :- use_module(library(data/pair), [pair/3]). 4 | :- use_module(library(ccstate), [run_nb_state/3, app/1, run_ref/1, run_env/1, env_new/2, env_app/2, env_upd/3, env_get/2]). 5 | :- use_module(library(lambda2)). 6 | :- use_module(library(ccmacros2)). 7 | :- use_module(ccbeam3). 8 | 9 | :- set_prolog_flag(back_quotes, symbol_char). 10 | 11 | 12 | :- initialization module(test_vbeam), 13 | set_prolog_flag(back_quotes, symbol_char). 14 | 15 | % ---- test programs ----- 16 | choose(Xs,X) :- 17 | length(Xs,N), P is 1/N, 18 | maplist(pair(P),Xs,Dist), 19 | dist(Dist,X). 20 | dist(Ps,Xs,X) :- 21 | maplist(pair,Ps,Xs,PXs), 22 | dist(PXs,X). 23 | 24 | test0(r(X)) :- choose([1,2,3],X). 25 | 26 | test(Z) :- 27 | dist([0.2,0.5,0.3], [1,2,3],X), 28 | dist([0.4,0.4,0.2], [a(X),b(X),c(X)],Y), 29 | dist([0.1,0.5,0.4], [Y-x, Y-y, Y-z],Z1), 30 | dist([0.3,0.4,0.3], [Z1-u, Z1-v, Z1-w],Z). 31 | 32 | markov(0,_,[]). 33 | markov(N,Y,[X|Xs]) :- 34 | succ(M,N), 35 | trans(Y,X), 36 | markov(M,X,Xs). 37 | 38 | hmm(_,0-_,[]). 39 | hmm(HMM,N-Y,[X|Xs]) :- 40 | succ(M,N), 41 | trans(Y,Z), 42 | obs(Z,X), 43 | call(HMM,M-Z,Xs). 44 | 45 | trans(_,X) :- choose([a,b],X). 46 | obs(_,X) :- choose([x,y,z],X). 47 | 48 | link(a,X) :- choose([b,c],X). 49 | link(b,d). 50 | link(c,X) :- choose([d,m],X). 51 | link(d,X) :- choose([e,f],X). 52 | link(e,g). 53 | link(f,X) :- choose([g,k],X). 54 | link(g,h). 55 | link(h,X) :- choose([i,j],X). 56 | link(i,_) :- fail_. 57 | link(j,_) :- fail_. 58 | link(k,l). 59 | link(l,_) :- fail_. 60 | link(m,_) :- fail_. 61 | 62 | 63 | link(w,X) :- dist([0.75-x,0.25-y],X). 64 | link(x,X) :- dist([0.75-v,0.25-z],X). 65 | link(y,X) :- dist([0.9-z, 0.1-v],X). 66 | link(z,_) :- fail_. 67 | % link(z,X) :- dist([0.5-t,0.5-u],X). 68 | % link(t,_) :- fail_. 69 | % link(u,_) :- fail_. 70 | link(v,_) :- fail_. 71 | 72 | % left and right recursive grammar 73 | :- cctable sent//1. 74 | sent(S,L1,L2) :- choose([b,l,r],A), sentx(A,S,L1,L2). 75 | sentx(b,_) --> word. 76 | sentx(r,S) --> call(S), out(not). 77 | sentx(l,S) --> out(really), call(S). 78 | 79 | word --> {choose([cool,wicked],W)}, out(W). 80 | 81 | out(_,[],_) :- !, fail_. 82 | out(W,[X|T],T) :- W=X -> true; fail_. 83 | 84 | % incomplete recursive form 85 | :- cctable pathl//0, pathr//0, pp//0, qq//0. 86 | pathr --> link, {choose(['B','R'],Q)}, maybe_rec(Q,pathr). 87 | pathl --> {dist([0.6-'B',0.4-'R'],Q)}, maybe_rec(Q,pathl), link. 88 | 89 | pp --> {dist([0.6-b,0.4-r],Q)}, pp(Q). 90 | pp(b) --> link. 91 | pp(r) --> qq, link. 92 | qq --> pp. 93 | 94 | 95 | maybe_rec('B',_) --> []. 96 | maybe_rec('R',P) --> call(P). 97 | 98 | user:portray(F) :- float(F), !, format('~4g',[F]). 99 | -------------------------------------------------------------------------------- /textutils/prolog/docutils.pl: -------------------------------------------------------------------------------- 1 | :- module(docutils,[ 2 | phrase_to_pager/1 3 | , phrase_to_pager/2 4 | , html_to_viewer/2 5 | , html_to_pager/2 6 | , roff_to_pager/1 7 | , roff/3 8 | ]). 9 | 10 | :- use_module(library(fileutils)). 11 | :- use_module(library(dcg_core)). 12 | :- use_module(library(dcg_codes)). 13 | :- use_module(library('http/html_write')). 14 | 15 | :- meta_predicate 16 | phrase_to_pager(2) 17 | , phrase_to_pager(+,2) 18 | , html_to_pager(+,2) 19 | , html_to_viewer(+,2) 20 | , roff_to_pager(2) 21 | , roff(:,?,?) 22 | . 23 | 24 | phrase_to_pager(Phrase) :- phrase_to_pager('less -FX',Phrase). 25 | 26 | phrase_to_pager(Pager,Phrase) :- 27 | phrase(Phrase,Codes,[]), 28 | with_output_to_file(pipe(Pager), format(Codes,[])). 29 | 30 | html_to_pager(Viewer,Phrase) :- 31 | tty_size(_,TermWidth), 32 | FmtWidth is min(TermWidth,90), 33 | viewer_cmd_format(Viewer,FmtWidth,ViewerCmd), 34 | phrase(Phrase,Codes,[]), 35 | with_output_to_file( 36 | pipe(ViewerCmd), 37 | html_write:print_html(Codes) 38 | ). 39 | 40 | viewer_cmd_format(elinks/Pager,Width,Cmd) :- !, format(string(Cmd),'elinks -dump 1 -dump-width ~w | ~w',[Width,Pager]). 41 | viewer_cmd_format(lynx/Pager,Width,Cmd) :- !, format(string(Cmd),'lynx -stdin -dump -width=~w | ~w',[Width,Pager]). 42 | viewer_cmd_format(Browser,Width,Fmt) :- viewer_cmd_format(Browser/'less -FX',Width,Fmt). 43 | 44 | 45 | html_to_viewer(Viewer,Phrase) :- 46 | tty_size(_,TermWidth), 47 | FmtWidth is min(TermWidth,90), 48 | ( Viewer=elinks, 49 | sformat(ElinksViewer,'elinks -force-html',[FmtWidth]) 50 | ; Viewer=lynx, 51 | sformat(ElinksViewer,'lynx -stdin',[FmtWidth]) 52 | ), 53 | phrase(Phrase,Codes,[]), 54 | with_stream(Stream, 55 | open(pipe(ElinksViewer),write,Stream), 56 | print_html(Stream,Codes) 57 | ). 58 | 59 | roff_to_pager(Phrase) :- 60 | tty_size(_,TermWidth), 61 | FmtWidth is min(TermWidth,78), 62 | utils:rep(FmtWidth,'-',HRule), 63 | format(HRule), nl, 64 | format(string(Groff),'/usr/bin/groff -mdoc -Tascii -rLL=~wn | less -FX',[FmtWidth]), 65 | phrase(Phrase,Codes,[]), 66 | with_output_to_file(pipe(Groff), format(Codes,[])), nl. 67 | 68 | roff(M:mm1(Nm,Args)) --> ".", roff(M:mm(Nm,Args)), cr. 69 | roff(M:mm(Nm,Args)) --> at(Nm), sp, seq(M:Args,sp). 70 | 71 | roff(M:m(Nm)) --> roff(M:mm(Nm,[])). 72 | roff(M:m(Nm,A1)) --> roff(M:mm(Nm,[A1])). 73 | roff(M:m(Nm,A1,A2)) --> roff(M:mm(Nm,[A1,A2])). 74 | roff(M:m(Nm,A1,A2,A3)) --> roff(M:mm(Nm,[A1,A2,A3])). 75 | roff(M:m(Nm,A1,A2,A3,A4)) --> roff(M:mm(Nm,[A1,A2,A3,A4])). 76 | 77 | roff(M:m1(Nm)) --> roff(M:mm1(Nm,[])). 78 | roff(M:m1(Nm,A1)) --> roff(M:mm1(Nm,[A1])). 79 | roff(M:m1(Nm,A1,A2)) --> roff(M:mm1(Nm,[A1,A2])). 80 | roff(M:m1(Nm,A1,A2,A3)) --> roff(M:mm1(Nm,[A1,A2,A3])). 81 | roff(M:m1(Nm,A1,A2,A3,A4)) --> roff(M:mm1(Nm,[A1,A2,A3,A4])). 82 | 83 | 84 | -------------------------------------------------------------------------------- /cclab/prolog/ccbeam/ccbeam4.pl: -------------------------------------------------------------------------------- 1 | :- module(ccbeam, [lazy_beam/2, lazy_beam/4, dist/2, cctabled/2]). 2 | 3 | /** Probabilistic choice with beam search to find most probable paths 4 | 5 | Simple beam search using a priority queue to manage threads. 6 | With memoisation. No limit on number of threads. 7 | Working with head goals and variants instead of binary predicates. 8 | */ 9 | 10 | :- use_module(library(rbutils)). 11 | :- use_module(library(dcg_pair)). 12 | :- use_module(library(delimcc), [p_reset/3, p_shift/2]). 13 | :- use_module(library(lambda2)). 14 | 15 | :- set_prolog_flag(back_quotes, symbol_char). 16 | 17 | :- meta_predicate cctabled(0,0), lazy_beam(0,-). 18 | cctabled(TableAs,Head) :- p_shift(beam, tab(TableAs,Head)). 19 | dist(Xs,X) :- member(P-X,Xs), p_shift(beam, factor(P)). 20 | 21 | :- meta_predicate lazy_beam(0,-), lazy_beam(0,-,-,-). 22 | lazy_beam(Goal, Prob) :- lazy_beam(Goal, Prob, _, _). 23 | lazy_beam(Goal, Prob, S2, QMass) :- 24 | term_variables(Goal, Y), 25 | rb_empty(S1), pq_empty(PQ0), 26 | pq_insert(1,\\Y`Goal,PQ0,PQ1), 27 | run_beam(Prob-Y, S1-PQ1, S2-PQ2), 28 | pq_total(PQ2,QMass). 29 | 30 | run_beam(WeightedAns) --> 31 | \> pq_remove(P, Thread), 32 | { findall(Stat-Ans, p_reset(beam, call(Thread,Ans), Stat), Branches), 33 | partition(\\done-_`true, Branches, Answers, Suspensions) }, 34 | ( {WeightedAns=P-Ans, member(done-Ans, Answers)} 35 | ; foldl(\\P|susp(Req,Cont)-Ans`handle(Req, Cont, P-Ans), Suspensions), 36 | run_beam(WeightedAns) 37 | ). 38 | 39 | handle(factor(P), Cont, P0-Ans) --> 40 | {P1 is P0*P}, \> pq_insert(P1,\\Ans`Cont). 41 | handle(tab(TableAs,Head), Cont, P-Ans) --> 42 | { term_variables(Head,Y), 43 | term_to_ground(Head,Var), 44 | K = (\\Y`Ans`Cont) }, 45 | ( \< rb_upd(Var, entry(V,PYs,Conts), entry(V,PYs,[P-K|Conts])) 46 | -> \> rb_fold(\\P+K|X-PX`resume(P,PX,K,X), PYs) 47 | ; {rb_empty(Empty)}, 48 | \< rb_add(Var, entry(TableAs,Empty,[P-K])), 49 | \> pq_insert(1,producer(Var,\\Y`Head)) 50 | ). 51 | handle(ans(Var,Y), _, P-_) --> 52 | \< rb_upd(Var, entry(V,Ys,Conts), entry(V,Ys2,Conts)), 53 | ( {rb_add(Y,P,Ys,Ys2)} 54 | -> \> foldl(\\P+Y|P0-K`resume(P0,P,K,Y), Conts) 55 | ; {rb_upd(Y,OldP,NewP,Ys,Ys2), NewP is max(OldP,P)}, 56 | {debug(ccbeam, 'New solution for ~p: ~p @ ~p (prev was ~p)',[Var,Y,P,OldP])} 57 | ). 58 | 59 | producer(Var,Generate,_) :- call(Generate,Y), p_shift(beam, ans(Var,Y)). 60 | resume(P0,P,K,X) --> {P1 is P0*P}, pq_insert(P1,call(K,X)). 61 | 62 | pq_empty(0-H) :- empty_heap(H). 63 | pq_insert(P,X,T1-H1,T2-H2) :- T2 is T1+P, P1 is -P, add_to_heap(H1,P1,X,H2). 64 | pq_remove(P,X,T1-H1,T2-H2) :- get_from_heap(H1,P1,X,H2), P is -P1, T2 is T1-P. 65 | pq_total(T-_,T). 66 | 67 | term_to_ground(T, G) :- copy_term_nat(T,G), numbervars(G,0,_). 68 | -------------------------------------------------------------------------------- /cclab/prolog/cctab/cctab8.pl: -------------------------------------------------------------------------------- 1 | :- module(cctab, [run_tabled/1, cctabled/1]). 2 | 3 | /** Auto-prompt tabling with table completion 4 | 5 | cctab2 modified to switch into tabling mode (context delimited by 'tab' prompt) 6 | on calling outermost tabled predicate (the 'leader'). Tables are marked 'complete' 7 | on leaving tabling mode and subsequent lookups on complete tables need no delimited 8 | context. This more or less implements the functionality of Desouter et al's library. 9 | */ 10 | :- use_module(library(delimcc), [p_reset/3, p_shift/2]). 11 | :- use_module(library(ccstate), [run_nb_state/3, set/1, get/1]). 12 | :- use_module(library(lambda1)). 13 | :- use_module(library(rbutils)). 14 | :- use_module(tabled, []). 15 | 16 | head_to_variant(Head, Variant) :- 17 | copy_term_nat(Head, Variant), 18 | numbervars(Variant, 0, _). 19 | 20 | :- meta_predicate cctabled(0). 21 | cctabled(Head) :- 22 | term_variables(Head,Y), 23 | head_to_variant(Head, Variant), 24 | get(Tabs1), 25 | ( rb_lookup(Variant, tab(Solns,Status), Tabs1) 26 | -> ( Status=complete -> rb_in(Y, _, Solns) 27 | ; p_shift(tab, cons(Variant, Y, Tabs1)) % active consumer 28 | ) 29 | ; ( rb_lookup('$tabling?', true,Tabs1) 30 | -> p_shift(tab, prod(Variant, Y, Tabs1, Head)) % active producer 31 | ; ( rb_insert(Tabs1, '$tabling?', true, Tabs2), 32 | cont_tab(susp(prod(Variant, Y, Tabs2, Head), fail), Y) 33 | ; get(Tabs2), rb_map(Tabs2, cctab:completion_map, Tabs3), 34 | set(Tabs3), rb_lookup(Variant, tab(Solns,_), Tabs3), 35 | rb_in(Y, _, Solns) 36 | ) 37 | ) 38 | ). 39 | 40 | completion_map(true,false). % Applies to '$$$' key only 41 | completion_map(tab(Solns,_), tab(Solns,complete)). 42 | 43 | run_tab(Goal, Ans) :- 44 | p_reset(tab, Goal, Status), 45 | cont_tab(Status, Ans). 46 | 47 | cont_tab(done, _). 48 | cont_tab(susp(cons(Var,Y,Tabs1), Cont), Ans) :- 49 | rb_update(Tabs1, Var, tab(Solns,Ks), tab(Solns,[\Y^Ans^Cont|Ks]), Tabs2), 50 | set(Tabs2), 51 | rb_in(Y, _, Solns), 52 | run_tab(Cont, Ans). 53 | cont_tab(susp(prod(Var,Y,Tabs1,Head), Cont), Ans) :- 54 | rb_empty(Solns), 55 | rb_insert_new(Tabs1, Var, tab(Solns,[]), Tabs2), 56 | set(Tabs2), 57 | run_tab(producer(Var, \Y^Head, \Y^Ans^Cont, Ans), Ans). 58 | 59 | producer(Variant, Generate, KP, Ans) :- 60 | call(Generate, Y1), 61 | get(Tabs1), 62 | rb_update(Tabs1, Variant, tab(Solns1, Ks), tab(Solns2, Ks), Tabs2), 63 | rb_insert_new(Solns1, Y1, t, Solns2), 64 | set(Tabs2), 65 | member(K,[KP|Ks]), 66 | call(K,Y1,Ans). 67 | 68 | :- meta_predicate run_tabled(0), run_tabled(0,-). 69 | run_tabled(Goal) :- run_tabled(Goal,_). 70 | run_tabled(Goal, FinalTables) :- 71 | rb_empty(Tables), 72 | run_nb_state(Goal, Tables, FinalTables). 73 | 74 | -------------------------------------------------------------------------------- /cclab/prolog/cctab/machines.pl: -------------------------------------------------------------------------------- 1 | :- module(machines, [ iterate/4, unfold/2, unfold_finite/2, scanner/3, scan0/4, (**)//2 2 | , (>>)/3, iterator/3, unfolder/3, mapper/3, moore/5, progress/2, subsample/3, drop/3]). 3 | 4 | :- use_module(library(dcg_progress), [seqmap_with_progress//3]). 5 | :- use_module(library(lazy), [lazy_unfold/4, lazy_unfold_finite/4]). 6 | 7 | % running machines 8 | :- meta_predicate unfold(1,-), unfold_finite(1,-), iterate(1,?,+,-). 9 | unfold(MakeMachine, Stream) :- call(MakeMachine,unfolder(T,S)), lazy_unfold(T,Stream,S,_). 10 | unfold_finite(MakeMachine, Stream) :- call(MakeMachine,unfolder(T,S)), lazy_unfold_finite(T,Stream,S,_). 11 | iterate(Setup, LPs) --> {call(Setup, Step)}, seqmap_with_progress(1,Step,LPs). 12 | 13 | % bulding unfolding predicates 14 | :- meta_predicate scanner(2,1,-), scan(2,3,-,+,-), scan0(2,?,?,?), >>(1,2,-). 15 | scanner(Sel, Setup, machines:scan(Sel, Step)) :- call(Setup,Step). 16 | scan(Sel,Trans,X,P1,P2) :- call(Trans,LP,P1,P2), call(Sel,t(LP,P1,P2),X). 17 | scan0(Trans,S1,S1,S2) :- call(Trans,S1,S2). 18 | 19 | %% >>(+P:pred(-A), +Q:pred(+A,-B), -Y:B) is det. 20 | % machine composition: generator >> transducer --> generator 21 | >>(U,T,M) :- call(U, Unfolder), call(T, Unfolder, M). 22 | 23 | % some predicates for building machings 24 | :- meta_predicate unfolder(3,?,-), mapper(2,+,-), moore(3,2,?,+,-), iterator(1,+,-). 25 | 26 | %% unfolder(+T:pred(-X,+S,-S), S0:S, -G:unfolder(X,S)) is det. 27 | unfolder(T,S,unfolder(T,S)). 28 | 29 | %% mapper(+F:pred(+X,-Y), +G:unfolder(X,S), -T:unfolder(Y,S)) is det. 30 | mapper(F, unfolder(TA,SA), unfolder(machines:map_step(TA,F), SA)). 31 | map_step(T,F,Y) --> call(T,X), {call(F,X,Y)}. 32 | 33 | %% moore(+T:pred(+X,+SB,-SB), +O:pred(+SB,-Y), S0:SB, +G:unfolder(X,SA), -G2:unfolder(Y,pair(SA-SB))) is det. 34 | moore(TB,OB,SB, unfolder(TA,SA), unfolder(machines:moore_step(TA,TB,OB), SA-SB)). 35 | moore_step(TA,TB,OB, Out, SA1-SB1, SA2-SB2) :- call(TA,OA,SA1,SA2), call(TB,OA,SB1,SB2), call(OB,SB2,Out). 36 | 37 | %% iterator(+I:pred(-pred(-X,+S,-S)), S0:S, -G:unfolder(pair(X,S),S)) is det. 38 | iterator(Setup, S0, unfolder(machines:it_step(Step),S0)) :- call(Setup,Step). 39 | it_step(Step,X-S1,S1,S2) :- call(Step,X,S1,S2). 40 | 41 | %% drop(+N:natural +G:unfolder(X,S), -T:unfolder(X,S)) is det. 42 | drop(N, unfolder(T,S0), unfolder(T,S1)) :- length(X,N), foldl(T,X,S0,S1). 43 | 44 | subsample(N, unfolder(T,S0), unfolder(skip(N,T),S0)). 45 | skip(N,T,X,S1,S2) :- length([X|Y],N), foldl(T,[X|Y],S1,S2). 46 | 47 | progress(M1,M2) :- moore(prog_step,snd,0-_,M1,M2). 48 | prog_step(X,I-_,J-X) :- J is I+1, format('~d: ~w\n',[J,X]). 49 | 50 | **(G,N) --> {var(N)} -> rep_var(N,G); rep_nonvar(N,G). 51 | rep_nonvar(N,G) --> {N=<0} -> []; {M is N-1}, call_dcg(G), rep_nonvar(M,G). 52 | rep_var(N,G) --> {N=0}; rep_var(M,G), call_dcg(G), {N is M+1}. 53 | -------------------------------------------------------------------------------- /genutils/prolog/lazy.pl: -------------------------------------------------------------------------------- 1 | :- module(lazy, 2 | [ lazy_unfold/5 3 | , lazy_unfold/4 4 | , lazy_unfold_finite/4 5 | , lazy_seqmap/5 6 | , lazy_seqmap/4 7 | , lazy_maplist/2 8 | , lazy_maplist/3 9 | , lazy_maplist/4 10 | , lazy_repeat/2 11 | , lazy/4 12 | ]). 13 | 14 | :- meta_predicate 15 | lazy_seqmap(4,?,?,?,?) 16 | , lazy_seqmap(3,?,?,?) 17 | , lazy_unfold(4,?,?,?,?) 18 | , lazy_unfold(3,?,?,?) 19 | , lazy_unfold_finite(3,?,?,?) 20 | , lazy_maplist(1,?) 21 | , lazy_maplist(2,?,?) 22 | , lazy_maplist(3,?,?,?) 23 | , lazy(3,?,?,-) 24 | . 25 | 26 | %% lazy(+P:pred(+A,+B,-C), X:A, Y:B, -Z:C) is det 27 | % Lazy version of call/4, triggered when Z is needed. Goal 28 | % expansion version allows macro expansion of call(P, ...). 29 | lazy(P,X,Y,Z) :- freeze(Z,call(P,X,Y,Z)). 30 | user:goal_expansion(lazy(P,X,Y,Z), freeze(Z,call(P,X,Y,Z))). 31 | 32 | %% lazy_unfold( +P:pred(-A1,-A2,+S,-S), -XX1:list(A1), -XX2:list(A2), +S1:S, -S2:S) is det. 33 | %% lazy_unfold( +P:pred(-A1,+S,-S), -XX1:list(A1), +S1:S, -S2:S) is det. 34 | % 35 | % Lazily unfold an infinite stream 36 | lazy_unfold(P,[X1|XX],[Y1|YY],S1,S3) :- 37 | call(P,X1,Y1,S1,S2), 38 | freeze(YY,lazy:lazy_unfold(P,XX,YY,S2,S3)). 39 | 40 | lazy_unfold(P,[X1|XX],S1,S3) :- 41 | call(P,X1,S1,S2), 42 | freeze(XX,lazy:lazy_unfold(P,XX,S2,S3)). 43 | 44 | %% lazy_unfold_finite( +P:pred(-A1,+S,-S), -XX1:list(A1), +S1:S, -S2:S) is det. 45 | % Lazily unfold a finite list or infinite stream. If unfolding predicate fails, 46 | % then a finite list is produced. 47 | lazy_unfold_finite(P,Xs,S1,S3) :- 48 | ( call(P,X1,S1,S2) 49 | -> Xs=[X1|XX], freeze(XX,lazy:lazy_unfold_finite(P,XX,S2,S3)) 50 | ; Xs=[] 51 | ). 52 | 53 | %% lazy_seqmap( +P:pred(A1,A2,S,S), +XX1:list(A1), -XX2:list(A2), S1:S, S2:S) is det. 54 | %% lazy_seqmap( +P:pred(A1,A2,S,S), -XX1:list(A1), -XX2:list(A2), S1:S, S2:S) is nondet. 55 | %% lazy_seqmap( +P:pred(A1,S,S), -XX1:list(A1), S1:S, S2:S) is nondet. 56 | % 57 | % Lazy versions of dcg_core:seqmap//{2,3} - can succeed for any lenght of list. 58 | % Computation is frozen on last list, which is to be understood as an 'output'. 59 | lazy_seqmap(_,[],[],S,S). 60 | lazy_seqmap(P,[X1|XX],[Y1|YY],S1,S3) :- 61 | call(P,X1,Y1,S1,S2), 62 | freeze(YY,lazy:lazy_seqmap(P,XX,YY,S2,S3)). 63 | 64 | lazy_seqmap(_,[],S,S). 65 | lazy_seqmap(P,[X1|XX],S1,S3) :- 66 | call(P,X1,S1,S2), 67 | freeze(XX,lazy:lazy_seqmap(P,XX,S2,S3)). 68 | 69 | lazy_maplist(P,[X|XX]) :- call(P,X), freeze(XX,lazy:lazy_maplist(P,XX)). 70 | lazy_maplist(_,[]). 71 | 72 | lazy_maplist(P,[X|XX],[Y|YY]) :- call(P,X,Y), freeze(YY,lazy:lazy_maplist(P,XX,YY)). 73 | lazy_maplist(_,[],[]). 74 | 75 | lazy_maplist(P,[X|XX],[Y|YY],[Z|ZZ]) :- call(P,X,Y,Z), freeze(ZZ,lazy:lazy_maplist(P,XX,YY,ZZ)). 76 | lazy_maplist(_,[],[],[]). 77 | 78 | lazy_repeat(X,[X|L]) :- freeze(L,lazy:lazy_repeat(X,L)). 79 | -------------------------------------------------------------------------------- /plumdrum/prolog/humdrum/dynam.pl: -------------------------------------------------------------------------------- 1 | /* Part of plumdrum 2 | Copyright 2012-2015 Samer Abdallah (Queen Mary University of London; UCL) 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | :- module(dynam, []). 20 | 21 | /** dynam spine format for Humdrum 22 | 23 | This module provides the humdrum hook predicate humdrum:hum_data_hook//2 24 | to enable parsing of the dynam and db spine type. 25 | 26 | The dynam interpretation provides the following data term type: 27 | == 28 | dynam ---> st(loudness) % marking, forte, piano etc 29 | ; dy(progress, process) 30 | ; ed(editorial) 31 | ; rest 32 | ; accent 33 | ; subito 34 | ; sforz. 35 | 36 | loudness ---> mf % mezzoforte 37 | ; mp % mezzopiano 38 | ; f(N:natural) % N forte marks 39 | ; p(N:natural) % N piano marks. 40 | progress ---> begin; cont; end. 41 | process ---> crescendo; diminuendo. 42 | editorial ---> explicit; published. 43 | == 44 | 45 | The db interpretation simply produces floating point numbers 46 | encoding loudness in decibels. 47 | == 48 | db == float. 49 | == 50 | */ 51 | 52 | :- use_module(library(dcg_core)). 53 | :- use_module(library(dcg_macros)). 54 | :- use_module(library(humdrum)). 55 | :- use_module(library(humdrum/humutils)). 56 | 57 | :- set_prolog_flag(double_quotes,codes). 58 | 59 | humdrum:hum_data_hook(dynam,Sigs) --> !, seqmap(dynam,Sigs). 60 | humdrum:hum_data_hook(db,DB) --> !, float(DB). 61 | 62 | dynam(st(f(N))) --> "f", !, rep_shared(M,"f"), {succ(M,N)}. 63 | dynam(st(p(N))) --> "p", !, rep_shared(M,"p"), {succ(M,N)}. 64 | dynam(st(mf)) --> "mf". 65 | dynam(st(mp)) --> "mp". 66 | 67 | dynam(rest) --> "r". 68 | dynam(accent) --> "v". 69 | dynam(subito) --> "s". 70 | dynam(sforz) --> "z". 71 | 72 | dynam(ed(explicit)) --> "X". 73 | dynam(ed(published)) --> "x". 74 | 75 | dynam(dy(begin,crescendo)) --> "<". 76 | dynam(dy(cont,crescendo)) --> "(". 77 | dynam(dy(end,crescendo)) --> "[". 78 | dynam(dy(begin,diminuendo)) --> ">". 79 | dynam(dy(cont,diminuendo)) --> ")". 80 | dynam(dy(end,diminuendo)) --> "]". 81 | 82 | -------------------------------------------------------------------------------- /sparkle/README: -------------------------------------------------------------------------------- 1 | This package provides a more natural (from a Prolog point of view) interface 2 | to SPARQL endpoints. There are two layers. The first, lower layer, defines a 3 | DCG for generating SPARQL queries from a structured term. The second provides 4 | a translation from representation that looks more or less like a Prolog goal 5 | built from rdf/3 goals (with conjunction, disjunction etc) to a term in the 6 | term language understood by the SPARQL DCG. 7 | 8 | In addition, the library provides a mechanism to register known SPARQL endpoints 9 | so that they can be referred to by a short name, or to enable a query to be 10 | run against all registered endpoints. 11 | 12 | The library is based on the idea implemented in Yves Raimond's swic package, 13 | but the code has been completely re-implemented. 14 | 15 | ---++++ Prerequisites 16 | 17 | You just need SWI Prolog with its Semantic Web libraries. 18 | 19 | ---++++ Simple usage 20 | 21 | The (??)/2 and (??)/1 operators have a high precedence so that conjuction and disjunctive 22 | queries can be written to the right of it without parentheses. 23 | == 24 | ?- rdf_register_prefix(foaf,'http://xmlns.com/foaf/0.1/') 25 | ?- rdf_register_prefix(dbont,'http://dbpedia.org/ontology/') 26 | ?- sparql_endpoint( dbp, 'http://dbpedia.org/sparql/'). 27 | ?- debug(sparkle). % to show queries 28 | 29 | ?- dbp ?? rdf(Class,rdf:type,owl:'Class'), rdf(Instance,rdf:type,Class). 30 | ?- dbp ?? rdf(Person,rdf:type,foaf:'Person'), 31 | rdf(Person,foaf:Name,Name), 32 | filter(regex('Colt.*',Name)). 33 | ?- dbp ?? rdf(A,rdf:type,dbont:'Photographer'); rdf(A, rdf:type, dbont:'MusicalArtist'). 34 | == 35 | 36 | ---++++ Change log 37 | 38 | 0.0.8: concurrent_or/3 moved to separate module, fixes to concurrent_or/3. 39 | 40 | 0.0.7: More documentation. Renamed endpoint_query/3 to query_sparql/3. 41 | Non-autopaged queries now use sparkle:limit setting for default limit to 42 | avoid getting huge amounts of data when no limit is supplied. 43 | 44 | New in version 0.0.6: both (??)/2 and query_goal/3 can accept a variable 45 | as an endpoint. If this is the case, then multiple queries are made in parallel. 46 | Each successful result binds the endpoint variable to the source of that data, eg 47 | == 48 | EP ?? rdf(Class,rdf:type,owl:'Class'). 49 | == 50 | will bind Class to all known classes and EP to the endpoint which reported that class. 51 | If the same bindings can be returned from several endpoints, then (??)/2 will produce 52 | those binding multiple times, with EP bound to different values each time, even if the 53 | query reduces to an ASK SPARQL query. It's up to you to use once/1 etc as necessary 54 | if this is not the behaviour you want. 55 | 56 | Also new in 0.0.6, autopaged queries, that is, you can forget about OFFSET and LIMIT; 57 | multiple queries will be made as necessary to fetch data on demand. The default 58 | batch size is determined by the sparkle:limit setting. 59 | 60 | 61 | -------------------------------------------------------------------------------- /cclab/prolog/ccbeam/test_beam.pl: -------------------------------------------------------------------------------- 1 | :- module(test_prob, []). 2 | 3 | :- use_module(library(data/pair), [pair/3]). 4 | :- use_module(library(ccstate), [run_nb_state/3, app/1, run_ref/1, run_env/1, env_new/2, env_app/2, env_upd/3, env_get/2]). 5 | :- use_module(library(lambda2)). 6 | :- use_module(ccbeam2). 7 | 8 | :- set_prolog_flag(back_quotes, symbol_char). 9 | 10 | 11 | :- initialization module(test_prob), 12 | set_prolog_flag(back_quotes, symbol_char). 13 | 14 | % ---- test programs ----- 15 | choose(Xs,X) :- 16 | length(Xs,N), P is 1/N, 17 | maplist(pair(P),Xs,Dist), 18 | dist(Dist,X). 19 | dist(Ps,Xs,X) :- 20 | maplist(pair,Ps,Xs,PXs), 21 | dist(PXs,X). 22 | 23 | test0(r(X)) :- choose([1,2,3],X). 24 | 25 | test(Z) :- 26 | dist([0.2,0.5,0.3], [1,2,3],X), 27 | dist([0.4,0.4,0.2], [a(X),b(X),c(X)],Y), 28 | dist([0.1,0.5,0.4], [Y-x, Y-y, Y-z],Z1), 29 | dist([0.3,0.4,0.3], [Z1-u, Z1-v, Z1-w],Z). 30 | 31 | markov(0,_,[]). 32 | markov(N,Y,[X|Xs]) :- 33 | succ(M,N), 34 | trans(Y,X), 35 | markov(M,X,Xs). 36 | 37 | hmm(_,0-_,[]). 38 | hmm(HMM,N-Y,[X|Xs]) :- 39 | succ(M,N), 40 | trans(Y,Z), 41 | obs(Z,X), 42 | call(HMM,M-Z,Xs). 43 | 44 | trans(_,X) :- choose([a,b],X). 45 | obs(_,X) :- choose([x,y,z],X). 46 | 47 | link(a,X) :- choose([b,c],X). 48 | link(b,d). 49 | link(c,X) :- choose([d,m],X). 50 | link(d,X) :- choose([e,f],X). 51 | link(e,g). 52 | link(f,X) :- choose([g,k],X). 53 | link(g,h). 54 | link(h,X) :- choose([i,j],X). 55 | link(i,_) :- fail_. 56 | link(j,_) :- fail_. 57 | link(k,l). 58 | link(l,_) :- fail_. 59 | link(m,_) :- fail_. 60 | 61 | 62 | link(w,X) :- dist([0.75-x,0.25-y],X). 63 | link(x,X) :- dist([0.5-v,0.5-z],X). 64 | link(y,z). 65 | link(z,X) :- dist([0.5-t, 0.5-u],X). 66 | link(t,_) :- fail_. 67 | link(u,_) :- fail_. 68 | link(v,_) :- fail_. 69 | % link(z,z). 70 | 71 | bernoulli(P,X) :- NP is 1 - P, dist([NP-0,P-1],X). 72 | id --> []. 73 | 74 | % left and right recursive grammar 75 | sent(S,L1,L2) :- choose([b,l,r],A), sentx(A,S,L1,L2). 76 | sentx(b,_) --> word. 77 | sentx(r,S) --> call(S), out(not). 78 | sentx(l,S) --> out(really), call(S). 79 | 80 | word --> {choose([cool,wicked],W)}, out(W). 81 | 82 | out(_,[],_) :- !, fail_. 83 | out(W,[X|T],T) :- W=X -> true; fail_. 84 | 85 | % incomplete recursive form 86 | pathr(P) --> link, {choose(['B','R'],Q)}, maybe_rec(Q,P). 87 | pathl(P) --> {dist([0.6-'B',0.4-'R'],Q)}, maybe_rec(Q,P), link. 88 | % pathl(P) --> link. 89 | 90 | maybe_rec('B',_) --> []. 91 | maybe_rec('R',P) --> call(P). 92 | 93 | test_path(l, Start, End) :- test_path(pathl(P), P, Start, End). 94 | test_path(r, Start, End) :- test_path(pathr(P), P, Start, End). 95 | test_path(Inc, Complete, Start, End) :- 96 | memo_prob(Inc, Complete), 97 | call(Complete, Start, End). 98 | 99 | test_left_grammar(In,Tail) :- 100 | memo_prob(sent(S),S), 101 | call(S,In,Tail). 102 | 103 | user:portray(F) :- float(F), !, format('~3g',[F]). 104 | -------------------------------------------------------------------------------- /cclab/prolog/cclazy/ccvmemo.pl: -------------------------------------------------------------------------------- 1 | :- module(ccvmemo, [run_ltree/2, choose/2, guard/1, cctabled/1, get_tables/1]). 2 | 3 | /** Nondeterminism as a lazy search tree with recursive memoisation of multiple variants 4 | 5 | This is like ccmemo, but instead of memoising binary predicates (Input -> Output), it 6 | handles predicates of any arity with separate tables for each calling pattern. 7 | */ 8 | 9 | :- use_module(library(rbutils)). 10 | :- use_module(library(typedef)). 11 | :- use_module(library(delimcc), [pr_reset/3, pr_shift/2, p_shift/2]). 12 | :- use_module(library(ccstate), [app/1, upd/2, app/2, run_state/4, get/1]). 13 | :- use_module(library(lambda1)). 14 | 15 | :- type tree(A) ---> leaf(A); node(list(tree(A))). 16 | :- type ltree(A) ---> leaf(A); lnode(pred(list(ltree(A)))). 17 | :- type ltree(L,A) ---> leaf(A); lnode(L,pred(list(ltree(A)))). % with labelled nodes 18 | 19 | :- meta_predicate cctabled(0). 20 | cctabled(Head) :- pr_shift(nondet, mem(Head)), app(expl, ccvmemo:phrase([Head])). % weird context bug 21 | choose(Xs,X) :- pr_shift(nondet, choose(Xs,X)), app(expl, phrase([Xs>X])). 22 | 23 | :- meta_predicate guard(0). 24 | guard(P) :- call(P) -> true; pr_shift(nondet, fail). 25 | 26 | get_tables(Tabs1) :- get(Tabs), rb_fold(sanitize,Tabs,Tabs1,[]). 27 | sanitize(Var-entry(Solns,_)) --> [Var-Expls], {rb_visit(Solns,Expls)}. 28 | 29 | %% run_ltree(+P:pred, -T:ltree(list(any))) is det. 30 | :- meta_predicate run_ltree(0,-). 31 | run_ltree(Goal,Result) :- 32 | term_variables(Goal, Ans), 33 | pr_reset(nondet, \leaf(Ans->Expl)^run_state(expl, Goal, Expl, []), Result). 34 | 35 | choose(Xs,X,K,lnode(choice(Xs),ccvmemo:maplist(expand1(\X^K),Xs))). 36 | fail(_,lnode(fail,=([]))). 37 | 38 | mem(Head,K,Tree) :- 39 | term_variables(Head,Y), 40 | head_to_variant(Head, Variant), 41 | YK = \Y^K, 42 | upd(Tabs1, Tabs2), 43 | ( rb_update(Tabs1, Variant, entry(Ys,Ks), entry(Ys,[YK|Ks]), Tabs2) 44 | -> Tree = lnode(cons(Variant,Ys), ccvmemo:rb_fold(cons_expand1(YK),Ys,[])) 45 | ; rb_empty(EmptySet), 46 | rb_insert_new(Tabs1, Variant, entry(EmptySet,[]), Tabs2), 47 | run_state(expl, call(\Y^Head, YNew), Expl, []), % !!! open tail? 48 | app(rb_upd(Variant, entry(Ys,Ks), entry(Ys2,Ks))), 49 | ( rb_insert_new(Ys,YNew,[Expl],Ys2) 50 | -> Tree=lnode(prod(Variant,YNew),ccvmemo:maplist(send_to_cont(YNew),[YK|Ks])) 51 | ; rb_update(Ys,YNew,Expls,[Expl|Expls],Ys2), 52 | Tree=lnode(dup(Variant,YNew),=([])) 53 | ) 54 | ). 55 | 56 | cons_expand1(Kx,X-_,S,[Y|S]) :- expand1(Kx,X,Y). 57 | expand1(Kx,X,Y) :- pr_reset(nondet, call(Kx,X), Y). 58 | send_to_cont(Y,Ky,T) :- pr_reset(nondet, call(Ky,Y), T). 59 | 60 | head_to_variant(Head, Variant) :- 61 | copy_term_nat(Head, Variant), 62 | numbervars(Variant, 0, _). 63 | 64 | % for printing annotated search trees 65 | user:portray(choice(Xs)) :- write('?'), write(Xs). 66 | user:portray(cons(_:X,Ys)) :- rb_keys(Ys,Vals), write('C':X>Vals). 67 | user:portray(dup(_:X,Y)) :- write('D':X>Y). 68 | user:portray(prod(_:X,Y)) :- write('P':X>Y). 69 | 70 | -------------------------------------------------------------------------------- /cclab/prolog/cclazy/test_vmemo.pl: -------------------------------------------------------------------------------- 1 | :- module(test_vmemo, []). 2 | 3 | /** Test variant memoisation with explanation graphs 4 | Eg try this: 5 | == 6 | ?- explore_ltree(pathl(a,K), print_and_dump). 7 | == 8 | */ 9 | :- use_module(library(tabling)). 10 | :- use_module(library(math)). 11 | :- use_module(library(ccstate), [run_state/3]). 12 | :- use_module(library(lambda1)). 13 | :- use_module(ccvmemo, [guard/1, choose/2, run_ltree/2, cctabled/1, get_tables/1]). 14 | :- use_module(library(ccmacros)). 15 | :- use_module(treeutils). 16 | 17 | 18 | % -------------- calling stateful nondeterminism ------ 19 | 20 | explore_ltree(Goal, Explore) :- 21 | rb_empty(Empty), 22 | run_state(generate_explore(Goal, Explore), Empty, _). 23 | 24 | generate_explore(Goal, Explore) :- 25 | run_ltree(Goal, Tree), 26 | call(Explore, Tree). 27 | 28 | print_and_dump(T) :- 29 | print_ltree(T), 30 | get_tables(Ts), 31 | maplist(print_variant,Ts). 32 | 33 | print_variant(Var-Solns) :- pprintln('',Var), maplist(print_soln,Solns). 34 | print_soln(Y-Expls) :- pprintln(' ',Y), maplist(pprintln(' '),Expls). 35 | pprintln(Pref,X) :- write(Pref), print(X), nl. 36 | 37 | :- module(test_vmemo). 38 | 39 | % ---- test programs ----- 40 | test(Z) :- 41 | choose([1,2,3],X), 42 | choose([a(X),b(X),c(X)],Y), 43 | choose([Y-x, Y-y, Y-z],Z1), 44 | choose([Z1-u, Z1-v, Z1-w],Z). 45 | 46 | link(a,X) :- choose([b,c],X). 47 | link(b,d). 48 | link(c,X) :- choose([d,m],X). 49 | link(d,X) :- choose([e,f],X). 50 | link(e,g). 51 | link(f,X) :- choose([g,k],X). 52 | link(g,h). 53 | link(h,X) :- choose([i,j],X). 54 | link(i,X) :- choose([],X). 55 | link(j,X) :- choose([],X). 56 | link(k,l). 57 | link(l,X) :- choose([],X). 58 | link(m,X) :- choose([],X). 59 | 60 | link(N,M) :- 61 | number(N), 62 | guard(between(-5,5,N)), 63 | choose([-1,1],D), 64 | M is N+D. 65 | 66 | link(w,X) :- choose([x,y],X). 67 | link(x,z). 68 | link(y,z). 69 | link(z,X) :- choose([],X). 70 | % link(z,z). 71 | 72 | id --> []. 73 | 74 | sent(S1,S2) :- cctabled(sent_(S1,S2)). 75 | 76 | % left and right recursive grammar 77 | sent_(L1,L2) :- choose([b,l,r],A), sentx(A,L1,L2). 78 | sentx(b) --> word. 79 | sentx(r) --> sent, out(not). 80 | sentx(l) --> out(really), sent. 81 | 82 | word --> {choose([cool,wicked],W)}, out(W). 83 | 84 | out(_,[],_) :- !, guard(false). 85 | out(W,[X|T],T) :- guard(W=X). 86 | 87 | % incomplete recursive form 88 | 89 | :- cctable pathr//0, pathl//0. 90 | 91 | pathr --> link, {choose(['B','R'],Q)}, maybe_rec(Q,pathr). 92 | pathl --> {choose(['B','R'],Q)}, maybe_rec(Q,pathl), link. 93 | 94 | maybe_rec('B',_) --> []. 95 | maybe_rec('R',P) --> call(P). 96 | 97 | 98 | make_fib(Fib) :- Fib = cctabled(fib_inc(Fib)). % ha 99 | 100 | fib_inc(_,0,1) :- !. 101 | fib_inc(_,1,1) :- !. 102 | fib_inc(Fib,N,X) :- 103 | succ(M,N), call(Fib,M,Y), 104 | succ(L,M), call(Fib,L,Z), 105 | X is Y+Z. 106 | 107 | test_fib(Fib,Goal) :- 108 | make_fib(Fib), 109 | call(Goal). 110 | -------------------------------------------------------------------------------- /cclab/prolog/cctab/cctab9.pl: -------------------------------------------------------------------------------- 1 | :- module(cctab, [run_tabled/1, cctabled/1]). 2 | 3 | /** Auto-prompt tabling with table completion 4 | 5 | cctab2 modified to switch into tabling mode (context delimited by 'tab' prompt) 6 | on calling outermost tabled predicate (the 'leader'). Tables are marked 'complete' 7 | on leaving tabling mode and subsequent lookups on complete tables need no delimited 8 | context. This more or less implements the functionality of Desouter et al's library. 9 | 10 | Variation on cctab8 - more stuff in cctabled/1, less in shift-handler 11 | */ 12 | :- use_module(library(delimcc), [p_reset/3, p_shift/2]). 13 | :- use_module(library(ccstate), [run_nb_state/3, set/1, get/1]). 14 | :- use_module(library(rbutils)). 15 | :- use_module(library(lambda1)). 16 | :- use_module(tabled, []). 17 | 18 | head_to_variant(Head, Variant) :- 19 | copy_term_nat(Head, Variant), 20 | numbervars(Variant, 0, _). 21 | 22 | :- meta_predicate cctabled(0). 23 | cctabled(Head) :- 24 | term_variables(Head,Y), 25 | head_to_variant(Head, Variant), 26 | get(Tabs1), 27 | ( rb_lookup(Variant, tab(Solns,Status), Tabs1) 28 | -> ( Status=complete -> rb_in(Y, _, Solns) 29 | ; p_shift(tab, cons(Variant, Y, Tabs1)) % active consumer 30 | ) 31 | ; rb_empty(Empty), % initialise producer 32 | rb_insert_new(Tabs1, Variant, tab(Empty,[]), Tabs2), 33 | ( rb_lookup('$tabling?', true,Tabs2) 34 | -> set(Tabs2), p_shift(tab, prod(Variant, Y, Head)) % prompt already there 35 | ; rb_insert(Tabs2, '$tabling?', true, Tabs3), set(Tabs3), 36 | ( run_tab(producer(Variant, \Y^Head, \Y^Y^fail, Y), Y) % delimit top producer 37 | ; completed_table(Variant, Solns), % top producer is failure driven 38 | rb_in(Y, _, Solns) 39 | ) 40 | ) 41 | ). 42 | 43 | completed_tables(Variant, Solns) :- 44 | get(Tabs1), rb_map(Tabs1, cctab:completion_map, Tabs2), 45 | set(Tabs2), rb_lookup(Variant, tab(Solns,_), Tabs2). 46 | 47 | completion_map(true,false) : -!. % Applies to '$tabling?' key only 48 | completion_map(tab(Solns,_), tab(Solns,complete)). 49 | 50 | run_tab(Goal, Ans) :- 51 | p_reset(tab, Goal, Status), 52 | cont_tab(Status, Ans). 53 | 54 | cont_tab(done, _). 55 | cont_tab(susp(cons(Var,Y,Tabs1), Cont), Ans) :- 56 | rb_update(Tabs1, Var, tab(Solns,Ks), tab(Solns,[\Y^Ans^Cont|Ks]), Tabs2), 57 | set(Tabs2), 58 | rb_in(Y, _, Solns), 59 | run_tab(Cont, Ans). 60 | cont_tab(susp(prod(Var,Y,Head), Cont), Ans) :- 61 | run_tab(producer(Var, \Y^Head, \Y^Ans^Cont, Ans), Ans). 62 | 63 | producer(Variant, Generate, KP, Ans) :- 64 | call(Generate, Y1), 65 | get(Tabs1), 66 | rb_update(Tabs1, Variant, tab(Solns1, Ks), tab(Solns2, Ks), Tabs2), 67 | rb_insert_new(Solns1, Y1, t, Solns2), 68 | set(Tabs2), 69 | member(K,[KP|Ks]), 70 | call(K,Y1,Ans). 71 | 72 | :- meta_predicate run_tabled(0), run_tabled(0,-). 73 | run_tabled(Goal) :- run_tabled(Goal,_). 74 | run_tabled(Goal, FinalTables) :- 75 | rb_empty(Tables), 76 | run_nb_state(Goal, Tables, FinalTables). 77 | 78 | -------------------------------------------------------------------------------- /cclab/prolog/ccbeam/ccbeam2.pl: -------------------------------------------------------------------------------- 1 | :- module(ccbeam, [memo_prob/2, lazy_beam/2, dist/2, fail_/0]). 2 | 3 | /** Probabilistic choice with beam search to find most probable paths 4 | 5 | Simple search using a priority queue to manage threads 6 | With memoisation. No limit on number of threads. 7 | 8 | */ 9 | 10 | :- use_module(library(clpr)). 11 | :- use_module(library(rbutils)). 12 | :- use_module(library(typedef)). 13 | :- use_module(library(dcg_pair)). 14 | :- use_module(library(data/store)). 15 | :- use_module(library(math), [mul/3]). 16 | :- use_module(library(lazy), [lazy_unfold_finite//2]). 17 | :- use_module(library(delimcc), [p_reset/3, p_shift/2]). 18 | :- use_module(library(ccstate), [get/1, set/1, run_state/3, upd/2, ref_new/2, ref_get/2, ref_app/2, ref_upd/3]). 19 | :- use_module(library(lambda2)). 20 | :- use_module(pack(pha/prolog/library/priorityq)). 21 | 22 | :- set_prolog_flag(back_quotes, symbol_char). 23 | 24 | :- type weighted(A) ---> number - A. 25 | :- type dist(A) == list(weighted(A)). 26 | 27 | :- meta_predicate memo_prob(2,-). 28 | memo_prob(P, ccbeam:memf(P,R)) :- p_shift(beam, new(R)). 29 | 30 | memf(P,R,X,Y) :- p_shift(beam, mem(P,R,X,Y)). 31 | dist(Xs,X) :- p_shift(beam, dist(Xs,X)). 32 | fail_ :- p_shift(beam, dist([],_)). 33 | 34 | :- meta_predicate lazy_beam(1,-). 35 | lazy_beam(Pred,Stream) :- 36 | store_new(S1), proc_init(1,Pred,PQ1), 37 | lazy_unfold_finite(run_beam,Stream,S1-PQ1,_). 38 | 39 | run_beam(Ans) --> 40 | \> proc_remove(P, Thread), 41 | {p_reset(beam, call(Thread,Y), Status)}, 42 | cont_beam(Status, P-Y, Ans). 43 | 44 | cont_beam(done, PrX, PrX) --> []. 45 | cont_beam(susp(Req, Cont), PY, Ans) --> 46 | handle(Req, Cont, PY), 47 | run_beam(Ans). 48 | 49 | handle(dist(Xs,X), Cont, Pr-Y) --> 50 | \> foldl(insert(\\X`Y`Cont, Pr), Xs). 51 | handle(new(R), Cont, Pr-Y) --> 52 | {rb_empty(T)}, 53 | store_add(T,R) <\> proc_insert(Pr,\\Y`Cont). 54 | handle(mem(Pred,R,X,Z), Cont, Pr-Y) --> 55 | {K = (\\Z`Y`Cont)}, 56 | \< store_upd(R,Tab,Tab1), 57 | ( {rb_upd(X, entry(Ys,Conts), entry(Ys,[Pr-K|Conts]), Tab, Tab1)} 58 | -> \> rb_fold(insert_(K,Pr),Ys) 59 | ; {rb_empty(EmptyDist), 60 | rb_add(X, entry(EmptyDist,[Pr-K]), Tab, Tab1) }, 61 | \> proc_insert(1,producer(Pred,R,X)) 62 | ). 63 | handle(ans(R,X,Z), _, Pr-_) --> 64 | \< store_apply(R, rb_upd(X, entry(Zs,Conts), entry(Zs2,Conts))), 65 | ( {rb_add(Z,Pr,Zs,Zs2)} 66 | -> \> foldl(resume(Pr,Z), Conts) 67 | ; {NewP = OldP+Pr, rb_upd(Z,OldP,NewP,Zs,Zs2)} 68 | ). 69 | 70 | producer(P,R,X,_) :- call(P,X,Y), p_shift(beam, ans(R,X,Y)). 71 | insert(K, P0, P-X) --> resume(P0,P,K,X). 72 | insert_(K, P0, X-P) --> resume(P0,P,K,X). 73 | resume(P, X, P0-K) --> resume(P0,P,K,X). 74 | 75 | resume(P0,P,K,X) --> {P1 is P0*P}, proc_insert(P1,call(K,X)). 76 | 77 | proc_init(P,T,P-PQ1) :- pq_empty(PQ0), pq_insert(P,T,PQ0,PQ1). 78 | proc_insert(P,Th,T1-Q1,T2-Q2) :- pq_insert(P,Th,Q1,Q2), T2 is T1+P. 79 | proc_remove(P,Th,T1-Q1,T2-Q2) :- pq_remove(P,Th,Q1,Q2), T2 is T1-P. 80 | proc_empty(_-Q) :- pq_empty(Q). 81 | proc_stats(T,S,T-Q,T-Q) :- pq_size(Q,S). 82 | -------------------------------------------------------------------------------- /cclab/prolog/cctab/cctab5.pl: -------------------------------------------------------------------------------- 1 | :- module(cctab, [sanitise/2, run_tabled/1, run_tabled/2, cctabled/1]). 2 | 3 | /** Tabling with table completion [broken] 4 | 5 | The idea here was, when a producer has finished producing solutions, its 6 | associated table is marked 'complete' and any consumer continuations 7 | discarded. This does not work properly when there is a co-recursive system 8 | of predicates, because a producer thread can be suspended when it becomes 9 | a consumer of another tabled predicate. This looks like failure, and so the 10 | producer table is closed even though its continuation is still active as 11 | a consumer of another predicate. When that predicate yields a new answer, 12 | it is delivered to the original producer which may then produce its own 13 | new solutions, but then fails to distribute them to its own consumers because 14 | these have been discarded. The same problem afflicts cctab6. 15 | */ 16 | 17 | :- use_module(library(rbutils)). 18 | :- use_module(library(dcg_core), [out//1]). 19 | :- use_module(library(data/pair), [fst/2, fsnd/3]). 20 | :- use_module(library(callutils), [mr/5]). 21 | :- use_module(library(delimcc), [p_reset/3, p_shift/2]). 22 | :- use_module(library(ccstate), [run_nb_state/3, app/1, set/1, get/1]). 23 | :- use_module(library(lambda1)). 24 | :- use_module(tabled, []). 25 | 26 | head_to_variant(Head, Variant) :- 27 | copy_term_nat(Head, Variant), 28 | numbervars(Variant, 0, _). 29 | 30 | :- meta_predicate cctabled(0). 31 | cctabled(Head) :- p_shift(tab, Head). 32 | 33 | run_tab(Goal, Ans) :- 34 | p_reset(tab, Goal, Status), 35 | cont_tab(Status, Ans). 36 | 37 | cont_tab(done, _). 38 | cont_tab(susp(Head, Cont), Ans) :- 39 | term_variables(Head,Y), K= \Y^Ans^Cont, 40 | head_to_variant(Head, Variant), 41 | get(Tabs1), 42 | ( rb_update(Tabs1, Variant, tab(Solns,Status1), tab(Solns,Status2), Tabs2) 43 | -> ( Status1=active(Ks) 44 | -> Status2=active([K|Ks]), set(Tabs2) 45 | ; Status2=complete 46 | ), 47 | rb_in(Y, _, Solns), 48 | run_tab(Cont, Ans) 49 | ; rb_empty(Solns), 50 | rb_insert_new(Tabs1, Variant, tab(Solns,active([])), Tabs2), 51 | set(Tabs2), 52 | ( run_tab(producer(Variant, \Y^Head, K, Ans), Ans) 53 | ; app(rb_upd(Variant, tab(Ss,_), tab(Ss,complete))), fail 54 | ) 55 | ). 56 | 57 | producer(Variant, Generate, KP, Ans) :- 58 | call(Generate, Y1), 59 | app(add_soln(Variant, Y1, active(Ks))), 60 | member(K,[KP|Ks]), 61 | call(K,Y1,Ans). 62 | 63 | add_soln(Variant, Y1, Status, Tabs1, Tabs2) :- 64 | rb_update(Tabs1, Variant, tab(Solns1, Status), tab(Solns2, Status), Tabs2), 65 | rb_insert_new(Solns1, Y1, t, Solns2). 66 | 67 | :- meta_predicate run_tabled(0), run_tabled(0,-). 68 | run_tabled(Goal) :- run_tabled(Goal,_). 69 | run_tabled(Goal, FinalTables) :- 70 | rb_empty(Tables), 71 | term_variables(Goal, Ans), 72 | run_nb_state(run_tab(Goal, Ans), Tables, FinalTables). 73 | 74 | sanitise(Tabs1, Tabs2) :- rb_fold(mr(fsnd(clean_tab), out), Tabs1, Tabs2, []). 75 | clean_tab(tab(Solns,Status), Stat-Solns1) :- functor(Status,Stat,_), rb_fold(mr(fst,out), Solns, Solns1, []). 76 | -------------------------------------------------------------------------------- /dcgutils/prolog/dcg_progress.pl: -------------------------------------------------------------------------------- 1 | /* Part of dcgutils 2 | Copyright 2012-2015 Samer Abdallah (Queen Mary University of London; UCL) 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | :- module(dcg_progress, [ 20 | seqmap_with_progress//3 21 | , seqmap_with_progress//4 22 | , stats/0 23 | , stats/1 24 | ]). 25 | 26 | :- meta_predicate 27 | seqmap_with_progress(+,3,+,?,?), 28 | seqmap_with_progress(+,4,+,?,?,?). 29 | 30 | %% seqmap_with_progress( +Period:natural, +Pred:pred(A,S,S), +X:list(A))// is nondet. 31 | %% seqmap_with_progress( +Period:natural, +Pred:pred(A,B,S,S), +X:list(A), ?Y:list(B))// is nondet. 32 | % 33 | % Just like seqmap//2 and seqmap//3 but prints progress and memory usage statistics while running. 34 | % Information is printed every Period iterations. The first input list must be 35 | % valid list skeleton with a definite length, so that a percentage progress indicator 36 | % can be printed. 37 | seqmap_with_progress(E,P,X) --> {progress_init(E,X,Pr0)}, smp(X,P,Pr0). 38 | seqmap_with_progress(E,P,X,Y) --> {progress_init(E,X,Pr0)}, smp(X,Y,P,Pr0). 39 | 40 | smp([],_,Pr) --> !, {progress_finish(Pr)}. 41 | smp([X|XX],P,Pr1) --> {progress_next(Pr1,Pr2)}, call(P,X), !, smp(XX,P,Pr2). 42 | 43 | smp([],_,_,Pr) --> !, {progress_finish(Pr)}. 44 | smp([X|XX],[Y|YY],P,Pr1) --> {progress_next(Pr1,Pr2)}, call(P,X,Y), !, smp(XX,YY,P,Pr2). 45 | 46 | 47 | progress_init(E,X,pr(T0,T,E,0,0)) :- length(X,T), get_time(T0). 48 | progress_finish(Pr) :- 49 | progress_next(Pr,_), 50 | get_time(T1), Pr=pr(T0,N,_,_,_), 51 | format('\nFinished ~w items in ~3g minutes.\n',[N,(T1-T0)/60]). 52 | 53 | progress_next(pr(T0,Total,E,N,E),pr(T0,Total,E,M,1)) :- !, 54 | succ(N,M), 55 | stats(Codes), 56 | get_time(T1), 57 | format('~s | done ~0f% in ~3g s \r', [Codes,100*N/Total,T1-T0]), 58 | flush_output. 59 | 60 | progress_next(pr(T0,T,E,N,C),pr(T0,T,E,M,D)) :- succ(C,D), succ(N,M). 61 | 62 | 63 | %% stats is det. 64 | % 65 | % Print memory usage statistics. 66 | stats :- !, 67 | stats(Codes), 68 | format('~s\r',[Codes]), 69 | flush_output. 70 | 71 | %% stats( -Codes:list(code)) is det. 72 | % 73 | % Return memory usage statistics as a list of codes. 74 | stats(Codes) :- !, 75 | statistics(heapused,Heap), 76 | statistics(localused,Local), 77 | statistics(globalused,Global), 78 | statistics(trailused,Trail), 79 | format(codes(Codes), 'heap: ~t~D ~18| local: ~t~D ~36| global: ~t~D ~57| trail: ~t~D ~77|', 80 | [Heap,Local,Global,Trail]). 81 | 82 | -------------------------------------------------------------------------------- /genutils/prolog/data/pair.pl: -------------------------------------------------------------------------------- 1 | :- module(pair, 2 | [ ffst/3, ffst//3 3 | , fsnd/3, fsnd//3 4 | , dup/2, pair/3, fst/2, snd/2, is_pair/1 5 | , select_key_value/4 6 | , select_key_default_value/5 7 | , map_select_key_value/5 8 | , map_select_key_default_value/6 9 | , (&)/4 10 | , op(650,xfy,&) 11 | ]). 12 | 13 | :- meta_predicate fsnd(2,?,?), 14 | ffst(2,?,?), 15 | fsnd(4,?,?,?,?), 16 | ffst(4,?,?,?,?), 17 | &(2,2,?,?), 18 | map_select_key_value(2,+,-,+,-), 19 | map_select_key_default_value(2,+,+,-,+,-). 20 | 21 | %% is_pair(+X) is semidet. 22 | % True if X is a pair. 23 | is_pair(_-_). 24 | 25 | %% pair(X:A, Y:B, Z:pair(A,B)) is det. 26 | pair(X, Y, X-Y). 27 | 28 | %% dup(X:A, Y:pair(A,A)) is det. 29 | dup(X, X-X). 30 | 31 | %% fst(X:pair(A,B), Y:A) is det. 32 | fst(X-_, X). 33 | 34 | %% snd(X:pair(A,B), Y:B) is det. 35 | snd(_-Y, Y). 36 | 37 | %% ffst(+P:pred(A,B), X:pair(A,C), Y:pair(B,C)) is det. 38 | %% ffst(+P:pred(A,B,S,S), X:pair(A,C), Y:pair(B,C), S1:S, S2:S) is det. 39 | % Apply P to first element of pair. Two versions: one for normal use and 40 | % another for use in DCG goals. 41 | ffst(P,Y-X,Z-X) :- call(P,Y,Z). 42 | ffst(P,Y-X,Z-X) --> call(P,Y,Z). 43 | 44 | %% fsnd(+P:pred(B,C), X:pair(A,B), Y:pair(A,C)) is det. 45 | %% fsnd(+P:pred(B,C,S,S), X:pair(A,B), Y:pair(A,C), S1:S, S2:S) is det. 46 | % Apply P to second element of pair. Two versions: one for normal use and 47 | % another for use in DCG goals. 48 | fsnd(P,X-Y,X-Z) :- call(P,Y,Z). 49 | fsnd(P,X-Y,X-Z) --> call(P,Y,Z). 50 | 51 | %% &(+F:pred(A,B), +G:pred(A,C), X:A, Y:pair(B,C)) is det. 52 | % Apply F and G to X and pair results. 53 | &(F,G,X,Y-Z) :- call(F,X,Y), call(G,X,Z). 54 | 55 | 56 | %% map_select_key_value(+P:pred(A,B), K:C, Y:B, L1:list(pair(C,A)), L2:list(pair(C,A))) is nondet. 57 | % True when L2 is L1 with an element K-X removed, and P maps X to Y. 58 | map_select_key_value(P, K, Y, L1, L2) :- 59 | select(K-X, L1, L2), call(P,X,Y). 60 | 61 | %% map_select_key_default_value(+P:pred(A,B), K:C, Z:B, Y:B, L1:list(pair(C,A)), L2:list(pair(C,A))) is det. 62 | % If key K exists in pair list L1, extract value associated with it and apply P to get Y. 63 | % Otherwise unify default Z with Y. 64 | map_select_key_default_value(P, K, Default, Y, L1, L2) :- 65 | ( select(K-X, L1, L2) -> call(P,X,Y) 66 | ; Y=Default, L1=L2 67 | ). 68 | 69 | %% select_key_value(K:C, Y:B, L1:list(pair(C,A)), L2:list(pair(C,A))) is nondet. 70 | % True when L2 is L1 with an element K-Y removed. 71 | select_key_value(K, X, L1, L2) :- select(K-X, L1, L2). 72 | 73 | %% select_key_default_value(K:C, Z:B, Y:B, L1:list(pair(C,A)), L2:list(pair(C,A))) is det. 74 | % If key K exists in pair list L1, extract value Y associated with it. 75 | % Otherwise unify default Z with Y. 76 | select_key_default_value(K, Default, X, L1, L2) :- 77 | map_select_key_default_value((=), K, Default, X, L1, L2). 78 | 79 | user:goal_expansion(fsnd(P,P1,P2), (P1=X-Y1, P2=X-Y2, call(P,Y1,Y2))). 80 | user:goal_expansion(ffst(P,P1,P2), (P1=X1-Y, P2=X2-Y, call(P,X1,X2))). 81 | user:goal_expansion(fst(P,X), P=X-_). 82 | user:goal_expansion(snd(P,Y), P=_-Y). 83 | user:goal_expansion(pair(X,Y,P), P=X-Y). 84 | -------------------------------------------------------------------------------- /cclab/prolog/lambda1.pl: -------------------------------------------------------------------------------- 1 | :- module(lambda1, [ (\)/1, (\)/2, (\)/3, (\)/4, (\)/5, (\)/6, (\)/7 2 | , (^)/3, (^)/4, (^)/5, (^)/6, (^)/7, (^)/8 3 | , (<-)/2, (<-)/3, (<-)/4, (<-)/5, (<-)/6, (<-)/7 4 | , op(200,xfy,~) 5 | , op(600,xfx,<-) 6 | ]). 7 | 8 | /** Two approaches to lambdas 9 | 10 | This module implements two ways of implementing lambda terms. One is basically 11 | the same as Ulrich Neumerkel's in the library(lambda), but with less checking and a different 12 | notation for free variables which results in a simpler implementation. The result is 13 | well typed and elegant. Sample lambda: =|\Free~X^Y^foo(Y,X,Free), \X^Y^succ(Y,X)|= 14 | 15 | The other splits the arguments from the body at the top of the syntax tree representing 16 | the lambda term, and naturally leads to an implementation based on lists of arguments, a 17 | bit like library(yall). The result requires slightly less code (two clauses handle all 18 | arities of argument binding) but relies on heterogenous lists of arguments and the equivalent 19 | of apply/2, and is hence not well typed and, to my eyes, slightly less elegant. 20 | Sample lambda: =| Free/[X,Y]<-foo(X,Y,Free), \[X^Y]<-succ(Y,X) |=. 21 | */ 22 | 23 | :- op(200,xfy,~). 24 | :- meta_predicate \(0), \(1,?), \(2,?,?), \(3,?,?,?), \(4,?,?,?,?), \(5,?,?,?,?,?), \(6,?,?,?,?,?,?). 25 | :- meta_predicate ^(?,0,?), ^(?,1,?,?), ^(?,2,?,?,?), ^(?,3,?,?,?,?), ^(?,4,?,?,?,?,?), ^(?,5,?,?,?,?,?,?). 26 | 27 | :- set_prolog_flag(generate_debug_info, false). 28 | 29 | \(Lambda) :- copy_lambda(Lambda,Copy), call(Copy). 30 | \(Lambda,A1) :- copy_lambda(Lambda,Copy), call(Copy,A1). 31 | \(Lambda,A1,A2) :- copy_lambda(Lambda,Copy), call(Copy,A1,A2). 32 | \(Lambda,A1,A2,A3) :- copy_lambda(Lambda,Copy), call(Copy,A1,A2,A3). 33 | \(Lambda,A1,A2,A3,A4) :- copy_lambda(Lambda,Copy), call(Copy,A1,A2,A3,A4). 34 | \(Lambda,A1,A2,A3,A4,A5) :- copy_lambda(Lambda,Copy), call(Copy,A1,A2,A3,A4,A5). 35 | \(Lambda,A1,A2,A3,A4,A5,A6) :- copy_lambda(Lambda,Copy), call(Copy,A1,A2,A3,A4,A5,A6). 36 | 37 | copy_lambda(M:G~Lam, M:Copy) :- !, copy_term_nat(G~Lam,G~Copy). 38 | copy_lambda(M:Lam, M:Copy) :- copy_term_nat(Lam,Copy). 39 | 40 | ^(A,B,A) :- call(B). 41 | ^(A,B,A,V1) :- call(B,V1). 42 | ^(A,B,A,V1,V2) :- call(B,V1,V2). 43 | ^(A,B,A,V1,V2,V3) :- call(B,V1,V2,V3). 44 | ^(A,B,A,V1,V2,V3,V4) :- call(B,V1,V2,V3,V4). 45 | ^(A,B,A,V1,V2,V3,V4,V5) :- call(B,V1,V2,V3,V4,V5). 46 | 47 | % ---------------- another version --------------- 48 | 49 | :- op(600,xfx,<-). 50 | 51 | :- meta_predicate <-(?,0), <-(?,1,?), <-(?,2,?,?), <-(?,3,?,?,?), <-(?,4,?,?,?,?), <-(?,5,?,?,?,?,?). 52 | <-(Args,Body) :- copy_lambda(Args,Body,As,B), hat(As,B,[]). 53 | <-(Args,Body,A1) :- copy_lambda(Args,Body,As,B), hat(As,B,[A1]). 54 | <-(Args,Body,A1,A2) :- copy_lambda(Args,Body,As,B), hat(As,B,[A1,A2]). 55 | <-(Args,Body,A1,A2,A3) :- copy_lambda(Args,Body,As,B), hat(As,B,[A1,A2,A3]). 56 | <-(Args,Body,A1,A2,A3,A4) :- copy_lambda(Args,Body,As,B), hat(As,B,[A1,A2,A3,A4]). 57 | <-(Args,Body,A1,A2,A3,A4,A5) :- copy_lambda(Args,Body,As,B), hat(As,B,[A1,A2,A3,A4,A5]). 58 | 59 | copy_lambda(G/A,B,A1,B1) :- copy_term_nat(t(G,A,B),t(G,A1,B1)). 60 | copy_lambda(\A,B,A1,B1) :- copy_term_nat(A/B,A1/B1). 61 | 62 | % badly typed, uses univ operator! 63 | hat([],B,Vs) :- G =.. [call, B | Vs], call(G). 64 | hat([A|As],B,[A|Vs]) :- hat(As,B,Vs). 65 | 66 | -------------------------------------------------------------------------------- /cclab/prolog/cclazy/ccmemo.pl: -------------------------------------------------------------------------------- 1 | :- module(ccmemo, [run_ltree/2, choose/2, guard/1, memo_nondet/3, memo_nondet/2]). 2 | 3 | /** Nondeterminism as a lazy search tree with recursive memoisation 4 | 5 | This module uses delimited continuations to provided nondeterminism as a 6 | control effect along with memoisation of recursive, nondeterministic 7 | binary relations. The effect is reified as a lazy search tree. 8 | 9 | Use run_ltree/2 to run a unary predicate in a context that supports 10 | choose/2 for nondetermism and memo_nondet/{2,3} for creating memoised versions 11 | of a binary predicate. The whole of this must be run inside ccstate:run_ref/1, 12 | a context that provides mutable references as a control effect. Use treeutils.pl 13 | to visualise the tree. 14 | */ 15 | 16 | :- use_module(library(rbutils)). 17 | :- use_module(library(typedef)). 18 | :- use_module(library(delimcc), [pr_reset/3, pr_shift/2]). 19 | :- use_module(library(ccstate), [ref_new/2, ref_get/2, ref_app/2, ref_upd/3]). 20 | :- use_module(library(lambda1)). 21 | 22 | % nondeterminism as lazy search tree with recursive memoisation 23 | 24 | :- type tree(A) ---> leaf(A); node(list(tree(A))). 25 | :- type ltree(A) ---> leaf(A); lnode(pred(list(ltree(A)))). 26 | :- type ltree(L,A) ---> leaf(A); lnode(L,pred(list(ltree(A)))). % with labelled nodes 27 | 28 | :- meta_predicate memo_nondet(2,-), memo_nondet(2,-,-). 29 | memo_nondet(P,Q) :- memo_nondet(P,Q,_). 30 | memo_nondet(P, ccmemo:memf(P,R), ccmemo:memdump(R)) :- 31 | rb_empty(T), 32 | ref_new(T,R). 33 | 34 | memdump(R,Memo) :- 35 | ref_get(R,T), 36 | rb_visit(T,Pairs), 37 | maplist(\ (K-entry(Vals,_))^(K-Vals)^true, Pairs,Memo). 38 | 39 | memf(P,R,X,Y) :- pr_shift(nondet, mem(P,R,X,Y)). 40 | choose(Xs,X) :- pr_shift(nondet, choose(Xs,X)). 41 | 42 | :- meta_predicate guard(0). 43 | guard(P) :- call(P) -> true; pr_shift(nondet, fail). 44 | 45 | %% run_ltree(+P:pred(A), -T:ltree(A)) is det. 46 | % NB means nondet:prompt(ltree(A)). 47 | :- meta_predicate run_ltree(1,-). 48 | run_ltree(P,Result) :- pr_reset(nondet, to_ltree(P), Result). 49 | 50 | to_ltree(P,leaf(X)) :- call(P,X). 51 | 52 | % choose(Xs:list(B),X:B): handler(ltree(A)). 53 | choose(Xs,X,K,lnode(choice(Xs),ccmemo:maplist(expand1(\X^K),Xs))). 54 | fail(_,lnode(fail,=([]))). 55 | 56 | %% mem(+P:pred(+B,-C), +R:ref(memo(B,C)), +X:B, @Y:C, +K:pred(-ltree(A)), -T:ltree(A)) is det. 57 | mem(P,R,X,Y,K,Tree) :- 58 | YK = \Y^K, 59 | ref_upd(R,Tab,Tab1), 60 | ( rb_upd(X, entry(Ys,Conts), entry(Ys,[YK|Conts]), Tab, Tab1) 61 | -> Tree = lnode(cons(X,Ys), ccmemo:rb_fold(cons_expand1(YK),Ys,[])) 62 | ; rb_empty(EmptySet), 63 | rb_insert_new(Tab, X, entry(EmptySet,[]), Tab1), 64 | call(P,X,YNew), 65 | ref_app(R, rb_upd(X, entry(Ys,Conts), entry(Ys2,Conts))), 66 | ( rb_insert_new(Ys,YNew,t,Ys2) 67 | -> Tree=lnode(prod(X,YNew),ccmemo:maplist(send_to_cont(YNew),[YK|Conts])) 68 | ; Tree=lnode(dup(X,YNew),=([])), Ys2=Ys 69 | ) 70 | ). 71 | 72 | cons_expand1(Kx,X-_,S,[Y|S]) :- expand1(Kx,X,Y). 73 | expand1(Kx,X,Y) :- pr_reset(nondet, call(Kx,X), Y). 74 | send_to_cont(Y,Ky,T) :- pr_reset(nondet, call(Ky,Y), T). 75 | 76 | % for printing annotated search trees 77 | user:portray(choice(Xs)) :- write('?'), write(Xs). 78 | user:portray(cons(X,Ys)) :- rb_keys(Ys,Vals), write('C':X>Vals). 79 | user:portray(dup(X,Y)) :- write('D':X>Y). 80 | user:portray(prod(X,Y)) :- write('P':X>Y). 81 | 82 | -------------------------------------------------------------------------------- /pldb/prolog/db_aggregate.pl: -------------------------------------------------------------------------------- 1 | :- module(db_aggregate, [db_aggregate/5]). 2 | 3 | :- use_module(library(pldb_core)). 4 | 5 | %% db_aggregate( +Con, +Head:head(selector), +Spec:list(aggr), +GVars:list(var), -Res:list(_)) is nondet. 6 | % 7 | % Aggregation operations over tables. This predicate is intended to work somewhat 8 | % like SWI Prolog's aggregation library (aggregate.pl) but using SQL Select statements. 9 | % 10 | % ---+++ Examples 11 | % 12 | % Given a database connection db and a table called 'census' with columns 'country', 13 | % 'town' and 'population', we can compute the following: 14 | % The total urban population: 15 | % == 16 | % db_aggregate(db,census(_,_,P),[],[sum(P)],[TotalPopn]). 17 | % == 18 | % Urban population of China: 19 | % == 20 | % db_aggregate(db,census(china,_,P),[],[sum(P)],[ChinaPopn]). 21 | % == 22 | % Number of towns and urban population of each country 23 | % (goes through each country on backtracking): 24 | % == 25 | % db_aggregate(db,census(C,T,P),[C],[count(T),sum(P)],[NumTowns,NationalPopn]). 26 | % == 27 | % Average population of cities with more than 100,000 people: 28 | % == 29 | % db_aggregate(db,census(_,_,P:= >(100,000)),[],[avg(P)],[AvgCity]). 30 | % == 31 | % 32 | % The arguments are as follows: 33 | % 34 | % @param Head A term with the table name as the head functor and selector terms as arguments. 35 | % This defines the 'FROM WHERE ' part of the SQL query, 36 | % just as in db_select/2. Variables in this term will be unified with values from 37 | % the table during processing. 38 | % 39 | % @param GVars These are the variables which are to be considered 'free' in the whole 40 | % operation, that is, they will be unified with particular values on exit, 41 | % and different values can be obtained on backtracking. Translates to the 42 | % 'GROUP BY' clause of the SQL statement. 43 | % 44 | % @param Spec A list of aggregation expressions in terms of variables in the query 45 | % defining term Head. Each expression must be a valid SQL expression 46 | % when the variables are unified with the corresponding column names. 47 | % 48 | % @param Res A list of values, one for each aggregate expression in Spec. 49 | 50 | db_aggregate(Con,Head,Globals,Spec,Output) :- 51 | phrase_string( compose_aggregate(Con,Head,Spec,Globals,Output,Result), SQL), 52 | dbh_query_row(Con,SQL,Row), Row=..[row|Vals], 53 | maplist(decode,Vals,Result). 54 | 55 | 56 | %% compose_aggregate( +Con, +Head, +Spec, +Globals, @Out:list(var), -Args:list(result))// is det. 57 | compose_aggregate(Con,Head,Spec,Globals,Output,AggResults) --> 58 | { analyse_head(Con,Head,Tab,Args,Columns), 59 | build_select(Args,Columns,SelArgs,Where,Results), 60 | copy_term(Globals+Results+Spec,Globals1+Results1+Spec1), 61 | 62 | maplist(fst,Results1,SelArgs), % should bind variables in Globals1 to column names 63 | maplist(aux2(Columns),Globals,Globals1,GResults), % result catchers for global vars 64 | maplist(aux3,Output,Spec1,AResults), % result catchers for aggregates 65 | append(Globals1,Spec1,ToSelect), % list of things to SELECT is globals++aggregates 66 | append(GResults,AResults,AggResults) % list of result catchers 67 | }, 68 | sql(select(Tab,ToSelect,Where)), 69 | group_by(Globals1). 70 | 71 | % used above in compose_aggregate//6 72 | aux2(Cols, X, Name,X:Type) :- member(Name:Type,Cols). 73 | aux3(X, count(_), X:int4) :- !. 74 | aux3(X, _, X:numeric). 75 | fst(X:_,X). 76 | -------------------------------------------------------------------------------- /cclab/prolog/cclazy/test_memo.pl: -------------------------------------------------------------------------------- 1 | :- module(test_memo, []). 2 | 3 | :- use_module(library(tabling)). 4 | :- use_module(library(math)). 5 | :- use_module(library(ccstate), [run_ref/1, run_state/3, upd/2]). 6 | :- use_module(library(ccdetmem), [memo/3]). 7 | :- use_module(library(lambda1)). 8 | :- use_module(ccmemo, [guard/1, choose/2, run_ltree/2, memo_nondet/2, memo_nondet/3]). 9 | :- use_module(treeutils). 10 | 11 | % -------------- calling stateful nondeterminism ------ 12 | 13 | run_ltree_ref(Generate, Explore) :- 14 | run_ref(generate_explore(Generate, Explore)). 15 | 16 | generate_explore(Generate, Explore) :- 17 | run_ltree(Generate, Tree), 18 | call(Explore, Tree). 19 | 20 | depth_first(Items, Tree) :- 21 | df(Tree, Items, []). 22 | 23 | df(leaf(X), [X|L], L). 24 | df(lnode(GenSubtrees), L1, L2) :- 25 | freeze(L1, df_trees(GenSubtrees, L1, L2)). 26 | df_trees(Gen, L1, L2) :- 27 | call(Gen, Subtrees), 28 | foldl(df, Subtrees, L1, L2). 29 | 30 | 31 | :- module(test_memo). 32 | 33 | % ---- test programs ----- 34 | 35 | test0(r(X)) :- choose([1,2,3],X). 36 | 37 | test(Z) :- 38 | choose([1,2,3],X), 39 | choose([a(X),b(X),c(X)],Y), 40 | choose([Y-x, Y-y, Y-z],Z1), 41 | choose([Z1-u, Z1-v, Z1-w],Z). 42 | 43 | hmm(0,_,[]). 44 | hmm(N,Y,[X|Xs]) :- 45 | succ(M,N), 46 | trans(Y,X), 47 | hmm(M,X,Xs). 48 | 49 | trans(_,X) :- choose([a,b,c],X). 50 | 51 | link(a,X) :- choose([b,c],X). 52 | link(b,d). 53 | link(c,X) :- choose([d,m],X). 54 | link(d,X) :- choose([e,f],X). 55 | link(e,g). 56 | link(f,X) :- choose([g,k],X). 57 | link(g,h). 58 | link(h,X) :- choose([i,j],X). 59 | link(i,X) :- choose([],X). 60 | link(j,X) :- choose([],X). 61 | link(k,l). 62 | link(l,X) :- choose([],X). 63 | link(m,X) :- choose([],X). 64 | 65 | 66 | link(w,X) :- choose([x,y],X). 67 | link(x,z). 68 | link(y,z). 69 | link(z,X) :- choose([],X). 70 | % link(z,z). 71 | 72 | id --> []. 73 | 74 | % left and right recursive grammar 75 | sent(S,L1,L2) :- choose([b,l,r],A), sentx(A,S,L1,L2). 76 | sentx(b,_) --> word. 77 | sentx(r,S) --> call(S), out(not). 78 | sentx(l,S) --> out(really), call(S). 79 | 80 | word --> {choose([cool,wicked],W)}, out(W). 81 | 82 | out(_,[],_) :- !, guard(false). 83 | out(W,[X|T],T) :- guard(W=X). 84 | 85 | % incomplete recursive form 86 | pathr(P) --> link, {choose(['B','R'],Q)}, maybe_rec(Q,P). 87 | pathl(P) --> {choose(['B','R'],Q)}, maybe_rec(Q,P), link. 88 | 89 | 90 | 91 | maybe_rec('B',_) --> []. 92 | maybe_rec('R',P) --> call(P). 93 | 94 | 95 | fib_inc(_,0,1) :- !. 96 | fib_inc(_,1,1) :- !. 97 | fib_inc(Fib,N,X) :- 98 | succ(M,N), call(Fib,M,Y), 99 | succ(L,M), call(Fib,L,Z), 100 | X is Y+Z. 101 | 102 | test_fib(Fib,Dump,Goal) :- 103 | memo(fib_inc(Fib), Fib, Dump), 104 | call(Goal). 105 | 106 | :- table fib/2. 107 | fib(0,1) :- !. 108 | fib(1,1) :- !. 109 | fib(N,X) :- 110 | succ(M,N), fib(M,Y), 111 | succ(L,M), fib(L,Z), 112 | X is Y+Z. 113 | 114 | % for testing table copying overhead 115 | last(Last,[H|T],L) :- T=[] -> L=H; call(Last,T,L). 116 | 117 | 118 | test_path(l,D,Start, End) :- test_path(pathl(P), P, D, Start, End). 119 | test_path(r,D,Start, End) :- test_path(pathr(P), P, D, Start, End). 120 | test_path(Inc,Complete,Dump, Start, End) :- 121 | memo_nondet(Inc,Complete,Dump), 122 | call(Complete, Start, End). 123 | 124 | test_left_grammar(In,Dump,Tail) :- 125 | memo_nondet(sent(S), S, Dump), 126 | call(S,In,Tail). 127 | 128 | -------------------------------------------------------------------------------- /timeutils/prolog/timedcg.pl: -------------------------------------------------------------------------------- 1 | :- module(timedcg, 2 | [ now//1 3 | , sync//0 4 | , wait//0 5 | , wait//1 6 | , adv//1 7 | , cue//1 8 | , cue//2 9 | , run_cued//2 10 | , run_cued//3 11 | , run_cued/2 12 | , run_cued/3 13 | , sleep_till/1 14 | ]). 15 | 16 | /** Time DCG 17 | 18 | Some of the predicates below are designed to operate in a DCG where 19 | the state represents a time as a number of seconds since a particular 20 | epoch (see get_time/1). The enables the write of code in a sort 21 | of temporal modal logic form, where predicates can implicitly get 22 | at the current time (using dcg_core:get//1) or move to other times by 23 | chaging the DCG state. 24 | 25 | */ 26 | 27 | :- meta_predicate run_cued(+,//,+,-), run_cued(+,+,//,+,-). 28 | :- meta_predicate run_cued(+,//), run_cued(+,+,//). 29 | 30 | :- use_module(library(dcg_core)). 31 | :- use_module(library(dcg_pair)). 32 | :- use_module(library(dcg_macros)). 33 | 34 | 35 | % -------------------------------- Time DCG ------------------------------- 36 | 37 | %% now(-T:time)// is det. 38 | % 39 | % Unifies T with the current real time as returned by get_time/1. 40 | now(T,S,S) :- get_time(T). 41 | 42 | %% wait// is semidet. 43 | %% wait(+Pre:nonneg)// is semidet. 44 | % Waits (blocks) until the real world time catches up with the 45 | % current DCG time. If Pre is given, then wait//1 sleeps until 46 | % Pre seconds before the current DCG time. 47 | wait(T,T) :- sleep_till(T). 48 | wait(Pre,T,T) :- T1 is T-Pre, sleep_till(T1). 49 | 50 | %% sleep_till(+T:time) is semidet. 51 | % Compares T with the current real time (get_time/1); if T is 52 | % in the past, then fail, otherwise, blocks until approximately 53 | % T. Accuracy of timing cannot be guaranteed. 54 | sleep_till(T) :- 55 | get_time(T0), T@>T0, DT is T-T0, sleep(DT). 56 | 57 | %% sync// is det. 58 | % Runs in time DCG and sets the current time to the current real time as returned 59 | % by now//1 and get_time/1. 60 | sync --> now(T), set(T). 61 | 62 | %% adv(+T:nonneg)// is det. 63 | % Advances current time by T seconds. Runs in time DCG. 64 | adv(DT) --> trans(T1,T2), {T2 is T1+DT}. 65 | 66 | %% quant(+Q:nonneg)// is det. 67 | % Advances current time to the next multiple of Q. 68 | quant(Q) --> trans(T1,T2), {T2 is Q*ceil(T1/Q)}. 69 | 70 | %% cue(+D:nonneg)// is det. 71 | % Sets the current DCG time to D seconds after current real time. 72 | cue(D) --> now(T), set(T), adv(D). 73 | 74 | %% cue(+D:nonneg,+Q:nonneg)// is det. 75 | % Sets the current DCG time to next multiple of Q at least 76 | % D seconds after current real time. 77 | cue(D,Q) --> now(T), set(T), adv(D), quant(Q). 78 | 79 | cue(D,Q,O) --> now(T), set(T), adv(D), quant(Q), adv(O). 80 | lag(L) --> now(T0), get(T), {L is T-T0}. 81 | 82 | 83 | %% run_cued( +DT:nonneg, +Q:nonneg, +Cmd:phrase((time,S)), ?S1:S, ?S2:S) is nondet. 84 | %% run_cued( +DT:nonneg, +Cmd:phrase((time,S)), ?S1:S, ?S2:S) is nondet. 85 | %% run_cued( +DT:nonneg, +Q:nonneg, +Cmd:phrase(time)) is nondet. 86 | %% run_cued( +DT:nonneg, +Cmd:phrase(time)) is nondet. 87 | % 88 | % Run command Cmd in DT seconds. Cmd must operate in (time,S) DCG and is called 89 | % with the current real time plus DT seconds. If Q is supplied, the time 90 | % passed to Cmd is quantised upwards in units of Q seconds. 91 | run_cued(DT,Cmd) --> run_left((\< cue(DT), call_dcg(Cmd)),_,_). 92 | run_cued(DT,Q,Cmd) --> run_left((\< cue(DT,Q), call_dcg(Cmd)),_,_). 93 | run_cued(DT,Cmd) :- call_dcg((cue(DT), call_dcg(Cmd)),_,_). 94 | run_cued(DT,Q,Cmd) :- call_dcg((cue(DT,Q), call_dcg(Cmd)),_,_). 95 | 96 | -------------------------------------------------------------------------------- /plumdrum/prolog/humdrum/reps.pl: -------------------------------------------------------------------------------- 1 | /* Part of plumdrum 2 | Copyright 2012-2015 Samer Abdallah (Queen Mary University of London; UCL) 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | :- module(reps, [ representation/2 ]). 20 | 21 | %% representation( +Rep:xinterp, -Desc:atom) is semidet. 22 | %% representation( -Rep:xinterp, -Desc:atom) is nondet. 23 | % 24 | % Known exclusive interpretations 25 | 26 | representation( bhatk, 'Bhatkhande notation'). 27 | representation( cents, 'pitch in cents'). 28 | representation( cbr, 'critcal band rand in ERBs'). 29 | representation( cocho, 'cochlear coordinates in mm'). 30 | representation( correl, 'statistical correlation'). 31 | representation( date, 'absolute universal time'). 32 | representation( dB, 'relative amplitude'). 33 | representation( deg, 'relative scale degree'). 34 | representation( degree, 'absolute scale degree'). 35 | representation( diss, 'sensory dissonance'). 36 | representation( dur, 'physical time duration'). 37 | representation( embel, 'embelishment tones'). 38 | representation( freq, 'frequency in Hz'). 39 | representation( fret, 'fretted instrument tabulature'). 40 | representation( harm, 'Western functional harmony'). 41 | representation( hint, 'harmonic interval'). 42 | representation( 'Hildegard', 'Hildegard manuscripts notation'). 43 | representation( iv, 'interval vector'). 44 | representation( 'IPA', 'International Phonetic Alphabet'). 45 | representation( kern, 'Core pitch and duration'). 46 | representation( melac, 'melodic accent'). 47 | representation( metpos, 'metrical position'). 48 | representation( mint, 'melodic interval'). 49 | representation( 'MIDI', 'MIDI events tabulature'). 50 | representation( nf, 'normal form for pitch sets'). 51 | representation( ordo, 'sequential order'). 52 | representation( pc, 'pitch-class'). 53 | representation( pcset, 'Fortean pitch-class set'). 54 | representation( pf, 'prime form representation'). 55 | representation( pitch, 'ANSI pitch notation'). 56 | representation( recip, 'Reciprocal duration'). 57 | representation( simil, 'Damerau-Levenshtein edit distance'). 58 | representation( semits, 'pitch in semitones from middle C'). 59 | representation( solfg, 'tonic solfa syllable'). 60 | representation( solfg, 'French solfège system'). 61 | representation( specC, 'spectral centroid in Hz'). 62 | representation( spect, 'discrete spectrum'). 63 | representation( synco, 'degree of syncopation'). 64 | representation( takt, 'beat-position'). 65 | representation( text, 'vocal text'). 66 | representation( time, 'relative time in seconds'). 67 | representation( 'Tonh', 'German Tonhöhe pitch system'). 68 | representation( 'URrhythm', 'Johnson-Laird beat prototype'). 69 | representation( 'vox#', 'number of active voices'). 70 | representation( 'Zeit', 'absolute universal time period'). 71 | 72 | -------------------------------------------------------------------------------- /pldb/prolog/pldb_terms.pl: -------------------------------------------------------------------------------- 1 | :- module(pldb_terms, 2 | [ term_to_codes/2 3 | , string_to_term/3 4 | , strings_to_terms/2 5 | , term_pattern/3 6 | ]). 7 | 8 | :- use_module(library(dcg_core)). 9 | :- use_module(library(dcg_codes)). 10 | :- use_module(library(dcg_pair)). 11 | 12 | % sql_string(Term) --> 13 | % "'", esc(run_left(sql),Codes), "'", 14 | % { read_term_from_codes(Codes,Term,[back_quoted_string(false),double_quotes(string),variable_names(Bindings)]), 15 | % maplist(bind_var,Bindings) 16 | % }. 17 | 18 | % ----- Dealing with terms --------------------------------------------------- 19 | 20 | %% term_to_codes(?X,L:list(code)) is det. 21 | % 22 | % This formats any term such that it can be read back. 23 | % It MUST be a ground term. Atoms and functors are quoted properly. 24 | % '$VAR'(_) terms are written as with numbervars(true) option to write_term. 25 | % Operator declarations are not used. 26 | % 27 | % NB. we do not use numbervars or write_canonical/1 here, because it will 28 | % probably be more useful to label all the variables in one row together, 29 | % so that variables shared across muliple columns will be properly labelled. 30 | % 31 | % !!! TODO: make sure that variables shared across multiple columns are 32 | % properly reinstated all together in the aftermath of SELECT. 33 | % 34 | % NB. Strings are always written using double quotes. 35 | term_to_codes(V,L) :- 36 | (ground(V) -> true; throw(error(pldb:nonground(V)))), 37 | with_output_to(codes(L), write_canonish(V)). 38 | 39 | string_to_term(Text,Term,Bindings) :- 40 | read_term_from_atom(Text,Term,[back_quoted_string(false),double_quotes(string),variable_names(Bindings)]). 41 | 42 | strings_to_terms(Strings,Terms) :- 43 | maplist(string_to_term,Strings,Terms,Bindings), 44 | maplist(maplist(includes_binding(_)),Bindings). 45 | 46 | includes_binding(Master,Name=Var) :- memberchk(Name=Var,Master). 47 | bind_var(Name='$VAR'(Name)). 48 | 49 | %% term_pattern(?X)// is det. 50 | % Generates a valid SQL LIKE pattern for matching string representation of terms. 51 | % The term X is any Prolog term including variables. The database is assumed to contain 52 | % string values representing Prolog terms. This DCG rule generates a string corresponding to 53 | % the textual representation of X, except that each variable is replaced with a LIKE wildcard 54 | % character '%', and any wildcard characters present literally in X ('%', '_', or '\') 55 | % are escaped with a preceding '\'. 56 | % 57 | % Operator declaration are ignored: terms are written in their canonical form. 58 | term_pattern(Term,Pattern,Tail) :- 59 | term_variables(Term,Vars), 60 | with_output_to(codes(C1),write_with_variables_as(1,Vars,Term)), 61 | with_output_to(codes(C2),write_with_variables_as(2,Vars,Term)), 62 | escape_term_pattern(C1-(C2-Pattern),[]-([]-Tail)). 63 | 64 | write_with_variables_as(X,Vars,Term) :- 65 | maplist(=(X),Vars), 66 | write_canonish(Term), 67 | fail. 68 | write_with_variables_as(_,_,_). 69 | 70 | write_canonish(Term) :- 71 | write_term(Term,[quoted(true),ignore_ops(true),numbervars(true),back_quotes(symbol_char)]). 72 | 73 | escape_term_pattern --> \< eos, !. 74 | escape_term_pattern --> "1" <\> ("2" <\> "%"), !, escape_term_pattern. 75 | escape_term_pattern --> [_] <\> pattern, !, escape_term_pattern. 76 | 77 | eos([],[]). 78 | 79 | % escape string for use in SQL LIKE pattern (generate only, not parse) 80 | % (still needs escaping for writing as quoted SQL literal.) 81 | pattern --> "%" <\> "\\%", !. 82 | pattern --> "_" <\> "\\_", !. 83 | pattern --> "\\" <\> "\\\\", !. 84 | pattern --> [X] <\> [X]. 85 | 86 | -------------------------------------------------------------------------------- /callgraph/README: -------------------------------------------------------------------------------- 1 | This package provides library(callgraph), a tool for compiling a graph of calls between predicates in a module. 2 | 3 | ---++++ Prerequisites 4 | 5 | The graph layout programs from the GraphViz library (http://graphviz.org/) are 6 | used to render the end result. Whilst you can produce a dot file without them, 7 | you will need them for the final rendering. 8 | On Mac OS X with MacPorts installed, do this at the bash prompt. 9 | == 10 | $ sudo port install graphviz 11 | == 12 | On Debian based systems, do this: 13 | == 14 | $ sudo apt-get install graphviz 15 | == 16 | And so on. 17 | You will need a PDF viewer to see the results. 18 | 19 | 20 | 21 | ---++++ Simple usage 22 | 23 | To produce a call graph as a PDF, make sure that both this module and the 24 | module you wish to analyse are loaded, then do this: 25 | == 26 | ?- module_dotpdf(,[]). 27 | == 28 | This will produce a PDF file .pdf in the current directory. 29 | Often, the default layout program, dot, will produce a very wide graph. 30 | This can sometimes be alleviated by using the unflatten program from the 31 | Graphviz tools. In module_dotpdf/2, the default layout method does actually 32 | use unflatten without any parameters, but if this is not enough, you can 33 | provide values for the -f, -l and -c switches of unflatten (see the man 34 | page for unflatten for more details). For example, to produce a graph of 35 | callgraph itself, you can try the following: 36 | == 37 | $ swipl 38 | ?- use_module(library(callgraph)). 39 | ?- module_dotpdf(callgraph,[method(unflatten([fl(4),c(4)]))]). 40 | == 41 | 42 | ---++++ More complex usage 43 | 44 | Version 0.2.5 adds support for graphing multiple modules. 45 | For example, to graph modules callgraph and dot to a file 46 | called test.pdf, use 47 | == 48 | modules_dotpdf([callgraph,dot],[method(unflatten([fl(4),c(4)]))],test). 49 | == 50 | 51 | Version 0.3.2 adds support for node links by supplying the linkbase parameter. 52 | For example, if you have an SWI Prolog documentation server running on port 8000, 53 | then 54 | == 55 | ?- module_render(callgraph,[linkbase('http://localhost:8000/help/source/doc_for?object='), 56 | format(svg),method(unflatten([fl(4),c(4)]))]), 57 | www_open_url('callgraph.svg'). 58 | == 59 | should produce open an SVG in your browser with clickable nodes that link to 60 | the documentation for each predicate. 61 | 62 | ---++++ Output formats 63 | 64 | If you want the dot language source file, use module_dot/2 instead. The 65 | method option is then inapplicable. 66 | 67 | The code can also produce rendered graphs in any format supported by 68 | Graphviz, but this functionality is not currently exposed. 69 | 70 | ---++++ Limitations 71 | 72 | The graph compilation relies on prolog_walk_code/1 to do the actual code 73 | analysis. This does a good job in most cases, using meta-predicate declarations 74 | or inferred meta-predicates to detect many high-order calling patterns. 75 | Ironically enough, callgraph fails to analyse itself fully because 76 | prolog_walk_code/1 does not detect that it itself calls a given predicate 77 | for each call detected. Thus, in the example, there is no edge from 78 | assert_module_graph/1 to assert_edge/4. 79 | 80 | ---++++ Planned enhancements 81 | 82 | Allow more control of subgraph layout and style. 83 | Handling of recorded database is a bit unsatisfactory. 84 | The system for dealing with style attributes is 85 | a bit messy and could be cleaned up. 86 | 87 | ---++++ Change log 88 | 89 | Changes in v 0.4.0 90 | 91 | - Switched to using swipe for building shell pipelines 92 | - Now allow filename/1 option to determine full path of output PDF file. 93 | -------------------------------------------------------------------------------- /cclab/prolog/cclazy/ccprob.pl: -------------------------------------------------------------------------------- 1 | :- module(ccprob, [run_prob/2, dist/2, fail_/0, memo_prob/3]). 2 | 3 | /** Probabilistic choice as a lazy search tree with recursive memoisation 4 | 5 | This module uses delimited continuations to provided probabilistic choice as a 6 | control effect along with memoisation of recursive, probabilistic generators. 7 | The effect is reified as a lazy search tree with weighted branches. 8 | 9 | Use run_lwtree/2 to run a unary predicate in a context that supports 10 | dist/2 for probabilistic choice and memo_prob/{2,3} for creating memoised versions 11 | of a probabilistic generators. The whole of this must be run inside ccstate:run_ref/1, 12 | a context that provides mutable references as a control effect. You can use 13 | treeutils.pl to visualise the search tree. 14 | */ 15 | 16 | :- use_module(library(clpr)). 17 | :- use_module(library(rbutils)). 18 | :- use_module(library(typedef)). 19 | :- use_module(library(math), [mul/3]). 20 | :- use_module(library(delimcc), [pr_reset/3, pr_shift/2]). 21 | :- use_module(library(ccstate), [get/1, set/1, run_state/3, upd/2, ref_new/2, ref_get/2, ref_app/2, ref_upd/3]). 22 | :- use_module(library(lambda2)). 23 | 24 | :- set_prolog_flag(back_quotes, symbol_char). 25 | 26 | :- type weighted(A) ---> number - A. 27 | :- type dist(A) == list(weighted(A)). 28 | :- type wtree(A) ---> leaf(A); wnode(dist(tree(A))). 29 | :- type lwtree(L,A) ---> leaf(A); lwnode(L,pred(dist(ltree(A)))). % with labelled nodes 30 | 31 | :- meta_predicate memo_prob(2,-), memo_prob(2,-,-). 32 | memo_prob(P,Q) :- memo_prob(P,Q,_). 33 | memo_prob(P, ccprob:memf(P,R), ccprob:memdump(R)) :- 34 | rb_empty(T), 35 | ref_new(T,R). 36 | 37 | memdump(R,Memo) :- 38 | ref_get(R,T), 39 | rb_visit(T,Pairs), 40 | maplist(\\K-entry(_,Vals,_)`K-Vals`true, Pairs,Memo). 41 | 42 | factor(K) :- upd(P1,P2), {P2 = K*P1}. 43 | 44 | memf(P,R,X,Y) :- get(P0), pr_shift(prob, mem(P,R,P0,X,P1,Y)), factor(P1). 45 | dist(Xs,X) :- pr_shift(prob, dist(Xs,X,W)), factor(W). 46 | fail_ :- pr_shift(prob, fail). 47 | 48 | %% run_prob(+P:pred(A), -T:lwtree(A)) is det. 49 | :- meta_predicate run_prob(1,-). 50 | run_prob(P,Result) :- pr_reset(prob, to_lwtree(P), Result). 51 | 52 | to_lwtree(P,leaf(X:Prob)) :- run_state(call(P,X),1,Prob). 53 | 54 | % dist(Xs:dist(B),X:B): handler(lwtree(A)). 55 | dist(Xs,X,W,K,lwnode(dist(Xs),ccprob:maplist(expand1(\\W-X`K),Xs))). 56 | fail(_,lwnode(fail,=([]))). 57 | 58 | mem(P,R,P0,X,P1,Y,K,Tree) :- 59 | PYK = (\\P1-Y`K), 60 | ref_upd(R,Tab,Tab1), 61 | ( rb_update(Tab, X, entry(PP,Ys,Conts), entry(PP,Ys,[PC-PYK|Conts]), Tab1) 62 | -> {PC = P0/PP}, 63 | Tree = lwnode(cons(X,Ys),ccprob:rb_fold(cons_expand1(PYK),Ys,[])) 64 | ; rb_empty(EmptyDist), 65 | rb_insert_new(Tab, X, entry(P0,EmptyDist,[]), Tab1), 66 | run_state(call(P,X,YNew), P0, Prob), 67 | ref_app(R, rb_upd(X, entry(_,Ys,Conts), entry(P0,Ys2,Conts))), 68 | {PY = Prob/P0}, 69 | ( rb_insert_new(Ys,YNew,PY,Ys2) 70 | -> Tree=lwnode(prod(X,YNew),ccprob:maplist(send_to_cont(PY-YNew),[1-PYK|Conts])) 71 | ; {NewP = OldP+PY}, 72 | rb_update(Ys,YNew,OldP,NewP,Ys2), 73 | Tree=lnode(dup(X,YNew),=([])) 74 | ) 75 | ). 76 | 77 | cons_expand1(Kx,X-W,S,[WY|S]) :- expand1(Kx,W-X,WY). 78 | expand1(Kpx,W-X,W-Y) :- pr_reset(prob, call(Kpx,W-X), Y). 79 | send_to_cont(PY,P0-Ky,P0-T) :- pr_reset(prob, call(Ky,PY), T). 80 | 81 | % for printing annotated search trees 82 | user:portray(dist(Xs)) :- write('?'), maplist(\\F-X`X:S`format(string(S),'~2g',[F]), Xs, Ss), write(Ss). 83 | user:portray(cons(X,Ys)) :- rb_visit(Ys,Dist), print('C':X>Dist). 84 | user:portray(dup(X,Y)) :- write('D':X>Y). 85 | user:portray(prod(X,Y)) :- write('P':X>Y). 86 | --------------------------------------------------------------------------------