Pyke logic programming (7): Pattern Matching: "Two Patterns Matching"

Source: Internet
Author: User

Matching of two modes

You have seen different types of patterns and how they match with data.

Mode is used to generate facts (statements ). One way is to obtain the fact through inquiry, that is, the pattern matches the data.

Another way to generate facts is to use rules. I will explain it later.

Application rules, that is, matching between modes and data is required.

Before discussing the rules, we need to find out how the two modes match.

Simply put, all depends on the mode variable. Mode variables can be constrained not only into data, but also into other modes.

Constraint to text mode

Constrain the mode variable to the text mode, just like constrain it to the data in the text mode. That's all.

Constraint into another mode variable

If pattern variables A are constrained to B, that is, a is changed to B, they actually become the same pattern variables.

After the pattern variable A is bound to B, B is still free and unrestricted.

    • Before binding mode variable B to a value, it is wrong to say that A or B is already constrained.
    • No matter which one of the schema variables A or B is bound to a value, you can be sure that B is bound to that value.
    • If B is bound to a value, the same value can be obtained by matching with the mode variable A or B.

Regardless of the purpose and intent, pattern variables A and B are the same variables.

A pathological problem

After the two tuples match in one mode, what is the value of the pattern variable $ y constraint:

    • Tuples Mode:

      • (Ho, $ _, ($ A, $ A), ($ A, $ A, $ B), ($ A, * $ B ))
    • Tuples mode B:
      • ($ X, $ X, $ Y)

The answer is here. Don't peek at it ......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.