Merge pull request #58 from triska/master
ENHANCED: Better error handling if Type is invalid.
This commit is contained in:
@@ -27,15 +27,16 @@
|
|||||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
|
|
||||||
must_be(Type, Term) :-
|
must_be(Type, Term) :-
|
||||||
|
must_be_(type, Type),
|
||||||
must_be_(Type, Term).
|
must_be_(Type, Term).
|
||||||
|
|
||||||
|
|
||||||
must_be_(Type, _) :-
|
must_be_(Type, _) :-
|
||||||
var(Type),
|
var(Type),
|
||||||
instantiation_error(Type).
|
instantiation_error(Type).
|
||||||
must_be_(integer, Term) :- check_(integer, integer, Term).
|
must_be_(integer, Term) :- check_(integer, integer, Term).
|
||||||
must_be_(atom, Term) :- check_(atom, atom, Term).
|
must_be_(atom, Term) :- check_(atom, atom, Term).
|
||||||
must_be_(list, Term) :- check_(ilist, list, Term).
|
must_be_(list, Term) :- check_(ilist, list, Term).
|
||||||
|
must_be_(type, Term) :- check_(type, type, Term).
|
||||||
|
|
||||||
check_(Pred, Type, Term) :-
|
check_(Pred, Type, Term) :-
|
||||||
( var(Term) -> instantiation_error(Term)
|
( var(Term) -> instantiation_error(Term)
|
||||||
@@ -47,6 +48,10 @@ ilist(V) :- var(V), instantiation_error(V).
|
|||||||
ilist([]).
|
ilist([]).
|
||||||
ilist([_|Ls]) :- ilist(Ls).
|
ilist([_|Ls]) :- ilist(Ls).
|
||||||
|
|
||||||
|
type(type).
|
||||||
|
type(integer).
|
||||||
|
type(atom).
|
||||||
|
type(list).
|
||||||
|
|
||||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
can_be(Type, Term)
|
can_be(Type, Term)
|
||||||
@@ -63,6 +68,7 @@ ilist([_|Ls]) :- ilist(Ls).
|
|||||||
|
|
||||||
|
|
||||||
can_be(Type, Term) :-
|
can_be(Type, Term) :-
|
||||||
|
must_be(type, Type),
|
||||||
( var(Term) -> true
|
( var(Term) -> true
|
||||||
; can_(Type, Term) -> true
|
; can_(Type, Term) -> true
|
||||||
; type_error(Type, Term)
|
; type_error(Type, Term)
|
||||||
|
|||||||
Reference in New Issue
Block a user