all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Applying intern-soft to a symbol
@ 2017-04-24 15:07 N. Raghavendra
  2017-04-24 17:41 ` John Mastro
  0 siblings, 1 reply; 4+ messages in thread
From: N. Raghavendra @ 2017-04-24 15:07 UTC (permalink / raw)
  To: help-gnu-emacs

I am confused about the following Emacs Lisp interaction, where I've
numbered the prompts for ease of reference.

*** Welcome to IELM ***  Type (describe-mode) for help.
ELISP1> (intern-soft "quux")
nil
ELISP2> (intern-soft 'quux)
quux
ELISP3> (intern-soft "quux")
quux
ELISP4>

As I understand, the value of ELISP1 indicates that `quux' is not an
interned symbol in the default obarray.  The value of ELISP2 indicates
that `quux' is now an interned symbol in the default obarray, and the
value of ELISP3 confirms this.

Now, the Emacs Lisp manual says the following about intern-soft:

----------------------------------------------------------------------
Function: intern-soft name &optional obarray
  This function returns the symbol in OBARRAY whose name is NAME, or
  ‘nil’ if OBARRAY has no symbol with that name.  Therefore, you can
  use ‘intern-soft’ to test whether a symbol with a given name is
  already interned.  If OBARRAY is omitted, the value of the global
  variable ‘obarray’ is used.

  The argument NAME may also be a symbol; in that case, the function
  returns NAME if NAME is interned in the specified obarray, and
  otherwise ‘nil’.
----------------------------------------------------------------------

According to the second paragraph of this description, ELISP2 should
have returned nil, because the symbol `quux' was then not interned in
the default obarray.  Can someone please explain why ELISP2 returns
`quux' instead of nil?

Raghu.

--
N. Raghavendra <raghu@hri.res.in>, http://www.retrotexts.net/
Harish-Chandra Research Institute, http://www.hri.res.in/



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Applying intern-soft to a symbol
  2017-04-24 15:07 Applying intern-soft to a symbol N. Raghavendra
@ 2017-04-24 17:41 ` John Mastro
  2017-04-25 19:51   ` N. Raghavendra
  0 siblings, 1 reply; 4+ messages in thread
From: John Mastro @ 2017-04-24 17:41 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org; +Cc: N. Raghavendra

N. Raghavendra <nyraghu27132@gmail.com> wrote:
> I am confused about the following Emacs Lisp interaction, where I've
> numbered the prompts for ease of reference.
>
> *** Welcome to IELM ***  Type (describe-mode) for help.
> ELISP1> (intern-soft "quux")
> nil
> ELISP2> (intern-soft 'quux)
> quux
> ELISP3> (intern-soft "quux")
> quux
> ELISP4>
>
> As I understand, the value of ELISP1 indicates that `quux' is not an
> interned symbol in the default obarray.  The value of ELISP2 indicates
> that `quux' is now an interned symbol in the default obarray, and the
> value of ELISP3 confirms this.
>
> Now, the Emacs Lisp manual says the following about intern-soft:
>
> ----------------------------------------------------------------------
> Function: intern-soft name &optional obarray
>   This function returns the symbol in OBARRAY whose name is NAME, or
>   ‘nil’ if OBARRAY has no symbol with that name.  Therefore, you can
>   use ‘intern-soft’ to test whether a symbol with a given name is
>   already interned.  If OBARRAY is omitted, the value of the global
>   variable ‘obarray’ is used.
>
>   The argument NAME may also be a symbol; in that case, the function
>   returns NAME if NAME is interned in the specified obarray, and
>   otherwise ‘nil’.
> ----------------------------------------------------------------------
>
> According to the second paragraph of this description, ELISP2 should
> have returned nil, because the symbol `quux' was then not interned in
> the default obarray.  Can someone please explain why ELISP2 returns
> `quux' instead of nil?

The reader interned the symbol `quux' into the default obarray while
reading the expression (intern-soft 'quux). Reading occurs before
evaluation, so `quux' had been interned before the actual call to
`intern-soft' occurred.

        John



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Applying intern-soft to a symbol
  2017-04-24 17:41 ` John Mastro
@ 2017-04-25 19:51   ` N. Raghavendra
  2017-04-25 23:20     ` Emanuel Berg
  0 siblings, 1 reply; 4+ messages in thread
From: N. Raghavendra @ 2017-04-25 19:51 UTC (permalink / raw)
  To: help-gnu-emacs

At 2017-04-24T10:41:43-07:00, John Mastro wrote:

> The reader interned the symbol `quux' into the default obarray while
> reading the expression (intern-soft 'quux). Reading occurs before
> evaluation, so `quux' had been interned before the actual call to
> `intern-soft' occurred.

Thanks for the clarification.

I didn't understand that interning was done by the reader, though this
is clearly mentioned in the manual: `If the obarray does not contain a
symbol with that name, the reader makes a new symbol and adds it to the
obarray.  Finding or adding a symbol with a certain name is called
“interning” it, and the symbol is then called an “interned symbol”.'

Raghu.

--
N. Raghavendra <raghu@hri.res.in>, http://www.retrotexts.net/
Harish-Chandra Research Institute, http://www.hri.res.in/



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Applying intern-soft to a symbol
  2017-04-25 19:51   ` N. Raghavendra
@ 2017-04-25 23:20     ` Emanuel Berg
  0 siblings, 0 replies; 4+ messages in thread
From: Emanuel Berg @ 2017-04-25 23:20 UTC (permalink / raw)
  To: help-gnu-emacs

N. Raghavendra wrote:

> I didn't understand that interning was done
> by the reader, though this is clearly
> mentioned in the manual: `If the obarray does
> not contain a symbol with that name, the
> reader makes a new symbol and adds it to the
> obarray. Finding or adding a symbol with
> a certain name is called “interning” it, and
> the symbol is then called an “interned
> symbol”.'

Ha ha ha! Any questions? :)

-- 
underground experts united
http://user.it.uu.se/~embe8573




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-04-25 23:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-24 15:07 Applying intern-soft to a symbol N. Raghavendra
2017-04-24 17:41 ` John Mastro
2017-04-25 19:51   ` N. Raghavendra
2017-04-25 23:20     ` Emanuel Berg

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.