From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Re: checking for nil argument in interactive Date: Sun, 09 Nov 2008 22:20:18 +0100 Message-ID: <87wsfc1trh.fsf@thinkpad.tsdh.de> References: <87ej1kr51p.fsf@patagonia.sebmags.homelinux.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1226265679 26121 80.91.229.12 (9 Nov 2008 21:21:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 9 Nov 2008 21:21:19 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Nov 09 22:22:21 2008 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 1KzHjd-0002jg-AD for geh-help-gnu-emacs@m.gmane.org; Sun, 09 Nov 2008 22:22:17 +0100 Original-Received: from localhost ([127.0.0.1]:37536 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KzHiV-0000e0-LW for geh-help-gnu-emacs@m.gmane.org; Sun, 09 Nov 2008 16:21:07 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KzHhy-0000du-Tz for help-gnu-emacs@gnu.org; Sun, 09 Nov 2008 16:20:35 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KzHhx-0000dh-VK for help-gnu-emacs@gnu.org; Sun, 09 Nov 2008 16:20:34 -0500 Original-Received: from [199.232.76.173] (port=34318 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KzHhx-0000de-IJ for help-gnu-emacs@gnu.org; Sun, 09 Nov 2008 16:20:33 -0500 Original-Received: from main.gmane.org ([80.91.229.2]:33769 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KzHhx-0003ju-11 for help-gnu-emacs@gnu.org; Sun, 09 Nov 2008 16:20:33 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1KzHhu-0005Am-6K for help-gnu-emacs@gnu.org; Sun, 09 Nov 2008 21:20:30 +0000 Original-Received: from p54af180a.dip0.t-ipconnect.de ([84.175.24.10]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 09 Nov 2008 21:20:30 +0000 Original-Received: from tassilo by p54af180a.dip0.t-ipconnect.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 09 Nov 2008 21:20:30 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 57 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: p54af180a.dip0.t-ipconnect.de User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) Cancel-Lock: sha1:69wki2mSRaLlL9APrrrHTYUV71Q= X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) 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:59594 Archived-At: Seb writes: Hi Seb, > I don't understand why the following arg symbol doesn't get set to > "string": > > > (defun funny-function (arg) > (interactive "sarg: ") > (if (not arg) (setq arg "string")) > (message "arg: %s" arg)) > > To test: > > M-x funny-function RET RET Because in that case arg is the empty string. > I've also tried (eq "" arg) for the if boolean but get the same > result. Because (eq "foo" "foo") ==> nil in the general case. See the manual for details. ,----[ (info "(elisp)Equality Predicates") ] | -- Function: eq object1 object2 | This function returns `t' if OBJECT1 and OBJECT2 are the same | object, `nil' otherwise. | | `eq' returns `t' if OBJECT1 and OBJECT2 are integers with the same | value. Also, since symbol names are normally unique, if the | arguments are symbols with the same name, they are `eq'. For | other types (e.g., lists, vectors, strings), two arguments with | the same contents or elements are not necessarily `eq' to each | other: they are `eq' only if they are the same object, meaning | that a change in the contents of one will be reflected by the same | change in the contents of the other. | | (eq 'foo 'foo) | => t | | (eq 456 456) | => t | | (eq "asdf" "asdf") | => nil `---- So to compare stings use `string='. Hope that helps, Tassilo -- The glass is neither half-full nor half-empty: it's twice as big as it needs to be.