Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates #191

Merged
merged 7 commits into from
Oct 27, 2024
Merged

Updates #191

merged 7 commits into from
Oct 27, 2024

Conversation

yuce
Copy link
Owner

@yuce yuce commented Oct 26, 2024

Enhancements

Python to Prolog Placeholders

Prolog.asserta, Prolog.assertz, Prolog.retract, Prolog.query methods take a format and optional arguments to convert Python values to strings.
The following types are recognized:

  • String
  • Integer
  • Float
  • pyswip.Atom
  • pyswip.Variable
  • Lists of the types above

Other types are converted to strings using the str function.

The placeholders are set using %p.

Example:

ids = [1, 2, 3]
joe = Atom("joe")
Prolog.assertz("user(%p, %p)", joe, ids)
list(Prolog.query("user(%p, IDs)", joe))

Added more examples

Moved The Towers of Hanoi example to pyswip.examples.hanoi package.
For example, here is how to solve the puzzle with 5 disks:

from pyswip.examples.hanoi import solve
solve(5)

Or:

from pyswip.examples.hanoi import solve
solve(5, simple=True)

It is also available via the command line:

python3 -m pyswip.examples.hanoi 5 --simple

Similarly, Coins example was moved to pyswip.examples.coins package.

@yuce yuce merged commit cc850b2 into master Oct 27, 2024
4 checks passed
@yuce yuce deleted the python-to-prolog branch October 27, 2024 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant