From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.help Subject: RE: conditionals in elisp Date: Tue, 27 Oct 2009 00:37:38 -0700 Message-ID: References: <87iqe1og0i.fsf@newsguy.com><14A45A8A6D3A42A7ADA56DE8DB68C74E@us.oracle.com> <8763a1o0yx.fsf@newsguy.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1256629155 7668 80.91.229.12 (27 Oct 2009 07:39:15 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 27 Oct 2009 07:39:15 +0000 (UTC) To: "'Harry Putnam'" , Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Oct 27 08:39:08 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1N2ge3-0006mG-3d for geh-help-gnu-emacs@m.gmane.org; Tue, 27 Oct 2009 08:39:07 +0100 Original-Received: from localhost ([127.0.0.1]:39513 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N2ge2-00055n-IR for geh-help-gnu-emacs@m.gmane.org; Tue, 27 Oct 2009 03:39:06 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N2gde-00055D-Mu for help-gnu-emacs@gnu.org; Tue, 27 Oct 2009 03:38:42 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N2gda-00053i-Bv for help-gnu-emacs@gnu.org; Tue, 27 Oct 2009 03:38:42 -0400 Original-Received: from [199.232.76.173] (port=50643 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N2gda-00053f-6G for help-gnu-emacs@gnu.org; Tue, 27 Oct 2009 03:38:38 -0400 Original-Received: from acsinet11.oracle.com ([141.146.126.233]:36511) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1N2gdZ-0007yw-H6 for help-gnu-emacs@gnu.org; Tue, 27 Oct 2009 03:38:37 -0400 Original-Received: from rgminet13.oracle.com (rcsinet13.oracle.com [148.87.113.125]) by acsinet11.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id n9R7d507023411 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 27 Oct 2009 07:39:06 GMT Original-Received: from acsmt353.oracle.com (acsmt353.oracle.com [141.146.40.153]) by rgminet13.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id n9R76cWp026665; Tue, 27 Oct 2009 07:39:11 GMT Original-Received: from abhmt017.oracle.com by acsmt355.oracle.com with ESMTP id 20638991341256629067; Tue, 27 Oct 2009 00:37:47 -0700 Original-Received: from dradamslap1 (/24.5.184.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 27 Oct 2009 00:37:46 -0700 X-Mailer: Microsoft Office Outlook 11 Thread-Index: AcpWxxErgrO8qjkfQK6xJZtx0K1AzAABM3yA In-Reply-To: <8763a1o0yx.fsf@newsguy.com> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Source-IP: acsmt353.oracle.com [141.146.40.153] X-Auth-Type: Internal IP X-CT-RefId: str=0001.0A090206.4AE6A378.002A:SCFMA4539814,ss=1,fgs=0 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 1) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:69267 Archived-At: >> If you only partially understand what you read, try >> something based on what you think you understand: >> `M-:', then type some expression you think might >> work, from what you read. Emacs and Emacs Lisp are >> 100% interactive - you get immediate feedback. >> Best way to learn. >> >> If you don't understand what you read at all, and >> you need more help, ask here. There's no shame in >> asking, ever. But for your _own_ sake, learn to >> interact with Emacs itself. You will not regret it. > I can say for certain that after just half a page under 10.2 > Conditionals and my head is spinning. > The stuff there does not match up to what little programming I've > learned of perl shell etc. Or if it does... I'm not seeing it yet. OK. I apologize for assuming that you were looking for a quick answer here instead of looking to learn. Learning from examples is fine - very good, in fact. Others have already provided you examples, so I hope that helped. The quick and easy answer would have been to just give you a couple examples to learn from. You can evaluate each expression by typing it after `M-:' and hitting Enter. (if) raises an error: wrong number of arguments - 0 (if nil) raises an error: wrong number of args - 1 (if nil 3) -> nil (if t 3) -> 3 (if nil 3 4) -> 4 (if t 3 4) -> 3 (if nil 3 4 5) -> 5 (if t 3 4 5) -> 3 (if nil 3 4 5 6) -> 6 (if "anything but nil" 3) -> 3 (if "nil" 3) -> 3 (if 99 3 "anything") -> 3 (if nil 3 (setq a 5) a) -> 5 And maybe some more would help. But I'm sure others have helped enough on this score. The point remains, however: to learn, you need to dialog with Emacs itself. Not to try that is to not learn the first thing about Emacs: it's helpful and interactive. Even if reading manuals is not your thing, you need to learn how Emacs itself can help you: how to find the value of a variable; how to find what the arguments to a function are; and so on. `C-h v' and `C-h f' are your friends. These and other friends are all in the `Help > Describe' menu. `M-:' is your friend. You can use it to evaluate any Emacs-Lisp expression, just to see what happens. Try it - you can't break anything. If you find yourself in the debugger because evaluation raised an error, just hit `q' to get back out. Try it: M-: (if) M-: (if t) M-: (if some-variable) The error messages can also help you learn. Try, fail, succeed, fail, learn. Know too that `C-g' cancels the action in progress and any crazy state you might find yourself in - it returns you to the top level, where you want to be. Repeat it if necessary: `C-g C-g'... Even so, you will do yourself a big favor if you make occasional forays into the Emacs manual, and even the Elisp manual. Run away when it seems to be gibberish, sure, but keep diving back into it - some places are easier than others. Things that are more helpful when you're starting out are generally nearer the beginning of the manual. In this case, if the `Conditionals' page was gibberish to you, try to understand why. Maybe you lack some more basic understanding, so it would help to first get some info about more basic stuff in Emacs Lisp. What does a truth (boolean) value look like in Lisp, for instance? What are the paretheses all about? What does a string look like? a variable? There are a lot of such basic questions that are helpful places to start. And yes, the manual is your friend for such things. In this case, asking the manual's index about `true' would help you: `i true' takes you to the page that explains truth values in Emacs Lisp, page `nil and t'. `i false' takes you to the same page. The page is short, and I'll bet it clears up a few questions you might have. But if even that page is too hard, then ask Emacs questions about the terms there that seem confusing to you. Ask about `variable'. Ask about `list'. Ask about `quote'. You get the idea. The answers to your questions are really there, and in some cases in language that you can understand. The problem is to find the right pages to read - pages that make sense to you at your current level of knowledge/ignorance. Skip over any stuff you cannot yet understand, and try to find stuff you do understand. But to do that you need, as a start, to feel comfortable asking Emacs. So the first step is to find out how to ask Emacs. That's why I stressed learning that first - before trying to learn Emacs Lisp. I don't mean learning Emacs; I meaning learning to use Emacs to ask Emacs itself questions. Then you can ask it about Emacs Lisp, for example. `C-h i' is your friend; it puts you into a manual. But how to get around inside a manual? If that's a problem, then start with the manual about reading manuals: `Info'. (It's a bit verbose, but it can help.) In general, `i' (the index) is your best friend inside a manual. `i variable', `i list' `i quote', `i evaluation', even `i give up' - Emacs lets you know you cannot give up: "No `give up' in index" - there ain't no such thing. If the language and formatting of the Elisp manual is itself confusing, see page `Conventions' (`g conventions'; `i conventions' won't get you there, unfortunately). Page `nil and t' is part of the `Conventions' explanation. You can also start with the Emacs tutorial: `C-h t' (menu Help > Emacs Tutorial). That leads you through practice exercises. Again, it's a bit verbose, but it can help. Believe me, my intent was not to just throw the book at you, but to help. You need to interact with Emacs itself _about learning Emacs_ and Lisp - that's the key. There is nothing Emacs likes to talk more about than itself. And there's no one who knows Emacs better than Emacs knows itself. The doc is sometimes wrong or poorly worded, but `M-:' never lies. A lot of Emacs's explanations will not be verbose gibberish. Explore the `Help > Describe' menu, and you will see that much of that help is short and to the point. `C-h b' gives you a list of all key bindings currently in effect - few wasted words. `C-h k' tells you what any key, mouse action, or menu item does. The first thing to try to find out about Emacs is not the syntax of particular Emacs-Lisp expressions. It's how Emacs can help you find out about Emacs and Lisp. Start with the `Help' menu (or the tutorial or the `Info' manual). And please continue to ask questions here. Don't misunderstand my reply as simply `RTFM'. My message is to bring Emacs itself into your circle of friends - s?he can help; you just need to know how to ask.