6
4

More than 3 years have passed since last update.

python 3.8.2でprologを動かしてみた

Last updated at Posted at 2020-06-11

「pyswip便利なんだけどpython 3に対応してないからな~泣」という声をネットのどこかで見かけたので、

python3.8.2でもpyswipちゃんと動いたよ」という報告をしようと思い、この記事を書いた。

蛇足だが、予言者でもない限り、「python3でも動く」とは確かに言えない。python3.8.2で動いても、python3.8.3以降で動く論理的な保証はどこにもないからだ。

1. pip install pyswip
2. 次のコードを実行

from pyswip import Prolog
p = Prolog()
p.assertz("father(michael, john)")
p.assertz("father(michael, gina)")
for s in p.query("father(X,Y)"):
    print(s["X"], "is the father of", s["Y"])

3. 次のように標準出力を得る

micheal is the father of john
micheal is the father of gina

参考: https://github.com/yuce/pyswip の「Examples」

6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4