{ "info": { "author": "Tim Hemel", "author_email": "yldprolog@timit.nl", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: GNU Affero General Public License v3", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# yldprolog\n\nyldprolog is a rewrite of Yield Prolog, which compiles Prolog into source code that you can embed in your code. Yield Prolog supports several programming languages, yldprolog only supports Python.\n\nThe rewrite grew out of the need to run multiple Prolog instances concurrently. In Yield Prolog, the active instance is a Python module, and therefore it is cumbersome to have multiple instances at the same time. This rewrite uses object instances instead, which make this much easier.\n\nThe interface for the engine changed and as a result, the code generated by the existing YieldProlog compiler is not compatible with yldprolog. You will need to use the yldprolog compiler.\n\nThe yldprolog compiler uses ANTLR and supports the most common Prolog constructs.\n\n# Usage\n\n## Compiling a Prolog program\n\nLet's look at the following Prolog script:\n\n```\n%\n% The following Prolog code is based on the example \"monkey and banana\"\n% from: Ivan Bratko, Prolog Programming for Artificial Intelligence,\n% third edition. ISBN 0-201-40375-7.\n%\n\nmove(state(middle,onbox,middle,hasnot),\n grasp,\n state(middle,onbox,middle,has)).\n\nmove(state(P,onfloor,P,H),\n climb,\n state(P,onbox,P,H)).\n\nmove(state(P1,onfloor,P1,H),\n push(P1,P2),\n state(P2,onfloor,P2,H)).\n\nmove(state(P1,onfloor,B,H),\n walk(P1,P2),\n state(P2,onfloor,B,H)).\n\ncanget(state(_,_,_,has)).\ncanget(State1) :-\n move(State1,Move,State2),\n canget(State2).\n```\n\nYou can compile this Prolog script with:\n\n```\nyldpc monkey.prolog > monkey.py\n```\n\nThe result is a Python module that defines the predicates as functions.\nYou can use these modules in your program, for example.\n\n```\n# 1. construct the yldproglog engine\nyp = YP()\n# 2. load a script from a path or filename\nyp.load_script_from_file(pathlib.Path(_SCRIPT_DIR) / 'monkey.py')\n# 3. execute the query:\n# canget(state(atdoor, onfloor, atwindow, hasnot))\nq = yp.query('canget', [yp.functor('state',\n\t[yp.atom('atdoor'), yp.atom('onfloor'),\n\typ.atom('atwindow'), yp.atom('hasnot')])])\n# 4. q is a generator that will give all solutions. Since this\n# query has infinitely many solutions, we will just get the\n# first one.\nself.assertEqual(next(q), False)\n```\n\n# Building the compiler\n\n## Installing ANTLR\n\nYou can use `antlr4` to build the prolog compiler. You will need version 4.7.2 or higher.\n\n### Installing ANTLR manually (optional)\n\nIf your system's antlr4 is older, you can download the ANTLR jar file from\nthe antlr web page:\n\n```\nwget https://www.antlr.org/download/antlr-4.7.2-complete.jar\n```\n\nSave this file somewhere, and create a wrapper script:\n\n```\n#!/bin/bash\n\njava -cp \"$HOME/antlr-4.7.2/antlr-4.7.2-complete.jar:$CLASSPATH\" \\\n\torg.antlr.v4.Tool \"$@\"\n```\n\n### Installing the ANTLR Python runtime\n\nYou will also need to install the Python runtime, for example (Python3):\n\n```\npip3 install antlr4-python3-runtime==4.7.2\n```\n\n### Generating the compiler\n\nYou build the compiler by running `make compiler`.\n\n\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "", "keywords": "prolog", "license": "GNU Affero General Public License v3", "maintainer": "", "maintainer_email": "", "name": "yldprolog", "package_url": "https://pypi.org/project/yldprolog/", "platform": "", "project_url": "https://pypi.org/project/yldprolog/", "project_urls": { "Source": "https://github.com/timhemel/yldprolog" }, "release_url": "https://pypi.org/project/yldprolog/1.0.0/", "requires_dist": [ "antlr4-python3-runtime (>=4.7.2)" ], "requires_python": ">=3.6", "summary": "A rewrite of Yield Prolog for Python", "version": "1.0.0" }, "last_serial": 5946178, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "92576bb743e08f228117c418ca3e556b", "sha256": "c0643e3070077f5462bfc57509996f168f22bc8f00de0ba534cf766209c17dc9" }, "downloads": -1, "filename": "yldprolog-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "92576bb743e08f228117c418ca3e556b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 38348, "upload_time": "2019-10-08T18:54:04", "url": "https://files.pythonhosted.org/packages/47/ba/3c58551a6d39711d291f3c33d2834181c8941d76cd2d0ce1263f7f1a21c3/yldprolog-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b24b67f5357ec8e5a765b2ab5f40238e", "sha256": "9d9db9d8867f7802259a7b763f473da837b92ebef76f025cc7a72c9d9928b04a" }, "downloads": -1, "filename": "yldprolog-1.0.0.tar.gz", "has_sig": false, "md5_digest": "b24b67f5357ec8e5a765b2ab5f40238e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 24162, "upload_time": "2019-10-08T18:54:07", "url": "https://files.pythonhosted.org/packages/90/9d/f71fd0b930f92dbf6933d97d65016c6db536b0c36c65ae9ed76278080ea8/yldprolog-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "92576bb743e08f228117c418ca3e556b", "sha256": "c0643e3070077f5462bfc57509996f168f22bc8f00de0ba534cf766209c17dc9" }, "downloads": -1, "filename": "yldprolog-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "92576bb743e08f228117c418ca3e556b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 38348, "upload_time": "2019-10-08T18:54:04", "url": "https://files.pythonhosted.org/packages/47/ba/3c58551a6d39711d291f3c33d2834181c8941d76cd2d0ce1263f7f1a21c3/yldprolog-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b24b67f5357ec8e5a765b2ab5f40238e", "sha256": "9d9db9d8867f7802259a7b763f473da837b92ebef76f025cc7a72c9d9928b04a" }, "downloads": -1, "filename": "yldprolog-1.0.0.tar.gz", "has_sig": false, "md5_digest": "b24b67f5357ec8e5a765b2ab5f40238e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 24162, "upload_time": "2019-10-08T18:54:07", "url": "https://files.pythonhosted.org/packages/90/9d/f71fd0b930f92dbf6933d97d65016c6db536b0c36c65ae9ed76278080ea8/yldprolog-1.0.0.tar.gz" } ] }