On 23 Nov 2013, at 11:28, Daniel Diaz <[email protected]> wrote:

> Hi Sean
> 
> Well done !

Thanks. Praise indeed. Sadly lacking in the day job lately!

> However, I don’t understand why you added the call to keysort/2 since setof/3 
> already sorts the list (this is the only difference between setof/ and 
> bagof/3). You can remove it.

I wasn’t sure about that either because I am returning a pair with Line-Name 
i.e. line-number and test function and I wasn’t sure *how* the default sort 
would handle that so I rolled my own. Basically I was not sure what the 
collation order would be for my list. I don’t think the documentation says what 
it does to determine the ordering so I took no chances!

 I *will* take it out and see what happens though. In the documentation it says 
that it uses "sort(I,Instances)” but I couldn’t seem to relate that to my code. 
I will re-visit and try to understand again. One thing I know, it is worth 
getting good with the debugger which I am quite familiar with now.

> PS: about sockets: I have put a version in the git which adds the 
> SO_REUSEADDR option at socket creation. To get it:
> 
> git clone git://git.code.sf.net/p/gprolog/code gprolog-code

That’s nice to know… I will do a build today to get the “~” fix you did too. 
Getting the dreaded “address already in use” can be really irritating when you 
are rapid fire developing some server or client stuff.

> 
> BTW: if you write on the socket, you may to call flush_output(SO) to be sure 
> the data is sent (and thus accessible on the other side).

I have done enough with sockets over the years to know flush() is your friend! 
I will add a flush to be safe.

Lunch beckons, that some basketball with my son but tonight I hack for England. 
Having learned Lisp, Erlang, Haskell I am starting to think that Prolog is what 
I have been “yearning for” all my life! Oh my god, did I just say that! Yes, 
you did, no go out and get a life 
:)

All the best,
Sean.





> 
> Le 22 nov. 2013 à 23:43, Sean Charles <[email protected]> a écrit :
> 
>> 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.
>> 
>> 
>> 
>> 
>> 
>> -- 
>> Ce message a été vérifié par MailScanner pour des virus ou des polluriels et 
>> rien de suspect n'a été trouvé.
> 
> 
> -- 
> 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

Reply via email to