all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Gregor Zattler <telegraph@gmx.net>,
	help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: RE: why not "stripes" in: (let ((zebra 'stripes) ...  ; strings vs symbols?
Date: Sun, 29 Dec 2013 08:00:43 -0800 (PST)	[thread overview]
Message-ID: <d03f2b86-bdef-4432-bf86-594dd1e57575@default> (raw)
In-Reply-To: <20131229142332.GA7972@boo.workgroup>

> ATM i read "An Introduction to Programming in Emacs Lisp".  In
> the section where the let function is explained in detail the
> author, Robert J. Chassell, uses this "silly" example:
> 
>      (let ((zebra 'stripes)
>            (tiger 'fierce))
>        (message "One kind of animal has %s and another is %s."
>                 zebra tiger))
> 
> which when evaluated produces "One kind of animal has stripes and
> another is fierce." as output.
> 
> The thing which makes me wonder is why he uses   'stripes   instead
> of "stripes" in this example.

Either is OK.  They both produce the same effect here.
Use `C-h f format' to see what %s does (versus %S).

> In the output of the message function it makes no difference but
> to me it seems more natural to use strings here since they are
> part of a string in the output...

The beauty of %s is that you can print any Lisp object.  For a
symbol, its `symbol-name' is printed with %s.

> I do not really understand how the   'stripes   are different
> to   "stripes".  Isn't   'stripes   a notation for the symbol
> stripes?   This would mean there is the notion of a symbol which
> is bound to noting?

Yes, and yes.  Here it is irrelevant whether the symbol `stripes'
is bound to a value.

A symbol can be used for various things in Lisp.  For one thing,
It can act as a variable, having a `symbol-value'.  For another,
it can act as a function, having a `symbol-function'.

It can also act as a (rudimentary) OO object, having "slots" or
"attributes", called its symbol "properties".  These are stored
on its `symbol-plist', and are accessed using `get' and `put'.

And it need not have a non-nil value for any of these things,
in which case it at least acts as an identity, having a
`symbol-name'.

Unlike strings "stripes" and "stripes", which might be `eq' but
at least are `equal', (if in the same obarray) two symbols
`stripes and `stripes are `eq'.  They are the same Lisp object.
For one thing, that generally saves space and makes comparison
quicker.

> Could somebody please enlighten me as to what the differences
> between "stripes" and 'stripes are in which cases which notation
> is more useful/natural?

Natural is in the eye of the beholder.  But symbols are powerful
and easy to use in Lisp.  They are used a lot.



  reply	other threads:[~2013-12-29 16:00 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-29 14:23 why not "stripes" in: (let ((zebra 'stripes) ... ; strings vs symbols? Gregor Zattler
2013-12-29 16:00 ` Drew Adams [this message]
2013-12-30 11:24 ` Thien-Thi Nguyen
     [not found] ` <mailman.10682.1388402467.10748.help-gnu-emacs@gnu.org>
2013-12-30 13:19   ` Damien Wyart
2013-12-30 15:12     ` Drew Adams
2013-12-30 17:21     ` Thien-Thi Nguyen
2013-12-31 17:52   ` Emanuel Berg
     [not found] <mailman.10627.1388327081.10748.help-gnu-emacs@gnu.org>
2013-12-29 23:39 ` Emanuel Berg
2013-12-30 15:27 ` Barry Margolin
  -- strict thread matches above, loose matches on Subject: below --
2013-12-30 16:46 Rustom Mody
2014-01-01  4:53 ` Rustom Mody
2014-01-02  5:30   ` Rustom Mody
     [not found]   ` <mailman.10827.1388640687.10748.help-gnu-emacs@gnu.org>
2014-01-02 14:31     ` Emanuel Berg
2014-01-03  5:00       ` Yuri Khan
     [not found]       ` <mailman.10894.1388725210.10748.help-gnu-emacs@gnu.org>
2014-01-03 23:47         ` Emanuel Berg
     [not found] ` <mailman.10770.1388552064.10748.help-gnu-emacs@gnu.org>
2014-01-01 17:26   ` Emanuel Berg
     [not found] <mailman.10695.1388422033.10748.help-gnu-emacs@gnu.org>
2013-12-31 18:24 ` Emanuel Berg
2014-01-01  2:00   ` Evans Winner
2014-01-01 17:29     ` Emanuel Berg
2014-01-01 19:02       ` Emanuel Berg
2014-01-02  4:28         ` Stefan Monnier
2014-01-02  4:39         ` Yuri Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d03f2b86-bdef-4432-bf86-594dd1e57575@default \
    --to=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=telegraph@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.