consult_file(_File):-
	get_env_var('IFE_HOME', _Ife_Home),
	name(_Ife_Home, _Str1),
	append(_Str1, "lib/uc/uc/kbs", _Str2),
	append(_Str2, _File, _Str3),
	name(_MC_fname, _SC_str3),
	[-_MC_fname].


refresh(_Concept) :-
	known(_Concept, _Value),
	ask_usr(_Concept, _Value).
refresh(_).					%% always succeed
refresh(_Concept, _Keys) :-
	known(_Concept, _Keys, _Value),
	ask_usr(_Concept, _Value).
refresh(_, _).					%% always succeed

refreshc(_Concept):-				%% if known, write
	known(_Concept,_Value),			%% if unknown, clear
	ask_usr(_Concept,_Value)
	;
	ask_usr(_Concept,' ').

refreshc(_Concept,_Keys):-
	known(_Concept,_Keys,_Value),
	ask_usr(_Concept,_Value)
	;
	ask_usr(_Concept,' ').

refresht(_Concept):-				%% ditto, for tell
	known(_Concept,_Value),
	tell_usr(_Concept,_Value)
	;
	true.

refresht(_Concept,_Keys):-
	known(_Concept,_Keys,_Value),
	tell_usr(_Concept,_Value)
	;
	true.

near(_X1, _Y1, _X2, _Y2, _Criteria) :-
	number(_X1), number(_Y1), number(_X2), number(_Y2), 
	_Criteria > ((_X1 - _X2) ^ 2 + (_Y1 - _Y2) ^ 2).

near(_X1, _Y1, _X2, _Y2, _Criteria) :-
	( number(_X1) -> _X3 = _X1 ; flt(_X1, _X3) ), 
	( number(_Y1) -> _Y3 = _Y1 ; flt(_Y1, _Y3) ), 
	( number(_X2) -> _X4 = _X2 ; flt(_X2, _X4) ), 
	( number(_Y2) -> _Y4 = _Y2 ; flt(_Y2, _Y4) ), 
	_Criteria > ((_X3 - _X4) ^ 2 + (_Y3 - _Y4) ^ 2).

location_near(_Latitude, _Longitude, _Location) :-
	position_of(_Location, _Lat, _Lng),
	near(_Latitude, _Longitude, _Lat, _Lng, 0.3).


%%  gen_integer(X,Seed) generates integers, incrementing from Seed.
%%  NG if arg1 is nonvar or arg2 is var.

gen_integer(X, Seed) :-
  var(X),
  integer(Seed),
  gen_integer_vc(X, Seed).

gen_integer_vc(X, Seed) :-
  X is Seed;
  (New_seed is Seed+1,
   gen_integer_vc(X, New_seed)).


%%  append(First_part, Second_part, List) iff List is the
%%  concatenation of the first two arguments.

append([], List, List).
append([Elem | First_part], Second_part, [Elem | List]) :-
  append(First_part, Second_part, List).

member(X,[X|_]).
member(X,[_|T]) :-
	member(X,T).

%%  chars_to_words(Chars, Words)
%%  parses a list of characters (read by read_until) into a list of words,
%%		striped down to only handle ints 

chars_to_words(Chars,Words) :- 
        chars_to_words(Words,Chars,[]).

chars_to_words([Word|Words],A,B) :- 
        chars_to_word(Word,A,C),  !,
        chars_to_words(Words,C,B).

chars_to_words([],A,A).


chars_to_word(Word,A,B) :- 		%% this bit repeated for valid tokens
        'C'(A,Char,C),
        is_digit(Char),  !,
        Init is Char-48,
        chars_to_integer(Init,Word,C,B).

chars_to_integer(Init,Final,A,B) :- 
        'C'(A,Char,C),
        is_digit(Char),  !,
        Next is Init*10-48+Char,
        chars_to_integer(Next,Final,C,B).

chars_to_integer(Final,Final,A,A).

is_digit(Char) :-
	Char >= "0", Char =< "9".	% decimal digit

chars_to_word(Word,A,B) :- 
        'C'(A,Char,C),
        is_space(Char),  !,
        chars_to_word(Word,C,B).
is_space(32).			% ` `
is_space(95).			% `_`		%% for bb input strings
is_space( 9).			% `\t`
is_space(10).			% `\n`
is_space(11).			% `\v`
is_space(12).			% `\f`
is_space(13).			% `\r`

%% to support finding number of petri network arcs
llen('[]',0) :-
	!.
llen([_L0,_L1|_L2],_L) :-
	!,
	llen(_L2,_Len),
	_L is _Len + 2.
llen([_L0|_L1],_L) :-
	llen(_L1,_Len),
	_L is _Len + 1.

first([X|_],X).

