Ritorniamo ad usare il Visual Prolog ed osserviamo che a proposito di liste esiste la classe list.
Ecco che cosa ho trovato nell’Help di Visual Prolog a propo-sito di questa classe:
Overview Package
SUMMARY: Domains Predicates DETAIL: Domains Predicates Class list
Package: list
The list class contains predicates to work on prolog lists.
Description
The predicates are declared using polymorphic list type creation, there the predicates can operate on any prolog lists.
Domain Summary filterPredicate
Deprecated use core::predicate_dt instead
Predicate Summary .
append: : (Elem* Front, Elem* Tail) -> Elem* List.
List is the result of appending Tail to Front.
append: : (Elem* Front1, Elem* Front2, Elem* Tail) -> Elem*
List.
List is the result of append(Front1, append(Front2, Tail)).
append: : (Elem* Front1, Elem* Front2, Elem* Front3, Elem*
Tail) -> Elem* List.
List is the result of append(Front1, append(Front2, ap-pend(Front3, Tail))).
append: : (Elem* Front1, Elem* Front2, Elem* Front3, Elem*
Front4, Elem* Tail) -> Elem* List.
List is the result of append(Front1, append(Front2, ap-pend(Front3, append(Front4, Tail)))).
appendList: : (Elem** ListList) -> Elem* List.
List is the result of appending all the lists in ListList.
classInfo: : classInfo.
Class information predicate.
decompose: : (Elem* List, function Separator) -> tuple*.
Decompose input list in some lists by Separator.
difference: : (Elem* List1, Elem* List2) -> Elem* List1ExceptList2.
differenceBy: : (comparator Comparator, Elem* List1, Elem2*
List2) -> Elem* List1ExceptList2.
differenceEq: : (predicate_dt Eq, Elem* List1, Elem2* List2) -> Elem* List1ExceptList2.
List1ExceptList2 contains the elements from List1 which are not in List2.
drop: : (positive Count, Elem* List) -> Elem* LastPart.
Drops the first Count elements from list List, and returns the remaining last elements as LastPart.
exists: : (Elem* List, predicate_dt Test) determ.
Succeeds if one of the members of List satisfies the Test.
filter: : (Elem* List, predicate_dt PositiveFilter) -> Elem*
FilteredPositiveList.
Extracts all items from List which fulfills the Filter.
OutElem.
Fold list over function
forAll: : (Elem* List, predicate Predicate).
Invoke Predicate for all list elements
getMember_nd: : (Elem* List) -> Elem Value nondeterm.
Returns the members Value of the list List.
getTupleMember_nd: : (tuple List) -> tuple Value nonde-term.
Tuple version of getMember_nd where two lists.
intersection: : (Elem* ListA, Elem* ListB) -> Elem* Inter-sectionAB.
intersectionBy: : (comparator Comparator, Elem* ListA, Elem* ListB) -> Elem* IntersectionAB.
intersectionEq: : (predicate_dt Eq, Elem* ListA, Elem* ListB) -> Elem* IntersectionAB.
Returns intersection of ListA and ListB.
isMember: : (Elem Value, Elem* List) determ.
isMemberBy: : (comparator Comparator, Test Value, Elem*
List) determ.
isMemberEq: : (predicate_dt Eq, Test Value, Elem* List) determ.
Succeds if Value is member of List.
length: : (Elem* List) -> positive Length.
Returns the length of the list List.
map: : (Elem* List, function Function) -> OutElem* NewList.
Convert list to another list
maximum: : (Elem* List) -> Elem Item.
maximumBy: : (comparator Comparator, Elem* List) ->
Elem Item.
Return maximum Item of List.
memberIndex_nd: : (Elem Value [out], positive Index [out], Elem* List) nondeterm.
Returns the members Value of the list List and their Index.
minimum: : (Elem* List) -> Elem Item.
minimumBy: : (comparator Comparator, Elem* List) ->
Elem Item.
Return minimum Item of List.
nDuplicates: : (Elem, positive N) -> Elem* NList.
Create list of N duplicates
nth: : (positive Index, Elem* List) -> Elem Item.
Return Item of List at position Index. Index is zero based.
remove: : (Elem* List, Elem Value) -> Elem* Rest.
removeAll: : (Elem* List, Elem Value) -> Elem* Rest.
removeAllBy: : (comparator Comparator, Elem* List, Elem2 Value) -> Elem* Rest.
removeAllEq: : (predicate_dt Eq, Elem* List, Elem2 Value) -> Elem* Rest.
Remove the all occurences of Value from List.
removeBy: : (comparator Comparator, Elem* List, Elem2 Value) -> Elem* Rest.
removeConsecutiveDuplicates: : (Elem* List) -> Elem*
Rest.
removeConsecutiveDuplicatesBy: : (core::comparator Com-parator, Elem* List) -> Elem* Rest.
removeConsecutiveDuplicatesEq: : (predicate_dt Eq, Elem*
List) -> Elem* Rest.
Remove the all consecutive duplicates from List (mainly for sorted list). Last occurences are retained. Complexity is O(N).
removeDuplicates: : (Elem* List) -> Elem* Rest.
removeDuplicatesBy: : (comparator Comparator, Elem*
List) -> Elem* Rest.
Remove the all duplicates from List. First occurences are retained. Complexity is O(N ln N)
removeDuplicatesEq: : (predicate_dt Eq, Elem* List) ->
Elem* Rest.
Remove the all duplicates from List. Last occurences are
reverse: : (Elem* List) -> Elem* Reverse.
Reverse is the reverse of List.
setNth: : (positive Index, Elem* List, Elem Item, Elem*
NewList [out]).
Returns the NewList with the Index’th element changed to Item. Index is zero based.
sort: : (Elem* List) -> Elem* Sorted.
sort: : (Elem* List, sortOrder Order) -> Elem* Sorted.
Sorted is the sorted version of List.
sortBy: : (comparator Comparator, Elem* List) -> Elem*
Sorted.
sortBy: : (comparator Comparator, Elem* List, sortOrder Order) -> Elem* Sorted.
Sorted is the sorted version of List.
split: : (positive Index, Elem* List, Elem* LeftList [out], Elem*
RightList [out]).
Splits the list List in two lists in a place of element of index Index. Index is zero based.
take: : (positive Count, Elem* List) -> Elem* FirstPart.
Takes the first Count elements from list List, and returns them as FirstPart.
tryGetIndex: : (Elem Item, Elem* List) -> positive Index determ.
tryGetIndexBy: : (comparator Comparator, Elem2 Item, Elem* List) -> positive Index determ.
tryGetIndexEq: : (predicate_dt Eq, Elem2 Item, Elem* List) -> positive Index determ.
Get Index of Item in the List. Index is zero based. Fails if Item is not found.
tryGetMemberBy: : (comparator Comparator, Test Value, Elem* List) -> Elem determ.
tryGetMemberEq: : (predicate_dt Eq, Test Value, Elem*
List) -> Elem determ.
Succeds if Value is member of List.
tryGetNth: : (positive Index, Elem* List) -> Elem Item de-term.
Return Item of List by Index. Index is zero based. Fails if the list is too short.
tryLastItem: : (Elem* List) -> Elem LastItem determ.
Get the LastItem from the List. Fails if List is empty.
union: : (Elem* ListA, Elem* ListB) -> Elem* UnionAB.
unionBy: : (comparator Comparator, Elem* ListA, Elem*
ListB) -> Elem* UnionAB.
unionEq: : (predicate_dt Eq, Elem* ListA, Elem* ListB) ->
Elem* UnionAB.
Returns union of ListA and ListB.
unzip: : (tuple*, A* AList [out], B* BList [out]).
Returns the the lists AList and BList from list of paired val-ues tuple(A, B).
unzip: : (tuple*, A* AList [out], B* BList [out], C* CList [out]).
Returns the the lists AList and BList from list of paired val-ues tuple(A, B).
zip: : (A* AList, B* BList) -> tuple*.
Returns the list of paired values tuple(A, B) from the lists AList and BList.
zip: : (A* AList, B* BList, C* CList) -> tuple*.
Returns the list of trippled values tuple(A, B, C) from the lists AList, BList and CList.
zipHead_nd: : (A* Alist, B* Blist) -> tuple nondeterm.
Returns the paired values tuple(A, B) from the lists AList and BList, ignoring misaligned tails.
zip_nd: : (A* AList, B* BList) -> tuple nondeterm.
Returns the paired values tuple(A, B) from the lists AList and BList.
questa classe. Costruiamo come al solito un nuovo proget-to usandoProject->New, chiamiamo questo nuovo progetto provalist, compiliamo, aggiungiamo un nuovo package chia-mato packscheda ed inseriamo in esso il form schedaform sotto riportato
Attiviamo la voce del menu File->New ed associamo a essa la seguente procedura:
Associamo alla pressione del tasto Push Button la seguente azione
Dobbiamo osservare l’uso del predicato append della clas-se list, detta classe è priva del costruttore new, quindi non possiamo istanziare dei suoi oggetti ma richiamiamo diretta-mente i suoi predicati mediante l’uso dei “::”. Da osservare che append richiede due parametri che sono entrambi delle liste, alla prima lista verrà appesa la seconda ed il risultato verrà restituito per essere inserito nella variabile Lista, quin-di non possiamo prendere quin-direttamente il contenuto della casella di testo edit_ctl ma bisogna trasformare questi in una lista.
Le caselle di testo sono degli oggetti della classe editControl , di questo oggetto usiamo solo il predicato getText che è ereditato dalla classe Window, ecco che cosa
ho trovato nell’Help a proposito di questo predicato:
LLIsta = listbox_ctl:getAll(),
listbox_ctl:clearAll(),
listbox_ctl:addList(Lista).
backtracking, 65 clausola terminale, 30 clausole di Horn, 28 clausole ricorsive, 30 fatti-funtore, 29 fatti-variabile, 29 liste, 57
toTerm, 34 toterm, 34
79
81