Re: Predicate ordering when using current_predicate/1

Daniel Diaz <[email protected]>
Newsgroups gmane.comp.gnu.prolog.general
Message-ID <[email protected]>
Hi,

here is a piece of code doing what you want

get_tests(L) :-

setof(t(File, Line, Name), get_one_test(File, Line,
Name), L).

get_one_test(File, Line, Name) :-

current_predicate(Name/0),

atom_concat('test_', _, Name),

predicate_property(Name, prolog_file(File)),

predicate_property(Name, prolog_line(Line)).

This returns a list containing triplets t(File, Line, Name)
where File is the file pathname of the test, Line
is the line number in the source file and Name the test
name (beginning by test_). The list is sorted on File
and then on Line.

I keep the File in case your tests reside in different files, if
it is not the case you simplify the code by removing everything
related to File (including predicate_property(...,
prolog_line(Line))).

If you only need the list of test names (and don't want the File
and Line), you can define

get_tests_name(AllTests) :-

get_tests(L),

findall(Name, member(t(_,_,Name), L), AllTests).

Then get_test_names does the job.

Daniel

Le 21/11/2013 16:48, emacstheviking a écrit :

Hi,

There is no mention of the actual order of returned
predicates, recently I created a testing framework and it has
this line of code thanks to Daniel,

findall(Name,(current_predicate(Name/0),
atom_concat('test_', _, Name)),AllTests)

I am writing tests now that rely upon them being executed
in the order that they are defined in the source file i.e. the
temporal order in which they were added to the database I
presume.

However, they do not seem to come out in the expected order
unless I have done something wrong but the above line of code
is what dictates the order of execution.

Sean.

--

Ce message a été vérifié par
MailScanner
pour des virus ou des polluriels et rien de
suspect n'a été trouvé.

_______________________________________________
Users-prolog mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/users-prolog
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.