|
203 | 203 |
|
204 | 204 |
|
205 | 205 | metta_defn_return(Self, Original, Body, WrappedBody, ReturnVal):-
|
206 |
| - if_or_else(metta_defn_decl(Self, Original, Body, WrappedBody, ReturnVal), metta_defn_fallback(Self, Original, Body, WrappedBody, ReturnVal)). |
| 206 | + if_or_else(metta_defn_decl(Self, Original, Body, WrappedBody, ReturnVal), |
| 207 | + metta_defn_fallback(Self, Original, Body, WrappedBody, ReturnVal)). |
207 | 208 |
|
208 | 209 | metta_defn_decl(Self, [Op | Parameters], Body, [let, ReturnVal, Body, ReturnVal], ReturnVal):- metta_defn(Self, [Op | Parameters], Body).
|
| 210 | + |
| 211 | +must_length(List,Len):- is_list(List),!,must_det_lls(length(List,Len)). |
| 212 | +must_length(List,Len):- integer(Len),!,must_det_lls(length(List,Len)). |
| 213 | +must_length(List,Len):- trace,length(List,Len). |
| 214 | + |
| 215 | +metta_defn_fallback(_Self, [Op | Parameters], [let, ReturnVal, Body, ReturnVal], Body, ReturnVal):- |
| 216 | + must_length(Parameters, Len), |
| 217 | + format(atom(Fn),'mc_~w__~w',[Len,Op]), |
| 218 | + current_predicate(Fn/_), |
| 219 | + Body = ['call-fn',Fn|Parameters],!. |
| 220 | + |
209 | 221 | metta_defn_fallback(_Self, [Op | Parameters], Body, Body, ReturnVal):-
|
210 | 222 | Body = [let, [quote, ReturnVal], [quote, [Op | Parameters]], ReturnVal].
|
211 | 223 |
|
212 | 224 |
|
213 | 225 | metta_typed_defn(Self, ParamTypes, RetType, Head, WrappedBody, ReturnVal):- Head = [Op | Parameters],
|
214 | 226 | function_declaration(Self, Op, _Len, Parameters, ParamTypes, RetType, WrappedBody, ReturnVal).
|
215 | 227 |
|
216 |
| -function_declaration(Self, Op, Len, Parameters, ParamTypes, RetType, WrappedBody, ReturnVal) :- |
| 228 | +function_declaration(_, Op, Len, Parameters, ParamTypes, RetType, WrappedBody, ReturnVal) :- |
| 229 | + must_det_lls(( |
217 | 230 | %Self = '&self',
|
218 | 231 | len_or_unbound(Parameters, Len),
|
| 232 | + %(var(Len)->op_farity(Op, Len);true), |
| 233 | + %len_or_unbound(Parameters, Len), |
| 234 | + nop(no_repeats_var(NRR)), |
219 | 235 | metta_defn_return(Self, [Op | Parameters], Body, WrappedBody, ReturnVal),
|
220 |
| - len_or_unbound(Parameters, Len), |
| 236 | + must_length(Parameters, Len), |
221 | 237 | NR = ([Op | Parameters] + Body),
|
222 |
| - copy_term(NR, NRR), |
223 |
| - no_repeats_var(NRR), |
224 | 238 | head_body_typedef(Self, Op, Len, ParamTypes, RetType, [Op | Parameters], Body),
|
225 |
| - NR = NRR. %nop(write_src_nl(metta_defn(Self, [Op | Parameters], Body))). |
| 239 | + NR = NRR)). %nop(write_src_nl(metta_defn(Self, [Op | Parameters], Body))). |
226 | 240 |
|
227 | 241 | head_body_typedef(Self, Op, Len, ParamTypes, RetType, Head, Body):-
|
228 |
| - (src_data_ordinal(Self, [=, Head, Body], ClauseOrdinal)*->true; (ClauseOrdinal = -1)), |
| 242 | + (src_data_ordinal(Self, [=, Head, Body], ClauseOrdinal)*->true; |
| 243 | + (src_data_ordinal(Self, [=, Head, _], ClauseOrdinal)*->true; |
| 244 | + (ClauseOrdinal = -1))), |
229 | 245 | length(ParamTypes, Len),
|
230 | 246 | SrcObject = pr(ParamTypes, RetType),
|
231 | 247 | findall(TypeDeclLoc-SrcObject, (src_data_ordinal(Self, [:, Op, [Ar|Type]], TypeDeclLoc), Ar=='->', append(ParamTypes, [RetType], Type)), SrcObjectList),
|
232 |
| - nearest_src_object(SrcObject, ClauseOrdinal, SrcObjectList). |
| 248 | + nearest_src_object(SrcObject, ClauseOrdinal, SrcObjectList),!. |
| 249 | +head_body_typedef(Self, Op, Len, ParamTypes, RetType, _Head, _Body):- |
| 250 | + get_operator_typedef(Self, Op, Len, ParamTypes, RetType). |
233 | 251 |
|
234 | 252 | src_data_ordinal(_Self, Data, Ordinal):-
|
235 | 253 | user:metta_file_buffer(0, Ordinal, _TypeNameCompound, Data, _NamedVarsListC, _Context, _Range).
|
|
250 | 268 | DistanceOther is LocOther-ClauseOrdinal,
|
251 | 269 | DistanceOther>0, DistanceOther<Distance), !.
|
252 | 270 |
|
253 |
| -nearest_src_object(SrcObject, _, SrcObjectList):- last(_ - SrcObject, SrcObjectList). |
| 271 | +nearest_src_object(SrcObject, _, SrcObjectList):- last(_ - SrcObject, SrcObjectList),!. |
| 272 | + |
254 | 273 |
|
255 | 274 | finfo([Op|Args]):- is_list(Args), !, length(Args, Len), finfo(Op, Len).
|
256 | 275 | finfo(Op):- atomic(Op), !, finfo(Op, _, _).
|
|
259 | 278 | finfo(Op, Len, Head) :-
|
260 | 279 | % length(Parameters, Len),
|
261 | 280 | op_farity(Op, Len),
|
| 281 | + succ(Len,LenP1), |
262 | 282 | call_showing(predicate_behavior(Self, Op, Len, [List|_]), predicate_behavior(Self, Op, Len, List)),
|
263 | 283 | length(Parameters, Len),
|
264 | 284 | length(ParamTypes, Len),
|
265 | 285 | [Op|Parameters] = Head,
|
266 |
| - call_showing(get_ftype('=', _RetType1, 20, Self, Head, TypeO), get_ftype(Self, Head, TypeO)), |
| 286 | + call_showing(get_ftype('=', _RetType1, 20, Self, Head, TypeO), [['get-ftype', Self, Head],==>,TypeO]), |
267 | 287 | %call_showing(metta_atom(_, [iz, Op, _])),
|
268 | 288 | %call_showing(metta_atom(_, [':', Op, _])),
|
269 |
| - % ReturnVal = '$VAR'('ReturnVal'), |
270 |
| - call_showing(function_declaration_scores(Self, Op, Len, Parameters, ParamTypes, _RetType, _Body, _ReturnVal, _Scores)), |
271 |
| - call_showing((metta_atom(KB, [A, B|Out]), sub_var(Op, [A, B])), ist(KB, [A, B|Out])), |
| 289 | + ReturnVal = '$VAR'('_returnVal'), |
| 290 | + call_showing(transpiler_predicate_store(Op, LenP1, _, _)), |
| 291 | + call_showing(transpiler_clause_store(Op, LenP1, _, _, _, _, _, _, _)), |
| 292 | + format(atom(Fn),'mc_~w__~w',[Len,Op]), % forall(current_predicate(Fn/LenP1),listing(Fn/LenP1)), |
| 293 | + call_showing(Fn/LenP1), |
| 294 | + call_showing(function_declaration_scores(Self, Op, Len, Parameters, ParamTypes, _RetType, Body, ReturnVal,_)), |
| 295 | + if_t(\+ metta_defn(Self, [Op | Parameters], Body), call_showing(metta_defn_return(Self, [Op | Parameters], Body, _, ReturnVal),[=,[Op | Parameters],Body])), |
| 296 | + call_showing((metta_atom(KB, [A, B|Out]), sub_var(Op, [A, B])), [ist,KB, [A, B|Out]]), |
272 | 297 | true.
|
273 | 298 |
|
274 |
| -call_showing(Var):- \+ callable(Var), !. |
275 |
| -call_showing(Atom):- atom(Atom), !, current_predicate(Atom/_, SHOWP), !, call_showing(SHOWP, SHOWP). |
276 |
| -call_showing(Op/Len):- !, current_predicate(Op/Len, SHOWP), !, call_showing(SHOWP, SHOWP). |
277 |
| -call_showing(SHOWP):- call_showing(SHOWP, SHOWP), !. |
| 299 | +call_showing(Var):- \+ callable(Var), !, write_src_nl(not(callable(Var))). |
| 300 | +call_showing(Atom):- atom(Atom), \+ current_predicate(Atom/_, _), !, write_src_nl(unknown(Atom)). |
| 301 | +call_showing(Atom):- atom(Atom), !, forall(current_predicate(Atom/N),call_showing(Atom/N)). |
| 302 | +call_showing(Op/Len):- \+ current_predicate(Op/Len), !, write_src_nl(unknown(Op/Len)). |
| 303 | +call_showing(Op/Len):- !, forall(current_predicate(Op/Len, SHOWP), call_showing(clause(SHOWP,Body), (SHOWP:-Body))). |
| 304 | +call_showing(SHOWP):- \+ current_predicate(_, SHOWP), !, write_src_nl(unknown(SHOWP)). |
| 305 | +call_showing(SHOWP):- call_showing(SHOWP, SHOWP). |
278 | 306 |
|
279 |
| -call_showing(SHOWP, Template):- current_predicate(_, SHOWP), !, |
| 307 | +call_showing(SHOWP, Template):- |
280 | 308 | no_repeats_var(TemplateNR),
|
281 | 309 | findall(Template, (SHOWP, TemplateNR=Template), ScoredBodies),
|
282 |
| - maplist(write_src_nl, ScoredBodies), !. |
283 |
| -call_showing(SHOWP, _Template):- write_src_nl(unknown(SHOWP)). |
| 310 | + maplist(output_showing, ScoredBodies), |
| 311 | + ignore((ScoredBodies==[], functor(Template,F,A),output_showing(missing(F/A)))). |
| 312 | + |
| 313 | +output_showing(List):- is_list(List),!,write_src_nl(List). |
| 314 | +output_showing(Info):- w_color(white,write_w_attvars(Info)),nl, !. |
| 315 | +output_showing(Info):- write_src_nl(Info). |
| 316 | + |
| 317 | + |
284 | 318 |
|
285 | 319 | function_declaration_scores(Self, Op, Len, Parameters, ParamTypes, RetType, Body, ReturnVal, Score + HScore):-
|
286 | 320 | function_declaration(Self, Op, Len, Parameters, ParamTypes, RetType, Body, ReturnVal),
|
|
0 commit comments