Re: Predicate ordering when using current_predicate/1

Sean Charles <[email protected]>
Newsgroups gmane.comp.gnu.prolog.general
Message-ID <[email protected]>
Danieal,

Mission accomplished!

I ran with what you gave me and I now have a process that executes tests in the same order as they are declared in the source text. I had to learn (very quickly) about the A-B pair notation, something I had not seen before but as with the predicate indicator thing, once you know how it works the rest is easy…easier.

Here’s what I ended up with:
run_tests :-
        get_all_tests(AllTests),
        keysort(AllTests, SortedTests),
        maplist(exec_test, SortedTests),

The get_all_tests/1 predicate and the supporting acts look like this:
get_all_tests(Tests) :-
	setof(Line-Name, get_one_test(Name, Line), Tests).


get_one_test(Name, Line) :-
	current_predicate(Name/0),
	atom_concat('test_', _, Name),
	predicate_property(Name, prolog_line(Line)).


exec_test(_-TestFunction) :- /* omitted for brevity! */

Essentially I get all the test_ predicates then keysort/2 them into line number order and then maplist/2 over the exec_test/1 function which is now modified to accept a pair. Damn that’s useful to know!

So, once again, thank you very mud for your support in helping me out.

I am going to try to finish my Redis tests over the weekend and then I am going to update my “main” project with this improved code. in fact, I might even create a little github project and then include it as a dependency or something like that later on.

Have a great weekend!
:)
Sean.

_______________________________________________
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.