Skip to content

Commit

Permalink
Partial impelementations of new current-[predicate/function]-arity.
Browse files Browse the repository at this point in the history
* See issue #177
* The new mettalog predicates are meant to report the arity of a
  function and its corresponding predicate defined e.g. at the repl,
  but without an explicit declaration of their arities. The two new
  predicates should query the mettalog database for a predicate/function
  compiled into a Prolog predicate with a compilation prefix ('mc__')
  but that doesn't seem to work as expected.
  • Loading branch information
stassa committed Dec 12, 2024
1 parent 6af3149 commit a5fbc24
Showing 1 changed file with 44 additions and 10 deletions.
54 changes: 44 additions & 10 deletions prolog/metta_lang/metta_eval.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1830,18 +1830,52 @@
% =================================================================
% =================================================================
% =================================================================
% METTLOG COMPILER PREDEFS
% =================================================================
% =================================================================
% =================================================================
% METTALOG COMPILER PREDEFS
% =================================================================
% =================================================================
% =================================================================

%/* TODO: this should take into account the compilation prefix but
eval_20(_Eq,_RetType,_Dpth,_Slf,['current-predicate-arity',F],A):-
% These two are no longer strictly compiler redefinitions - the compiler
% predicates should be predicate/function-arity (not "current"), for
% arities explicitly declared by the user. This pair of predicates
% should instead handle deduced arities of functions defined but without
% an explicit arity declaration.
!,
eval_for('Symbol',F,FF),
current_predicate_arity(FF,A).
eval_20(_Eq,_RetType,_Dpth,_Slf,['current-function-arity',F],A):-
!,
eval_for('Symbol',F,FF),
current_function_arity(FF,A).
%*/

/* TODO: This could work but the prefixed prdicate/function is not found.
eval_20(_Eq,_RetType,_Dpth,_Slf,['current-predicate-arity',F],A):-
!,
eval_for('Symbol',F,FF),
transpile_prefix(P),
atom_concat(P,FF,FF_mc),
current_predicate_arity(FF_mc,A).
eval_20(_Eq,_RetType,_Dpth,_Slf,['current-function-arity',F],A):-
!,
eval_for('Symbol',F,FF),
transpile_prefix(P),
atom_concat(P,FF,FF_mc),
current_function_arity(FF_mc,A).
*/

current_predicate_arity(F,A):-
metta_atom('&self',[:,F,[->|Args]]),
!,
length(Args,A).
current_predicate_arity(F,A):-
current_predicate(F/A).

eval_20(_Eq,_RetType,_Dpth,_Slf,['predicate-arity',F],A):- !,
eval_for('Symbol',F,FF),
predicate_arity(FF,A).
eval_20(_Eq,_RetType,_Dpth,_Slf,['function-arity',F],A):- !,
eval_for('Symbol',F,FF),
function_arity(FF,A).
current_function_arity(F,A):-
current_predicate_arity(F,PA)
,A is PA - 1.



Expand Down

0 comments on commit a5fbc24

Please sign in to comment.