aboutsummaryrefslogtreecommitdiff
path: root/locale/eo/LC_MESSAGES/_tils/2021-04-24-common-lisp-argument-precedence-order-parameterization-of-a-generic-function.po
blob: 2676e93698f80c3a4ec900f58507081f7adbe5ac (about) (plain) (blame)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#
msgid ""
msgstr ""

msgid ""
"title: Common Lisp argument precedence order parameterization of a generic "
"function"
msgstr ""

msgid "date: 2021-04-24"
msgstr ""

msgid "layout: post"
msgstr ""

msgid "lang: en"
msgstr ""

msgid ""
"ref: common-lisp-argument-precedence-order-parameterization-of-a-generic-"
"function"
msgstr ""

msgid ""
"When CLOS dispatches a method, it picks the most specific method definition "
"to the argument list:"
msgstr ""

msgid ""
"\n"
"* (defgeneric a-fn (x))\n"
"#<STANDARD-GENERIC-FUNCTION A-FN (0) {5815ACB9}>\n"
"\n"
"* (defmethod a-fn (x) :default-method)\n"
"#<STANDARD-METHOD A-FN (T) {581DB535}>\n"
"\n"
"* (defmethod a-fn ((x number)) :a-number)\n"
"#<STANDARD-METHOD A-FN (NUMBER) {58241645}>\n"
"\n"
"* (defmethod a-fn ((x (eql 1))) :number-1)\n"
"#<STANDARD-METHOD A-FN ((EQL 1)) {582A7D75}>\n"
"\n"
"* (a-fn nil)\n"
":DEFAULT-METHOD\n"
"\n"
"* (a-fn \"1\")\n"
":DEFAULT-METHOD\n"
"\n"
"* (a-fn 0)\n"
":A-NUMBER\n"
"\n"
"* (a-fn 1)\n"
":NUMBER-1\n"
msgstr ""

msgid ""
"CLOS uses a similar logic when choosing the method from parent classes, when"
" multiple ones are available:"
msgstr ""

msgid ""
"* (defclass class-a () ())\n"
"\n"
"#<STANDARD-CLASS CLASS-A {583E0B25}>\n"
"* (defclass class-b () ())\n"
"\n"
"#<STANDARD-CLASS CLASS-B {583E7F6D}>\n"
"* (defgeneric another-fn (obj))\n"
"\n"
"#<STANDARD-GENERIC-FUNCTION ANOTHER-FN (0) {583DA749}>\n"
"* (defmethod another-fn ((obj class-a)) :class-a)\n"
"; Compiling LAMBDA (.PV-CELL. .NEXT-METHOD-CALL. OBJ):\n"
"; Compiling Top-Level Form:\n"
"\n"
"#<STANDARD-METHOD ANOTHER-FN (CLASS-A) {584523C5}>\n"
"* (defmethod another-fn ((obj class-b)) :class-b)\n"
"; Compiling LAMBDA (.PV-CELL. .NEXT-METHOD-CALL. OBJ):\n"
"; Compiling Top-Level Form:\n"
"\n"
"#<STANDARD-METHOD ANOTHER-FN (CLASS-B) {584B8895}>\n"
msgstr ""

msgid ""
"Given the above definitions, when inheriting from `class-a` and `class-b`, "
"the order of inheritance matters:"
msgstr ""

msgid ""
"* (defclass class-a-coming-first (class-a class-b) ())\n"
"#<STANDARD-CLASS CLASS-A-COMING-FIRST {584BE6AD}>\n"
"\n"
"* (defclass class-b-coming-first (class-b class-a) ())\n"
"#<STANDARD-CLASS CLASS-B-COMING-FIRST {584C744D}>\n"
"\n"
"* (another-fn (make-instance 'class-a-coming-first))\n"
":CLASS-A\n"
"\n"
"* (another-fn (make-instance 'class-b-coming-first))\n"
":CLASS-B\n"
msgstr ""

msgid ""
"Combining the order of inheritance with generic functions with multiple "
"arguments, CLOS has to make a choice of how to pick a method given two "
"competing definitions, and its default strategy is prioritizing from left to"
" right:"
msgstr ""

msgid ""
"* (defgeneric yet-another-fn (obj1 obj2))\n"
"#<STANDARD-GENERIC-FUNCTION YET-ANOTHER-FN (0) {584D9EC9}>\n"
"\n"
"* (defmethod yet-another-fn ((obj1 class-a) obj2) :first-arg-specialized)\n"
"#<STANDARD-METHOD YET-ANOTHER-FN (CLASS-A T) {5854269D}>\n"
"\n"
"* (defmethod yet-another-fn (obj1 (obj2 class-b)) :second-arg-specialized)\n"
"#<STANDARD-METHOD YET-ANOTHER-FN (T CLASS-B) {585AAAAD}>\n"
"\n"
"* (yet-another-fn (make-instance 'class-a) (make-instance 'class-b))\n"
":FIRST-ARG-SPECIALIZED\n"
msgstr ""

msgid ""
"For that, we use the `:argument-precedence-order` option when declaring a "
"generic function:"
msgstr ""

msgid ""
"* (defgeneric yet-another-fn (obj1 obj2) (:argument-precedence-order obj2 obj1))\n"
"#<STANDARD-GENERIC-FUNCTION YET-ANOTHER-FN (2) {584D9EC9}>\n"
"\n"
"* (yet-another-fn (make-instance 'class-a) (make-instance 'class-b))\n"
":SECOND-ARG-SPECIALIZED\n"
msgstr ""

msgid ""
"I liked that the `:argument-precedence-order` option exists. We shouldn't "
"have to change the arguments from `(obj1 obj2)` to `(obj2 obj1)` just to "
"make CLOS pick the method that we want. We can configure its default "
"behaviour if desired, and keep the order of arguments however it best fits "
"the generic function."
msgstr ""

msgid "Comparison with Clojure"
msgstr ""

msgid "Clojure has an equivalent, when using `defmulti`."
msgstr ""

msgid ""
"Since when declaring a multi-method with `defmulti` we must define the "
"dispatch function, Clojure uses it to pick the method definition. Since the "
"dispatch function is required, there is no need for a default behaviour, "
"such as left-to-right."
msgstr ""

msgid "Conclusion"
msgstr ""

msgid ""
"Making the argument precedence order configurable for generic functions but "
"not for class definitions makes a lot of sense."
msgstr ""

msgid ""
"One shouldn't change the order of arguments of a generic function for the "
"sake of tailoring it to the CLOS priority ranking algorithm, but doing it "
"for a class definition is just fine."
msgstr ""

msgid "TIL."
msgstr ""

msgid ""
"CLOS has to make a choice between the first and the second definition of "
"`yet-another-fn`, but its choice is just a heuristic. What if we want the "
"choice to be based on the second argument, instead of the first?"
msgstr ""

msgid ""
"When declaring a class, we can choose the precedence order, and that is "
"about it. But when defining a generic function, the order of arguments is "
"more important to the function semantics, and the argument precedence being "
"left-to-right is just the default behaviour."
msgstr ""

msgid "References"
msgstr ""

msgid ""
"[Object-Oriented Programming in Common Lisp: A Programmer's Guide to "
"CLOS](https://en.wikipedia.org/wiki/Object-"
"Oriented_Programming_in_Common_Lisp), by Sonja E. Keene"
msgstr ""

#~ msgid ""
#~ "CLOS has to make a choice between the first and the second definition of "
#~ "`yet-another-fn`, but its choice is just a heuristic. What if we want to the"
#~ " choice to be based on the second argument first?"
#~ msgstr ""

#~ msgid ""
#~ "When declaring a class, we can choose the precedence order, and that is "
#~ "about it. But when defining a generic function, the order of argumentws is "
#~ "more important to the function semantics, and the argument precedence being "
#~ "left-to-right is just the default behaviour."
#~ msgstr ""