Pyke logical programming (8): Pattern Matching: "answers to pathological questions"

Source: Internet
Author: User
Answers to pathology questions

This is the answer to the following question:

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)
Answer

Let's match and combine the members of the two tuples one by one.

    • (Ho, $ _, ($ A, $ A) matches with $ X.

      Matched successfully:

      $ X constraints to (Ho, $ _, ($ A, $ ))

    • ($ A, $ A, $ B) matches with $ X.

      Because $ X has bound the value above, this matching actually becomes:

      ($ A, $ A, $ B) matches with (Ho, $ _, ($ A, $)

      The following constraints are imposed:

      $ A to Ho

      $ B to ($ A, $)

      $ _ Is an anonymous variable with no value. It cannot constrain other variables or be subject to other variables.

    • ($ A, * $ B) matches with $ Y.

      Because $ A and $ B already have constraints, this match actually becomes:

      (Ho, Ho, Ho) matches with $ y

      The following constraints are imposed:

      $ Y to (Ho, Ho, Ho)

In short, the matching process completes the constraints of the following values:

$ X to (Ho, $ _, ($ A, $ ))

$ A to Ho

$ B to ($ A, $)

$ Y to (Ho, Ho, Ho)

The conclusion is: $ Y equals (Ho, Ho, Ho ).

Note: If the answer is correct, you should use Pyke.

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.