users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Predicate searching by wildcard or similar


From: Daniel Diaz
Subject: Re: Predicate searching by wildcard or similar
Date: Fri, 08 Nov 2013 18:36:42 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0

Hi Sean,

since it is possible to have 2 predicates with the same name but different number of arguments, both information (name and arity) are needed to identifiy a given predicate. A Prolog term Name/Arity is called a predicate indicator (PI). Several built-in predicates accept/return a PI. It is the case of current_predicate (btw I should write current_predicate/1 ;-)).

Daniel


Le 08/11/2013 00:06, Sean Charles a écrit :
Daniel,

I tried out the code, perfect!

However I was surprised (and suitably delighted and impressed) that one can write X/Y in that predicate …… could you explain exactly what is going on here as it is not something I have encountered yet. There *may* be something like it in my AOP book but it’s in work right now! I know there is an odd “difference list syntax” in that book too but that uses “\” not “/“.

Thanks a lot once again.

Sean




On 5 Nov 2013, at 21:41, Paulo Moura <address@hidden> wrote:

Hi Sean,

On 05/11/2013, at 21:27, Sean Charles <address@hidden> wrote:

Hi,

I just wrote a *really simple* testing framework for my project, it looks like this at the test script end:

test_package([it('should ensure that global values have expected settings', defaults_correctly_set_test)
     ,it('should correctly set the quiet flag on "-q"', respect_quiet('-q'))
     ,it('should correctly set the quiet flag on "--quiet"', respect_quiet('--quiet'))
     ,it('should correctly set the wrap flag on "--wrap"', respect_wrap)
     ,it('should correctly set the check flag on "--nocheck"', respect_check)
     ,it('should add unhandled options as source filenames', filename_check)
     ,it('should throw exceptions on unknown options', handle_unknown_options)
     ]).

The test_package predicate is called from the framework by the script, the script pulls in the file and that has an initialisation instruction:

:- initialization(run_tests).

run_tests :-
test_package(AllTests),
maplist(call, AllTests),
ink(normal, '*done*'),
stop.


What would have made it *really* nice was to have been able to find all predicates starting with test_ or ending with _test etc. so that I would not have needed to make the test_package predicate unify the variable with the list of tests to be run. Some tests mentioned above...

defaults_correctly_set_test :-
cl_set_defaults,
get_all_globals([],[],user_input,user_output,php,nowrap,check,plain,noisy).


respect_quiet(Flag) :-
cl_set_defaults,
process_option(Flag),
get_all_globals(_,_,_,_,_,_,_,_,quiet).


As you can see, having to enter the test predicate AND enter it in the test package isn’t ideal ALTHOUGH it does allow me to provide a nice label but I could have done that with a really long predicate name anyway.

So, how would I do that in GNU Prolog…if it is possible. The listing() predicate is not much help in this instance…

You may find some inspiration on the Logtalk unit test tool, which uses the term-expansion mechanism in its implementation to collect the tests defined in an unit in order to run them. See:

https://github.com/LogtalkDotOrg/logtalk3/tree/master/tools/lgtunit

You should also be able to use it for testing your project code.

Cheers,

Paulo

-----------------------------------------------------------------
Paulo Moura
Logtalk developer

Email: <mailto:address@hidden>
Web:   <http://logtalk.org/>
-----------------------------------------------------------------





_______________________________________________
Users-prolog mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/users-prolog


--


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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]