Share Tips, Code Samples, etc. with the Visual Prolog community.
Vitaly Markov
Active Member
Posts: 40
Joined: 30 Nov 2003 0:01

Class for operation on lists in VIP7

Unread post by Vitaly Markov »

We (Vinitarkh and Alison) offer the class "listext_progz" for operation on lists in VIP7.
Two files (.cl and .pro) of this class are placed on a progz-forum:
http://www.progz.ru/forum/index.php?showtopic=31078
by two parts everyone. This class has 80 predicates. PFC "list" for me has seemed very poor. Predicates "minimum", "maximum", "removeDuplicates" of class "list" are made not very reliably and can be fatally completed on long lists. Therefore these predicates have been altered and now they are fast and reliable.

The brief description of "listext_progz" class:
1. Together with classical list-oriented predicates the class contains:
- Predicates for operation with sets.
- Special predicates for deriving arrangements, permutations and combinations of set.
- Predicates for creation of list of random numbers.
- Predicates for creation of sequences of items of arithmetical and geometrical progressions.
- Predicates of shifts to the left and to the right.
2. The majority of predicates are polymorphic.
3. The agreement about names of predicates:
Predicates are divided into the functional groups which are characterized by prefixes: check_, create_, cut_, get_, insert_, is_, remove_, replace_. Postfixes _d, _nd define modes of determinism. The postfix _Nth is used for operation with indexes of items of list.
4. Some predicates are duplicated in predicate styles and in the functional style. Predicate style is convenient in some tasks, in other tasks the functional style is convenient .
5. Class "listext_progz" is static and demands the PFC: std, math, redBlackTree and exception.
6. File "listext_progz.cl" is written in style PFC that allows to generate help automatically. If you see english errors - inform me and then I shall correct them.
7. File "listext_progz.pro" is written also in style PFC. Predicates are tested. However if someone will find the error or faster or reliable solution - prompt please and I shall correct. If you will not find some standard list-oriented predicates - too I shall be glad to hear and consider efficient ideas.

Thanks.
Steve Lympany
VIP Member
Posts: 56
Joined: 31 Mar 2001 23:01

Unread post by Steve Lympany »

Hi,
It looks useful. Can you make it simpler to download, and provide a single zip file here? Thanks
regards
Steve
Vitaly Markov
Active Member
Posts: 40
Joined: 30 Nov 2003 0:01

Unread post by Vitaly Markov »

Hi!
I am sorry. I attach single zip file. I have absolutely overlooked, that a visual-prolog-forum allows to do it.
:( Probably seldom I submit messages for this forum.
Thanks
Vinitarkh
Attachments
listext_progz.zip
A class "listext_progz" for operation on lists in VIP7
(11.61 KiB) Downloaded 1286 times
Kari Rastas
Active Member
Posts: 36
Joined: 4 Mar 2000 0:01

Unread post by Kari Rastas »

Code: Select all

LIST1 = lists2::create_RndRealList(4),         LIST2 = lists2::create_RndRealList(4),         LIST3 = lists2::create_RndRealList(4),         LIST4 = lists2::create_RndRealList(4),         LIST5 = lists2::create_RndRealList(4),         stdio::write("\nLIST1 =",LIST1,"\n"),         stdio::write("\nLIST2 =",LIST2,"\n"),         stdio::write("\nLIST3 =",LIST3,"\n"),         stdio::write("\nLIST4 =",LIST4,"\n"),         stdio::write("\nLIST5 =",LIST5,"\n").   LIST1 =[0.04081167350523174,0.9407666893675923,0.2281259661540389,0.6363639894407243]   LIST2 =[0.3039343669079244,0.03323988243937492,0.2806777900550515,0.7954026011284441]   LIST3 =[0.3039343669079244,0.03323988243937492,0.2806777900550515,0.7954026011284441]   LIST4 =[0.3039343669079244,0.03323988243937492,0.2806777900550515,0.7954026011284441]   LIST5 =[0.3039343669079244,0.03323988243937492,0.2806777900550515,0.7954026011284441]
Because randomInit should be used only once (first time when random is used) a better solution would be

Code: Select all

clauses     create_RndUnsignedList(Length, Max) = [math::random(Max) || std::for(_,1, Length)] :-         checkRandomInit().   clauses     create_RndRealList(Length) = [math::random() || std::for(_,1,Length)] :-         checkRandomInit().   class facts     randomInitUsed : boolean := false().   class predicates     checkRandomInit : ().   clauses     checkRandomInit():-         randomInitUsed = false(),!,         Now = time::new(),         Now:getDateAndTimeDetailed (Year, Month, Day, Hour, Minutes, SecondsReal),         Seconds  = math::trunc(SecondsReal),         Milliseconds = math::round((SecondsReal-Seconds)*1000.0),         math::randomInit(Year+Month+Day+Hour+Minutes+Seconds+Milliseconds),         randomInitUsed := true().       checkRandomInit().
Vitaly Markov
Active Member
Posts: 40
Joined: 30 Nov 2003 0:01

Unread post by Vitaly Markov »

Hi!
I ask a pardon for three-day silence.
1. About a zero based indexes.
I used 0-based indexes to not break 0-based style of PFC-class "list" in which predicates (nth, setNth, tryGetIndex) use 0-based indexes. The base of indexes is a simple question about the agreements. I am sure, that the usual human reason works with 1-based indexes more easy. I wanted to undertake boldness to offer PDC to expand a set of predicates of PFC-class "list" in the future. And to use in it 1-based indexes.

2. About a create_RndxxxxList.
Let to express Kari the big gratitude.
I knew about this problem certainly.
But I did not attach great importance to this question.
You, Kari, have offered really good solution. Thank you.

Vinitarkh.
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

In general PFC code is zero-based. There are however exceptions:
  • Existing code will not change base, because that would break otherwise correct programs
  • When interfacing to external software (mainly Win32 API) the base used in this software will be carried into PFC
I.e. where practical possible code will be zero-based.
Regards Thomas Linder Puls
PDC
Audun Tönnesen
Active Member
Posts: 36
Joined: 27 Apr 2000 23:01

Unread post by Audun Tönnesen »

Thanks so much for sharing this useful list-module!
For me, as an average programmer, many of these predicates would have been extremely difficult to create.
Regards,
Audun.
Post Reply