How many prolog programmers




















This is a one-element list. The square brackets say it's a list, and its single element is "go A,B ". Logicians and Prolog programmers call "go A,B " a "term". It's like a structure or record, with two fields, distinguished by position rather than by name.

The first field will become whatever A holds; the second, whatever B holds. Whenever possible, Prolog programmers read programs as sets of logical statements, not as commands. So here's a logical reading for the first clause for "route": if A borders B, the route from A to B is the list containing the record "go A,B ".

Square brackets indicate a list, as before; vertical bar means "followed by". Could recursion ever be more concise? This "route" predicate generates a list, putting it into an output argument.

But predicates can also take lists as inputs, as I'll show now. A textbook author — possibly Patrick Henry Winston — once wrote the following as an example to help novices understand recursion: This is how to tidy up your room: if there are no toys lying around, do nothing. To render this as Prolog.

I'll write a predicate called "tidy" with two arguments. The first, an input, will be a list of toys. The second, an output, will be a list of the commands a robot must obey in order to tidy them. Here's my predicate: tidy [], []. I'll read the first clause as meaning: if the list of toys to tidy is empty, the list of commands needed is empty. Let's test this: 12? What this shows is that although Prolog has its roots in logical inference, it can do the same kind of list processing as any other language.

And in doing so, can build huge data structures indeed. I have just given my Prolog system this query and received the following reply: 14? The predicate "length" is a built-in, which can measure the length of a list. Your comment must be between 6 and characters. Save Changes. Vote and comment on others' rants. Post your own. Build your custom avatar. Keep me logged in. FYI we never show your email to other members. Forgot Password?

It happens to the best of us. If you still need help, email info devrant. Soon the train passes into a tunnel and it is pitch black. There is a sound of a kiss followed by the sound of a slap. When the train emerges from the tunnel, the four sit there without saying a word. The grandmother is thinking to herself, "It was very brash for that young man to kiss my granddaughter, but I'm glad she slapped him.

He thought to himself, "Life is good. How often does a guy have the chance to kiss a beautiful girl and slap his Project manager all at the same time! More jokes about: IT , programmer , travel , women. Girls are like Internet Domain names, the ones I like are already taken. More jokes about: IT , programmer , women. Wikipedia: I know everything!

Google: I have everything! Facebook: I know everybody! Internet: Without me you are nothing! Electricity: Keep talking bitches! More jokes about: IT , programmer.



0コメント

  • 1000 / 1000