yldprolog


Nameyldprolog JSON
Version 1.3.1 PyPI version JSON
download
home_pagehttps://github.com/timhemel/yldprolog
SummaryA rewrite of Yield Prolog for Python
upload_time2023-04-06 11:41:55
maintainer
docs_urlNone
authorTim Hemel
requires_python>=3.6
license
keywords prolog
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # yldprolog

yldprolog is a rewrite of [YieldProlog](http://yieldprolog.sourceforge.net/), which compiles Prolog into source code that you can embed in your code. Yield Prolog supports several programming languages, yldprolog only supports Python.

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

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

The yldprolog compiler uses ANTLR and supports the most common Prolog constructs.

# Usage

## Compiling a Prolog program

Let's look at the following Prolog script:

```
%
% The following Prolog code is based on the example "monkey and banana"
% from: Ivan Bratko, Prolog Programming for Artificial Intelligence,
% third edition. ISBN 0-201-40375-7.
%

move(state(middle,onbox,middle,hasnot),
     grasp,
     state(middle,onbox,middle,has)).

move(state(P,onfloor,P,H),
     climb,
     state(P,onbox,P,H)).

move(state(P1,onfloor,P1,H),
     push(P1,P2),
     state(P2,onfloor,P2,H)).

move(state(P1,onfloor,B,H),
     walk(P1,P2),
     state(P2,onfloor,B,H)).

canget(state(_,_,_,has)).
canget(State1) :-
     move(State1,Move,State2),
     canget(State2).
```

You can compile this Prolog script with:

```
yldpc monkey.prolog > monkey.py
```

The result is a Python module that defines the predicates as functions.
You can use these modules in your program, for example.

```
# 1. construct the yldproglog engine
yp = YP()
# 2. load a script from a path or filename
yp.load_script_from_file(pathlib.Path(_SCRIPT_DIR) / 'monkey.py')
# 3. execute the query:
#    canget(state(atdoor, onfloor, atwindow, hasnot))
q = yp.query('canget', [yp.functor('state',
	[yp.atom('atdoor'), yp.atom('onfloor'),
	yp.atom('atwindow'), yp.atom('hasnot')])])
# 4. q is a generator that will give all solutions. Since this
#    query has infinitely many solutions, we will just get the
#    first one.
self.assertEqual(next(q), False)
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/timhemel/yldprolog",
    "name": "yldprolog",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "prolog",
    "author": "Tim Hemel",
    "author_email": "tim@securesoftware.nl",
    "download_url": "https://files.pythonhosted.org/packages/a3/ab/71fc90a98e90e2112424522c91d223c09aa63fa07f3a2357cac5ff271008/yldprolog-1.3.1.tar.gz",
    "platform": null,
    "description": "# yldprolog\n\nyldprolog is a rewrite of [YieldProlog](http://yieldprolog.sourceforge.net/), 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",
    "bugtrack_url": null,
    "license": "",
    "summary": "A rewrite of Yield Prolog for Python",
    "version": "1.3.1",
    "split_keywords": [
        "prolog"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "82108b0be6850f99d44d217e766bf9993932bce9c80ef6e351499159b008af14",
                "md5": "259f64e411db4e726bf20d7646f8b6d9",
                "sha256": "7e18884a197ebdce4155777fe5843363f6ae9bbe523f9d84fd2a3a74385026f5"
            },
            "downloads": -1,
            "filename": "yldprolog-1.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "259f64e411db4e726bf20d7646f8b6d9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 27610,
            "upload_time": "2023-04-06T11:41:53",
            "upload_time_iso_8601": "2023-04-06T11:41:53.650643Z",
            "url": "https://files.pythonhosted.org/packages/82/10/8b0be6850f99d44d217e766bf9993932bce9c80ef6e351499159b008af14/yldprolog-1.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a3ab71fc90a98e90e2112424522c91d223c09aa63fa07f3a2357cac5ff271008",
                "md5": "01744c6349a85591ce3201ad77a5af17",
                "sha256": "380d3e9c3429ffbb44497c70ae441694dd786ca498e78405bdb699db0e8dce4b"
            },
            "downloads": -1,
            "filename": "yldprolog-1.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "01744c6349a85591ce3201ad77a5af17",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 28941,
            "upload_time": "2023-04-06T11:41:55",
            "upload_time_iso_8601": "2023-04-06T11:41:55.723364Z",
            "url": "https://files.pythonhosted.org/packages/a3/ab/71fc90a98e90e2112424522c91d223c09aa63fa07f3a2357cac5ff271008/yldprolog-1.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-06 11:41:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "timhemel",
    "github_project": "yldprolog",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "yldprolog"
}
        
Elapsed time: 0.09387s