1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
.. $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!
|