SHARE
TWEET

Untitled

a guest Dec 11th, 2019 127 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. func_call(Name/_/ResultIndex, Args, Result) :-
  2.     !,
  3.     List = [Name|Args],
  4.     nth0(ResultIndex, CallFunc, Result, List),
  5.     C=.. CallFunc,
  6.     call(C).
  7.    
  8.  
  9. func_call(Name/ArgsAmount, Args, Result):-
  10.     !,
  11.     func_call(Name/ArgsAmount/ArgsAmount, Args, Result).
  12.    
  13. func_call(F, X ,R) :-
  14.     current_predicate(F/N),
  15.     func_call(F/N/N , X ,R).
  16.    
  17. :- op(500, xfx, <#).
  18. :- op(450, xfy, #).
  19.    
  20. :- op(400, fx, #).
  21.  
  22. parse_args_chain(Head # Tail, [Head|TailArgs]) :-
  23.     !,
  24.     parse_args_chain(Tail, TailArgs).
  25.    
  26. parse_args_chain(Head, [Head]).
  27.  
  28. %Result <# Name # ArgsChain :-
  29.  %   parse_args_chain(ArgsChain, Args),
  30.   %  func_call(Name, Args, Result).
  31.    
  32. curry_call(function(Fun/NArgs, PrevArgs), Arg, Result) :-
  33.     append(PrevArgs, [Arg], AccuArgs),
  34.     N is NArgs - 1,
  35.     (
  36.         length(AccuArgs, N) ->
  37.             func_call(Fun, AccuArgs, Result) ;
  38.             Result = function(Fun/NArgs, AccuArgs)
  39.     ).
  40.    
  41. %Result <# Function # ArgsChain :-
  42.  %   initial_function(Function, IF),
  43.   %  curry(IF, ArgsChain, Result).
  44.                    
  45. curry(F, A # T, Result) :-
  46.     !,
  47.     curry_unpack(A, UA),
  48.     curry_call(F, UA, Res),
  49.     curry(Res, T, Result).
  50.    
  51. curry(F, A, Result) :-
  52.     curry_unpack(A, UA),
  53.     curry_call(F, UA, Result).
  54.  
  55. Result <# Function # ArgsChain :-
  56.     initial_function(Function, IF),
  57.     curry(IF, ArgsChain, Result), !.
  58.  
  59. initial_function(function(F, A), function(F, A)) :- !.
  60. initial_function(F, function(F, [])).
  61.  
  62. %curry(F, A # T, Result) :-
  63.  %   !, (
  64.   %      A = # (OtherFunction # OtherArgs) ->
  65.    %     Sub <# OtherFunction # OtherArgs, curry(F, Sub # T, Result) ;
  66.     %    curry(F, A, SubResult), curry(SubResult, T, Result)
  67.      %   ).
  68.  
  69. %curry(F, A, Result) :-
  70.  %   (
  71.   %      A = # (OtherFunction # OtherArgs) ->
  72.    %     Sub <# OtherFunction # OtherArgs, curry(F, Sub, Result) ;
  73.     %    curry_call(F, A, Result)
  74.     %).
  75.    
  76. curry_unpack(#(F # Args), AU) :-
  77.     !,
  78.     initial_function(F, IF),
  79.     curry(IF, Args, AU).
  80. curry_unpack(A, A).
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top