Does Visual Prolog supports or plan to support generic predicates?
I'm using the 7.4 version and I have a section of my code that looks rather untidy because it has a recurrent pattern that, I think, could be neatly solved using generic predicates. The following 2 sample codes illustrate what I mea,.
1. Sample of code with a recurrent pattern
----------------------------------------------
Code: Select all
interface integration
predicates
get_sheet:()->sheet.
try_sheet:()->sheet determ.
get_text->text.
try_text->text determ.
.... More similar definitions below........
end interface integration
implement integration
/*
Returns the sheet that in this context. Throws an exception if one is not found*/
get_sheet()=Sheet:-
try_sheet()=Sheet,!.
get_sheet()=_:-
error::raise(Cursor, "Unable to find a sheet in this context").
/*
Returns a sheet in this context if any; fails if there is none*/
try_sheet()=Sheet:-
/*
Get any ancestor of this context*/
Ancestor = ancestors(This),
/*
See if the ancestor can be converted to a sheet*/
Sheet = tryconvert(sheet, Ancestor),!.
/*
Returns the text that is in this context. Throws an exception if none is not found*/
get_text()=Text:-
Text = try_text(),!.
get_text()=_:-
error::raise("Unable to find a text in this context").
/*
Returns text in this context if any; fails if there is none*/
try_text()=Text:-
/*
Get any ancestor of this context*/
Ancestor = ancestors(This),
/*
See if the ancestor can be converted to text*/
Text = tryconvert(text, Ancestor),!.
....
end implement integration
---------------------------------------------------------------------------------------
Code: Select all
interface integration{@Type}
predicates
get_{@Type}()->{@Type}.
try_{@Type}()->{@Type} determ.
end interface integration
interface integration{@Type}
/*
Returns the @Type that is in this context. Throws an exception if none is not found*/
get_{@Type}(_Cursor)=Type:-
Type = try_{@Type}(),!.
get_{@Type}()=_:-
error::raise("Unable to find a ", xxx(@Type), " in this context").
/*
Returns a text import file in this context if any; fails if there is none*/
try_{@Type}()=Type:-
/*
Get any ancestor of this context*/
Ancestor = ancestors(This),
/*
See if the ancestor can be converted to text*/
Type = tryconvert({@Type}, Ancestor),!.
end interface integration