Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %-----------------------------------------------------------------------------%
- %
- % Lua Variables.
- %
- % This type represents the Mercury equivalent to Lua's variable list
- % espression, used to pass varadic function arguments and return
- % values.
- :- type vars
- ---> some [T] (var(T))
- ; some [T] (cons_var(T, vars))
- where equality is unify_vars.
- % Due to nil's special status as the abscence of value, a single
- % nil value is passed in place of the empty list and will unify
- % with lists of nil.
- %
- :- pred unify_vars(vars::in, vars::in) is det.
- :- implementation. % TODO: Move to main implementation
- unify_vars(var(T1), var(T2)) :- dynamic_cast(T1, T2).
- unify_vars(cons_var(T1, Vars1), cons_var(T2, Vars2) :-
- dynamic_cast(T1, T2),
- unify_vars(Vars1, Vars2).
- unify_vars(var(T1), cons_var(T2, var(nil))) :- dynamic_cast(T1, T2).
- unify_vars(cons_var(T1, var(nil)), var(T2)) :- dynamic_cast(T1, T2).
- :- interface.
- :- func vars(T, vars) = vars.
- :- mode vars(in, in) = out is det.
- :- mode vars(unused, out) = in is det.
- :- mode vars(out, out) = in is semidet.
- :- implementation. % TODO: Move to main implementation
- vars(T::in, Vars::in) = ('new cons_var'(T, Vars)::out).
- vars(_, Vars) = cons_var(_, Vars).
- vars(T1, Vars) = cons_var(T2, Vars) :- dynamic_cast(T1, T2).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement