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: What's wrong with this lisp code in my init file?! Date: Sun, 31 Dec 2006 14:29:17 -0800 Message-ID: References: <87r6ufwx7m.fsf@offby1.atm01.sea.blarg.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1167604223 1912 80.91.229.12 (31 Dec 2006 22:30:23 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 31 Dec 2006 22:30:23 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Dec 31 23:30:22 2006 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 1H19CA-0003lA-50 for geh-help-gnu-emacs@m.gmane.org; Sun, 31 Dec 2006 23:30:22 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1H19C9-0007nM-Kb for geh-help-gnu-emacs@m.gmane.org; Sun, 31 Dec 2006 17:30:21 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1H19Bx-0007md-P2 for help-gnu-emacs@gnu.org; Sun, 31 Dec 2006 17:30:09 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1H19Bv-0007kz-TT for help-gnu-emacs@gnu.org; Sun, 31 Dec 2006 17:30:08 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1H19Bv-0007kw-Qx for help-gnu-emacs@gnu.org; Sun, 31 Dec 2006 17:30:07 -0500 Original-Received: from [148.87.113.118] (helo=rgminet01.oracle.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1H19Bv-0005Ht-CY for help-gnu-emacs@gnu.org; Sun, 31 Dec 2006 17:30:07 -0500 Original-Received: from rgmgw2.us.oracle.com (rgmgw2.us.oracle.com [138.1.186.111]) by rgminet01.oracle.com (Switch-3.2.4/Switch-3.1.6) with ESMTP id kBVMU3Wm027971 for ; Sun, 31 Dec 2006 15:30:04 -0700 Original-Received: from rcsmt250.oracle.com (rcsmt250.oracle.com [148.87.90.195]) by rgmgw2.us.oracle.com (Switch-3.2.4/Switch-3.1.7) with ESMTP id kBVM9pSx010795 for ; Sun, 31 Dec 2006 15:30:03 -0700 Original-Received: from dhcp-amer-whq-csvpn-gw3-141-144-80-102.vpn.oracle.com by rcsmt250.oracle.com with ESMTP id 2326929821167604159; Sun, 31 Dec 2006 15:29:19 -0700 Original-To: X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) In-Reply-To: <87r6ufwx7m.fsf@offby1.atm01.sea.blarg.net> Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 X-Whitelist: TRUE X-Whitelist: TRUE X-Brightmail-Tracker: AAAAAQAAAAI= 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:40059 Archived-At: > But there's an even more general way to do more than one thing inside > an "if": the "progn" form. It simply does a bunch of things one after > the other: > > (if (furryp critter) > > ;; yup, furry > (progn > (pet critter) > (comb-fur critter)) > > ;; no fur > (progn > (apply 'sunscreen critter) > (search-for-tattoos critter))) (The second `progn' is not needed, there, BTW. `if' has an implicit `progn' for the false branch. I know that Eric knows that, but I thought I'd point it out.) While we're on the subject of conditionals and `progn', and hoping not to open too big a can of worms... `cond' is very general. Each of its clauses has in implicit `progn'. In this case, the code would be: (cond ((furryp critter) (pet critter) (comb-fur critter)) (t (apply 'sunscreen critter) (search-for-tattoos critter))) However, if there is only one test, and the conditional clause is used only for effect, not also for the value it returns, then many people (myself included) prefer to use `when' or `unless', instead of `if' or `cond'. This is largely a convention for human readers, letting them know that the value is unimportant. Like `cond' and `if' (second branch), `when' and `unless' have an implicit `progn'. In the OP case, the code would be: (when (eq window-system 'w32) (setq ps-printer-name t) (setq ps-lpr-command "...")) Of course, as Eric pointed out, in this case, you can combine the setq's: (when (eq window-system 'w32) (setq ps-printer-name t ps-lpr-command "...")) And there are also `and' and `or', which are sometimes used for nested conditionals of a particular form, and where the value matters. For example, this: (if a a (if b b (if c c nil))) is often written like this: (or a b c). And this: (if a (if b (if c c nil) nil) nil) is often written like this: (and a b c). If the value is unimportant, some people will combine `when' or `unless' with `and' or `or'. That is, instead of this: (and a b c (do-it-to-it)) Some people will write this: (when (and a b c) (do-it-to-it)) Most of choosing a particular conditional to use is about communicating intention to (human) readers of your code. Among various choices that do essentially the same thing, some are sometimes more readable than others or more clearly indicate what is important.