We can summarize all this in a table:
Method | [Reflexive "Mr. Boss"] |
[Reflexive "Mary"] |
[Reflexive ?x] |
---|---|---|---|
Reflexive βMr. Bossβ: himself |
π© | π₯ Fail | π© ?x = "Mr. Boss" |
Reflexive βMaryβ: herself |
π₯ Fail | π© | π© ?x = "Mary" |
Reflexive ?who: themself |
π© ?who ="Mr. Boss" |
π© ?who ="Mary" |
π© ?who =?x |
Here, a π© means a successful match, and a π₯ means a failed match.β For those that involve variables, we also list what the variable is connected to.
Matching multiple parameters
When we match a call with multiple parameters, we just match each parameter in turn.β But since one parameter might connect a variable to a value (or another variable), it can affect the matching of other parameters.
Easy case
When we match the call [Give "Mary" "Jill" "a nice raise"]
against the method:
Give ?giver ?receiver ?item: ?giver gave ?receiver ?item.
Each variable is in a different parameter, so matching is easy:
Task | Parameter 1 | Parameter 2 | Parameter 3 | |
---|---|---|---|---|
Call | Give |
"Mary" |
"Jill" |
"a nice raise" |
Method | Give |
?giver |
?receiver |
?item |
Connection | π© | π© "Mary" = ?giver |
π© "Jill" = ?receiver |
π© "a nice raise" = ?item |
Matching between parameters
What if we match the same call against the other method:
Give ?giver ?giver ?item: ?giver gave [Reflexive ?giver] ?item
Then we have a problem.β Parameter 1 wants to connect ?giver
wtih "Mary"
and parameter 2 wants to connect it with "Jill"
.
It can't do both, so the match fails:
Task | Parameter 1 | Parameter 2 | Parameter 3 | |
---|---|---|---|---|
Call | Give |
"Mary" |
"Jill" |
"a nice raise" |
Method | Give |
?giver |
?giver |
?item |
Connection | π© Give =Give |
π₯ "Mary" = ?giver |
π₯"Jill" = ?giver |
π© "a nice raise" = ?item |
On the other hand, the call [Give "Mary" "Mary" "a nice raise"]
works fine, because both parameters want to connect ?giver
to the same value:
Task | Parameter 1 | Parameter 2 | Parameter 3 | |
---|---|---|---|---|
Call | Give |
"Mary" |
"Mary" |
"a nice raise" |
Method | Give |
?giver |
?giver |
?item |
Connection | π©Give =Give |
π©"Mary" = ?giver |
π© "Mary" = ?giver |
π© "a nice raise" = ?item |
Fancy example
Now let's match against the same method, but change the call slightly:
[Give "Mary" ?somebody "a nice raise"]
we might do this because we want to print something about Mary giving someone a raise, but we don't care about who.β This matches:
Task | Parameter 1 | Parameter 2 | Parameter 3 | |
---|---|---|---|---|
Call | Give |
"Mary" |
?somebody |
"a nice raise" |
Method | Give |
?giver |
?giver |
?item |
Connection | π©Give =Give |
π©"Mary" = ?giver |
π©?somebody = ?giver |
π©"a nice raise" = ?item |
It connects the ?giver
, ?somebody
and "Mary"
all together.
Matching summary
Here's table of the matching results between different kinds of calls and different kinds of methods.β To save space, We'll just use two parameters and name it Task
:
Method | [Task 1 1] |
[Task 1 2] |
[Task 1 ?a] |
[Task ?a ?b] |
[Task ?a ?a] |
---|---|---|---|---|---|
Task 1 2: ... |
π₯ | π© | π©?a =2 |
π©?a =1 , ?b =2 |
π₯ |
Task 1 ?x: ... |
π©?x =1 |
π©?x =2 |
π©?a =?x |
π©?a =1 , ?b =?x |
π©?a =?x =1 |
Task ?x y: ... |
π©?x =y =1 |
π©?x =1 , ?y =2 |
π©?x =1 , ?b =?y |
π©?a =?x , ?b =?y |
π©?a =?x =y |
Task ?x ?x: ... |
π©?x =1 |
π₯ | π©?a =?x =1 |
π©?a =?x =?b |
π©?a =?x |