Frequently Asked Questions for ##Prolog [PDF]

Apr 3, 2016 - About 10% of the questions asked in ##prolog are solved by the person asking them when we insist they go a

2 downloads 21 Views 379KB Size

Recommend Stories


www.sunbiz.org - Frequently Asked Questions [PDF]
Mar 15, 2011 - The web address for the Division of Corporations´ web site is: www.sunbiz.org. You can access records for corporations, limited partnerships, limited liability limited partnerships, limited liability companies, federal tax lien regist

FREQUENTLY ASKED QUESTIONS
Suffering is a gift. In it is hidden mercy. Rumi

FREQUENTLY ASKED QUESTIONS (FAQ)
Forget safety. Live where you fear to live. Destroy your reputation. Be notorious. Rumi

19 – Frequently Asked Questions
Never let your sense of morals prevent you from doing what is right. Isaac Asimov

FREQUENTLY ASKED QUESTIONS
Those who bring sunshine to the lives of others cannot keep it from themselves. J. M. Barrie

FREQUENTLY ASKED QUESTIONS
The only limits you see are the ones you impose on yourself. Dr. Wayne Dyer

OLD POOL TABLE FREQUENTLY ASKED QUESTIONS (PDF)
Ask yourself: Is there someone who has hurt or angered me that I need to forgive? Next

FREQUENTLY AsKED QuESTIONS ABOUT OzoNE
Those who bring sunshine to the lives of others cannot keep it from themselves. J. M. Barrie

FREQUENTLY ASKED QUESTIONS AND FACTS
I want to sing like the birds sing, not worrying about who hears or what they think. Rumi

Continuing Education Frequently Asked Questions
I cannot do all the good that the world needs, but the world needs all the good that I can do. Jana

Idea Transcript


Frequently Asked Questions for ##Prolog Anne Ogborn , Michael Richter version 1.1, April 2, 2016

Table of Contents 1. Asking Questions on ##prolog 1.1. Correct 1.2. Complete 1.3. Concise 1.4. Clear 1.5. Courteous

2. And A Plea To The Regulars 2.1. Answer the question assuming the beginner is a beginner 2.2. Avoid Competing Teachers Syndrome 2.3. The Rules of The Road

3. Which Prolog To Use 4. Hello World 4.1. On Windows 4.2. On Linux or Mac

5. Syntax Cheat Sheet 6. Where to type in code 7. Why can’t I type in code at the repl? 8. More Solutions 9. Prolog Hung 10. How do I find the predicate that does so and so? 11. The Graphic Debugger 12. Variables, atoms, strings, and case 12.1. "hello" (pre SWI-Prolog rev 7) 12.2. "hello" (post SWI-Prolog rev 7) 12.3. hello 12.4. 'Howdy!' 12.5. HowAreYa

13. I get true, then false when I expected just true 14. The Cut 15. How do I get all the results in a list? 15.1. Why does bagof sometimes have repeats?

16. The standard recursion pattern 17. Can I make real world programs in Prolog? 18. So why am I doing toy problems in this class? 19. So why haven’t I heard of Prolog before? 20. Isn’t Prolog really OLD? 21. How do I make a web page in Prolog? 22. Why Can’t I do arithmetic? 23. So everything returns true or false, right? 24. How do I make an if statement? 25. How do I make a loop? 25.1. Recursion 25.2. Failure Driven Loop

26. How do I return if everything’s void?

v0.1 June 2013 v1.1 April 2016 - Made topic titles clearer, added some questions Up to All Tutorials

1. Asking Questions on ##prolog Some strong advice for undergrad students asking questions on ##prolog. There are about 50,000 students each semester who take a programming languages class that includes some basic Prolog. There are about 5000 commercial Prolog programmers in the entire world, and another 15000 or so researchers who use Prolog (these numbers are completely wild guesses). The small community means if you discover the great fun and power of Prolog and fall in love with it, we’ll take you to our breast. BUT… In their own self defense, regular denizens of ##prolog will definitely ignore you if you ignore the five C’s correct Accurately reflects what you really want to know complete We have all the info we need, not just the fragment you’re sure is the problem. concise Yes, this is in tension with complete, but you can find the balance. clear Clarify the question in your own mind, then express it with literate English. courteous We don’t want people to (Google it!

It’s good practice!) to us. We do, on the other hand, think that abuse is uncalled for.

1.1. Correct Understand what you really want to do. Don’t ask about getting the last 3 characters in a string if you want the file extension. Do you understand the homework problem, let alone how to answer it? Differentiate between goals and implementation. If you’re asking about an implementation detail instead of the goal in an unfamiliar language, you’re almost certainly asking the wrong question. Don’t come to us with random weird way of doing something simple and instead of taking advice that you want really simple thing insist that we help you with random weird way. Goals, not methods (and a little humility). Prolog can indeed handle "normal" programming tasks. It is rarely necessary to wrap it in C++ or Java wrappers. Please don’t show up with a simple Prolog program, struggling with Prolog basics, and expect us to talk you through JPL or C\++ interface libs (which are as hairy as such low level glue libs usually are). If you do need to integrate Prolog in an existing system, usually it can be done over sockets, pipes, or other simple alternative. Ask advice in the channel about the best way to go about it. Don’t ask for help setting up complex development environments when you’re a student and only will be writing 50 line programs. SWI-Prolog has a built-in editor that’s entirely adequate. We’re not going to help you get swipl running on Netbeans on a Mac, even if NetBeans is the only editor you’ve ever seen.

1.2. Complete You need to give us a complete program, not a fragment. Provide the minimal, complete expression of whatever your problem is. Give us code that runs, not a mangled fragment. We actually might try to run it. In Prolog code is data and vice versa. A program that depends on some data we don’t have isn’t complete.

1.3. Concise Don’t give us a long diatribe about how hard you’ve worked on this, how you figured out that case matters, etc ad nauseum. Don’t dump a thousand lines of code and expect people to work it all out for you. Write a small sample that demonstrates the problem. You may find that in making the minimal example you’ll understand your problem anyway.

1.4. Clear Don’t paste your code into irc one line at a time so it’s all jumbled. Use Pastebin or CollabEdit or gist or something. Make sure your code’s properly indented and has reasonable variable names. About 10% of the questions asked in ##prolog are solved by the person asking them when we insist they go away and clean up the code first. Use descriptive variable names. Prolog atoms are lowercase, Variables Are Propercase, and the compiler cares!. this_is_a_good_atom_name WhileThisIsHowYouWriteVariables. If you can’t come up with descriptive variable names, you don’t understand the problem and we can’t help you. Don’t ask questions you could have discovered the answers to with minimal searching. Before asking Whats the library call to do… questions, always check the search box on SWI-Prolog (Or the website for your version of Prolog), and use Google. Before asking any question, search Stack Overflow. This is courteous (it doesn’t waste our time), and will help you think clearly about the question. Don’t ask questions that clearly indicate you haven’t read the textbook. We don’t mind if you’re confused - Prolog’s mind warping! But you need to make a reasonable effort to understand the material first, not use us for not having wanted to show up for that 8am CS 302 class. Reasonable: I read the chapter on cut, read this website tutorial on cut, typed in a bunch of examples, and completely don’t get how to program if I completely undo my program each time. Unreasonable: What’s this exclamation point thing?

1.5. Courteous We do not exist to serve you. We don’t mind helping, but we do mind being taken for granted. Every moment spent answering questions is a moment we’re not coding. Don’t ask permission to ask. The whole point of the channel is to ask and answer questions about Prolog. It’s a slow moving channel. Instant answers are unlikely. (So don’t leave your homework for the last second.) Ask your question and then wait. Just because there is channel activity doesn’t mean people who know your answer are on now. If you’re asking about an obscure part of the language it can take days before someone answers. Check one of the many sites that log the channel. We heard you the first time. Don’t spam 43 channels. Don’t wait 14.8 seconds, then storm off in a snit with a sarcastic quip about how helpful people are being. Don’t ask questions of the form "how do I…" followed by your class assignment, copy/pasted direct, complete with assignment number. We enjoy doing your homework, after all. Your professors, who probably read the channel, enjoy other people doing your homework for you as well. Our purpose on earth is not to make up for your instructor’s failings. You’re paying for a class, ask the guy/gal getting paid. Have a sense of proportion. Having never used Prolog before, don’t announce you’re doing some obviously deep hackery like porting SWI-Prolog onto the JVM, and then ask for our help. Don’t brag how you’re going to make a human level AI program. Don’t come in and ask beginner questions while being secretive about what you’re doing like it’s some top secret thing. Most of us work in or around AI. You’re not fooling us. AI researchers know Prolog already. Don’t tell us how Python/Java/Cobol/etc is so much better. We’re mostly language geeks and love discussing the pros and cons of various languages, including Prolog, but expressing your low opinion of Prolog and loudly bemoaning being forced to understand it won’t convince us you’ve got the broad and searching mind we’re looking for. Don’t make crude jokes, have an offensive nick, or generally be somebody we wouldn’t want to share time with. That won’t convince us of the broad and searching thing either. Sexist humor/remarks won’t fly. If you aren’t ready for the grownup table, you’re not ready for ##prolog. After we spend 30 minutes solving your complex issue, don’t kill the channel immediately without saying thanks. Maybe our answer only looked right, and you’ll be back in 10 minutes.

2. And A Plea To The Regulars If you’re one of the many extremely bright people who regularly hangs out on ##prolog and answers questions, I have a plea.

2.1. Answer the question assuming the beginner is a beginner I’ve seen plenty of misbehavior from students. But I’ve also seen plenty of regulars answer reasonable, simple beginner questions with category theory. If they ask about functions, suspect they mean predicates until otherwise proven. I don’t think you’re intending to be mean, but when you demonstrate your intellect or highlight a fascinating corner of Prolog, in effect you’re ignoring the poor petitioner. So I do invite you to consider giving the simple, obvious answer first. It’s often what the asker needs.

2.2. Avoid Competing Teachers Syndrome There are a million ways to explain anything. If a new Prolog user is in the channel and someone is already helping them, refrain, please from offering your own much cooler/faster/more monadic/etc solution. I’d suggest to you that no one can learn as well from a cacaphony of competing voices as from a single clear voice. When helping on the channel I often have a strategy for helping the student planned out. Random offers of explanation/advice/solutions are likely to disrupt those plans.

2.3. The Rules of The Road I’d offer this "Rule of the Road" - in sailing the Rules of the Road establish which of two ships approaching on a collision course should turn. I’d suggest our rule of the road is "If someone is already engaging the new Prolog programmer, let them continue." All that out of the way, On to the FAQ

3. Which Prolog To Use I recommend SWI-Prolog. There are many good things to be said about other implementations of Prolog. Some are faster in some circumstances, have nice constraint libraries, or other attractive features, but you won’t be using any of those things as a beginning student. Installation on windows and mac is simple, there are installers for mac and windows and packages for most linux distros. Building from sources on Linux is also simple. SWI-Prolog has a built in IDE with a graphical debugger and syntax coloring editor. Further, it’s the most popular Prolog for commercial and research use, so the person you’re talking to probably can answer questions about SWI more easily. Bias warning - one of the authors of this FAQ is a peripheral contributor to SWI-Prolog.

4. Hello World An old tradition in computing is to write a program that prints hello world when one starts using a new language. Here’s how to do it in SWI-Prolog.

4.1. On Windows Right click in the file browser and make a new text document.

Rename the document helloworld.pl It should give a warning, and if you say go ahead and change, it will change the icon to an orange owl.

Double click on the document. SWI-Prolog should start up and show you a console like this

The ?- prompt is called a top level prompt. In Prolog we have facts and rules in files that we consult. Then we make queries about our database by typing them in at the top level. Query ?-edit. That means "type e then d then i then t then a period then a newline into the console" The pceEmacs editor pops up in a new window. This editor is a clone of emacs.

Type your first program into the editor. hello_world : write('hello world'), nl. Type ctrl-x ctrl-s to save your program. type ctrl-c ctrl-m to make your program. Making the program alters the database by adding a new rule, one that defines whether hello_world is true (it is), and as a side effect prints out hello world. Now ask Prolog if hello_world is true by querying ?- hello_world. and it prints hello world on the console and assures you that it’s indeed true.

4.2. On Linux or Mac These directions are for linux. Mac is similar. In a terminal touch helloworld.pl swipl -s helloworld.pl SWI-Prolog should start up and look like this anniepoo@localhost:~$ touch helloworld.pl anniepoo@localhost:~$ swipl -s helloworld.pl % /home/anniepoo/helloworld.pl compiled 0.00 sec, 1 clauses Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 6.3.15-115-g79fdabe) Copyright (c) 1990-2013 University of Amsterdam, VU Amsterdam SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. Please visit http://www.swi-prolog.org for details. For help, use ?- help(Topic). or ?- apropos(Word). ?- >>),writeln(X))). Note the extra parens. But I don’t recommend doing this. Your code will go away when you halt.

8. More Solutions See Prolog Hung

9. Prolog Hung SWI-Prolog’s pretty reliable. Here’s ways to hang it: 14 ?- assert(mep(7)). true. 15 ?- assert(mep(3)). true. 16 ?- mep(X). X = 7

Smile Life

When life gives you a hundred reasons to cry, show life that you have a thousand reasons to smile

Get in touch

© Copyright 2015 - 2024 PDFFOX.COM - All rights reserved.