add arg
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
:- module(builtins, [(=)/2, (+)/2, (*)/2, (-)/2, (/)/2, (/\)/2,
|
||||
(\/)/2, (is)/2, (xor)/2, (div)/2, (//)/2, (rdiv)/2, (<<)/2,
|
||||
(>>)/2, (mod)/2, (rem)/2, (>)/2, (<)/2, (=\=)/2, (=:=)/2,
|
||||
(-)/1, (>=)/2, (=<)/2, (->)/2, (;)/2, (==)/2, catch/3,
|
||||
(-)/1, (>=)/2, (=<)/2, (->)/2, (;)/2, (==)/2, arg/3, catch/3,
|
||||
throw/1, true/0, false/0]).
|
||||
|
||||
% arithmetic operators.
|
||||
@@ -86,3 +86,13 @@ handle_ball(Ball, C, R) :- Ball = C, !, '$erase_ball', call(R).
|
||||
handle_ball(_, _, _) :- '$unwind_stack'.
|
||||
|
||||
throw(Ball) :- '$set_ball'(Ball), '$unwind_stack'.
|
||||
|
||||
% arg.
|
||||
|
||||
arg(N, Functor, Arg) :- var(N), !, functor(Functor, _, Arity), arg_(N, 1, Arity, Functor, Arg).
|
||||
arg(N, Functor, Arg) :- integer(N), !, functor(Functor, _, Arity), '$get_arg'(N, Functor, Arg).
|
||||
arg(N, Functor, Arg) :- throw(error(type_error(integer, N), arg/3)).
|
||||
|
||||
arg_(N, N, N, Functor, Arg) :- !, '$get_arg'(N, Functor, Arg).
|
||||
arg_(N, N, Arity, Functor, Arg) :- '$get_arg'(N, Functor, Arg).
|
||||
arg_(N, N0, Arity, Functor, Arg) :- N0 < Arity, N1 is N0 + 1, arg_(N, N1, Arity, Functor, Arg).
|
||||
|
||||
Reference in New Issue
Block a user