10. Marts 2008

Čaklais

Nebiju iedomājies, ka pretī slinkajam (lazy) var stāvēt arī dedzīgais (eager): piemēram, čaklā inicializācija pret slinko. Interesanti, jo čaklā ideja ir noklusētā, bet slinko uztveram kā dizaina elementu.

No vikijas: An atom is a general-purpose name with no inherent meaning. It is composed of a sequence of characters that is parsed by the Prolog reader as a single unit. Atoms are usually bare words in Prolog code, written with no special syntax. However, atoms containing spaces or certain other special characters must be surrounded by single quotes. Atoms beginning with a capital letter must also be quoted, to distinguish them from variables. The empty list, written [], is also an atom. Other examples of atoms include x, blue, 'Taco', and 'some atom'. To vajag atcerēties.

Pašapliecināšanās:

compare(First, Second, First, Second) :- First =< Second, !. 
compare(First, Second, Second, First). 
smallest([], []). 
smallest([H], [H]). 
smallest([Head|Tail], [Smallest|[SecondSmallest|NewTail]]) :- 
    smallest(Tail, [Smaller|NewTail]), 
    compare(Head, Smaller, Smallest, SecondSmallest). 

inorder([],[]).
inorder(List, [Smallest|Others]) :- smallest(List, [Smallest|Rest]), inorder(Rest, Others). 

Augusts 2017

7d 1d 2d 3d 4d 5d 6d
  12345
6789101112
13141516171819
20212223242526
2728293031  
Powered by Sviesta Ciba