.. $Id: pathological_answer.txt a2119c07028f 2008-10-27 mtnyogi $
.. 
.. Copyright © 2008 Bruce Frederiksen
.. 
.. Permission is hereby granted, free of charge, to any person obtaining a copy
.. of this software and associated documentation files (the "Software"), to deal
.. in the Software without restriction, including without limitation the rights
.. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
.. copies of the Software, and to permit persons to whom the Software is
.. furnished to do so, subject to the following conditions:
.. 
.. The above copyright notice and this permission notice shall be included in
.. all copies or substantial portions of the Software.
.. 
.. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
.. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
.. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
.. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
.. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
.. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
.. THE SOFTWARE.

restindex
    crumb: Pathological Answer
    page-description:
        The answer to the *pathological question* in Matching Two Patterns.
    /description
    format: rest
    encoding: utf8
    output-encoding: utf8
    include: no
    initialheaderlevel: 2
/restindex

uservalues
    filedate: $Id: pathological_answer.txt a2119c07028f 2008-10-27 mtnyogi $
/uservalues

====================
Pathological Answer
====================

This is the answer to the following question:

Pathological Question
=====================

What is the bound value of pattern variable ``$y`` after matching the
following two tuple patterns:

    Tuple pattern A:
        ``((ho, $_, ($a, $a)), ($a, $a, $b), ($a, *$b))``
    Tuple pattern B:
        ``($x, $x, $y)``

Answer
======

Let's take this step by step, matching each element of the two tuple patterns
in turn.

#. Match ``(ho, $_, ($a, $a))`` to ``$x``.

   This succeeds with the following binding:
   
   ``$x``:
       ``(ho, $_, ($a, $a))``

#. Match ``($a, $a, $b)`` to ``$x``.

   Because ``$x`` is bound to a value, this becomes the same as matching:

   - ``($a, $a, $b)`` to
   - ``(ho, $_, ($a, $a))``

   Which succeeds, binding:

   ``$a``:
       ``ho``
   ``$b``:
       ``($a, $a)``

   ``$_`` is an anonymous variable, so it is not bound (or bound to).

#. Match ``($a, *$b)`` to ``$y``.

   Because both ``$a`` and ``$b`` have bound values, this becomes the same as
   matching:

   - ``(ho, ho, ho)`` to
   - ``$y``

   Which succeeds, binding:

   ``$y``:
       ``(ho, ho, ho)``

So the overall match succeeds with the following bindings:

   ``$x``:
       ``(ho, $_, ($a, $a))``
   ``$a``:
       ``ho``
   ``$b``:
       ``($a, $a)``
   ``$y``:
       ``(ho, ho, ho)``

And so ``$y`` is ``(ho, ho, ho)``!

.. note::
   If you got this right, you should really be using Pyke!

