From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim X Newsgroups: gmane.emacs.help Subject: Re: To setq or not setq, that is the question. Date: Fri, 26 Feb 2010 14:43:25 +1100 Organization: Rapt Technologies Message-ID: <87635k3bmq.fsf@lion.rapttech.com.au> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1267159252 24875 80.91.229.12 (26 Feb 2010 04:40:52 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 26 Feb 2010 04:40:52 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Feb 26 05:40:48 2010 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.69) (envelope-from ) id 1Nks0N-0001zC-El for geh-help-gnu-emacs@m.gmane.org; Fri, 26 Feb 2010 05:40:47 +0100 Original-Received: from localhost ([127.0.0.1]:56362 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nks0M-0004sA-9T for geh-help-gnu-emacs@m.gmane.org; Thu, 25 Feb 2010 23:40:46 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!news.kjsl.com!news.alt.net!news.astraweb.com!border2.newsrouter.astraweb.com!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.92 (gnu/linux) Cancel-Lock: sha1:xsS8MB95oYcaLz3WNWV/97nBruI= Original-Lines: 141 Original-NNTP-Posting-Host: d9ef1df6.news.astraweb.com Original-X-Trace: DXC=Ic50Ho]MQ9h3i\; U\i>iJhL?0kYOcDh@jO9CFk[n^YJo3ElHVh5T5@hXnbXF^Fa3ecWbWXOi=g13k Original-Xref: news.stanford.edu gnu.emacs.help:177112 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:72152 Archived-At: Bill writes: > Newbie here. > > In my .emacs file (blink-cursor-mode nil) works correctly. > Also (setq visible-bell t) works as promised. > > Is there some clue I am missing as to when setq is required and when > not? The first one is a function call and the second one is setting a variable. The following is meant to be very high level and is not 100% technically correct. However, it should be good enough to explain some of the basic concepts wihtout getting too bogged down in technical detail. In general, in elisp, the first value in a list i.e. (a b c d) is expected to be a function and the remaining values are arguments. so (blink-cursor-mode nil) is a call to the function blink-cursor-mode with an argument of nil. C-h f will explain what the function and its arguments mean i.e. ,----[ C-h f blink-cursor-mode RET ] | blink-cursor-mode is an interactive compiled Lisp function in `frame.el'. | | It is bound to . | | (blink-cursor-mode &optional ARG) | | Toggle blinking cursor mode. | With a numeric argument, turn blinking cursor mode on if ARG is positive, | otherwise turn it off. When blinking cursor mode is enabled, the | cursor of the selected window blinks. | | Note that this command is effective only when Emacs | displays through a window system, because then Emacs does its own | cursor display. On a text-only terminal, this is not implemented. | | [back] `---- The line (setq visible-bell t) is setting the variable visible-bell to the value 't' (also referred to as binding the value t to the symbol visible-bell. You can find out more details on this variable with C-h v i.e. ,----[ C-h v visible-bell RET ] | visible-bell is a variable defined in `C source code'. | Its value is nil | | Documentation: | *Non-nil means try to flash the frame to represent a bell. | | See also `ring-bell-function'. | | You can customize this variable. | | [back] `---- Note that (setq visible-bell t) follows the rule that the first argument in a list is expected to be a function i.e. C-h f setq ,----[ C-h f setq RET ] | setq is a special form in `C source code'. | | (setq [SYM VAL]...) | | Set each SYM to the value of its VAL. | The symbols SYM are variables; they are literal (not evaluated). | The values VAL are expressions; they are evaluated. | Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'. | The second VAL is not computed until after the first SYM is set, and so on; | each VAL can use the new value of variables set earlier in the `setq'. | The return value of the `setq' form is the value of the last VAL. | | [back] Note that the reference to 'special form' means that setq is slightly different to 'real' functions. It is special because unlike other functions, it does not evaluate its arguments. In lisp like languages, these special forms are macros and defined with defmacro rather than defun, but you probably don't need to worry about that too much right now. Note also that some lists are quoted, which prevents the lisp interpreter from trying to evaluate the list i.e. stops it from trying to evaluate the first item in the list as a function. A quoted list starts with a apostrophe (') i.e. '(a b c) will evaluate to (a b c) while (a b c) without the ' will cause the interpreter to try and evaluate the function 'a' with the arguments b and c. The ' is actually short hand for the function quote i.e. ,----[ C-h f quote RET ] | quote is a special form in `C source code'. | | (quote ARG) | | Return the argument, without evaluating it. `(quote x)' yields `x'. | | [back] `---- Notice that 'quote' is also a special form, which means it doesn't evaluate its argument. So '(a b c) is the same as (quote (a b c)) and therfore follows the rule regarding the first argument being something that is evaluated by the interpreter. This is also a good example of why special forms are needed. If quote was a function, it would try to evaluate its arguments. As its argument is a list, it would try to evaluate the first element i.e. 'a' which would cause an error if 'a' is not a defined function. In elisp, like other lisps, certain values evaluate to themselves i.e. 33 => 33 "fred" => fred 'c => c t => t nil => nil Emacs comes with a very good introduction to emacs lisp that has been written for people with little or no programming expeerience. I would highly recommend reading it as it will help you learn how you can extend and customize emacs for your own requirements. HTH Tim -- tcross (at) rapttech dot com dot au