Colon class § 4.2: Logical Paradigm

Source: Internet
Author: User

Lesson Four revisited paradigm (2)

4.2 Logic Paradigm--when the algorithm loses control

Tao often does nothing but all of them--"Laozi Dau Sutra"

Keywords: programming paradigm, logical programming, Prolog, algorithm, logic, control

Summary: A second discussion on logical programming

? Questions

is the measurement of software complexity determined by the length of the code?

Why is a logical encoding generally simpler than a procedural style?

What are the advantages and disadvantages of logical programming compared to imperative programming?

: Explain

The question mark puts forward: "Is logic programming not also very special?" I don't seem to be introducing much in front of you. ”

"Then we'll implement a quicksort with the logical language Prolog." "The colon says to flip the slide--

/*快速排序法的Prolog实现*/
/* 定义划分法 */
partition(_,[],[],[]).                         /* 划分递归终点 */
partition(Pivot,[X|Rest],[X|Small],Big) :-
X < Pivot, partition(Pivot,Rest,Small,Big).   /* 比基准小的归入Small */
partition(Pivot,[X|Rest],Small,[X|Big]) :-
X >= Pivot, partition(Pivot,Rest,Small,Big).  /* 比基准大的归入Big */
/* 定义排序法 */
qsort([],[]).                                /* 排序递归终点 */
qsort([Pivot|Rest],Sorted) :-
partition(Pivot,Rest,Small,Big),            /* 按基准划分子列 */
    qsort(Small,SortedSmall),                 /* 对前面的子列递归 */
    qsort(Big,SortedBig),                     /* 对后面的子列递归 */
    append(SortedSmall,[Pivot|SortedBig],Sorted)./* 子列合并 */

Comma scratching head: "See not quite understand oh, fortunately I remember your sentence: tolerance ignorance." I've endured! ”

Everybody's happy.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.