unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* What does the coding system nil mean?
@ 2004-01-24 22:13 Jesper Harder
  2004-01-25  6:10 ` Eli Zaretskii
       [not found] ` <mailman.1298.1075010993.928.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 11+ messages in thread
From: Jesper Harder @ 2004-01-24 22:13 UTC (permalink / raw)



  (coding-system-p nil) => t

OK, so nil is a coding system.

But I can't find any documentation about what it means to supply nil
to functions that take a coding system (`encode-coding-string' etc.),
and `describe-coding-system' refuses to describe the nil coding
system.

Hmm, `encode-coding-string' promises to set `last-coding-system-used'
... yet if you supply nil, it doesn't change the previous value of the
variable.

So, can anyone explain what a nil coding system means?

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

* Re: What does the coding system nil mean?
  2004-01-24 22:13 What does the coding system nil mean? Jesper Harder
@ 2004-01-25  6:10 ` Eli Zaretskii
       [not found] ` <mailman.1298.1075010993.928.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2004-01-25  6:10 UTC (permalink / raw)


> Newsgroups: gnu.emacs.help
> From: Jesper Harder <harder@myrealbox.com>
> Date: Sat, 24 Jan 2004 23:13:38 +0100
> 
> So, can anyone explain what a nil coding system means?

It means, quite naturally, that no code-conversion should take place.
That is, the original text or string are left unaltered.

Try it:

  M-: (encode-coding-string "SOME STRING" nil) 
      => "SOME STRING"

(include non-ASCII characters in the string to convince yourself they
are not encoded).

I agree that this should be in the docs somewhere, e.g. in the docs of
the en/decoding primitives such as encode-coding-region and
decode-coding-string.  So a documentation bug report is probably in
order.

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

* Re: What does the coding system nil mean?
       [not found] ` <mailman.1298.1075010993.928.help-gnu-emacs@gnu.org>
@ 2004-01-25 21:09   ` Jesper Harder
  2004-01-26  6:08     ` Eli Zaretskii
       [not found]     ` <mailman.1343.1075097239.928.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 11+ messages in thread
From: Jesper Harder @ 2004-01-25 21:09 UTC (permalink / raw)


Eli Zaretskii <eliz@elta.co.il> writes:

>> So, can anyone explain what a nil coding system means?
>
> It means, quite naturally, that no code-conversion should take
> place.  That is, the original text or string are left unaltered.

Then nil isn't really a coding system, but just a value that some
coding system related functions happen to interpret in a certain way.

Ah, it turns out that I was confused because I hadn't read the
documentation for `coding-system-p' carefully enough:

    Return t if OBJECT is nil or a coding-system.

Though, I think it's a bit odd for a predicate called
`coding-system-p' to return t for an object that is _not_ in fact a
coding system.

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

* Re: What does the coding system nil mean?
  2004-01-25 21:09   ` Jesper Harder
@ 2004-01-26  6:08     ` Eli Zaretskii
       [not found]     ` <mailman.1343.1075097239.928.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2004-01-26  6:08 UTC (permalink / raw)


> Newsgroups: gnu.emacs.help
> From: Jesper Harder <harder@myrealbox.com>
> Date: Sun, 25 Jan 2004 22:09:15 +0100
> 
> Then nil isn't really a coding system, but just a value that some
> coding system related functions happen to interpret in a certain way.

It's a coding system in the sense that every primitive that accepts a
coding system symbol also accepts nil.

> Though, I think it's a bit odd for a predicate called
> `coding-system-p' to return t for an object that is _not_ in fact a
> coding system.

IMHO, it's no more odd than this:

   M-: (listp nil) RET => t

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

* Re: What does the coding system nil mean?
       [not found]     ` <mailman.1343.1075097239.928.help-gnu-emacs@gnu.org>
@ 2004-01-26 15:07       ` Stefan Monnier
  2004-01-26 17:28         ` Eli Zaretskii
  2004-01-27 15:22         ` Oliver Scholz
  2004-01-26 15:20       ` Jesper Harder
  1 sibling, 2 replies; 11+ messages in thread
From: Stefan Monnier @ 2004-01-26 15:07 UTC (permalink / raw)


> It's a coding system in the sense that every primitive that accepts a
> coding system symbol also accepts nil.

Try (coding-system-doc-string nil) ;-)

>> Though, I think it's a bit odd for a predicate called
>> `coding-system-p' to return t for an object that is _not_ in fact a
>> coding system.

> IMHO, it's no more odd than this:

>    M-: (listp nil) RET => t

Given the fact that the only empty list is nil, I don't find it too odd.
As a former Schemer, I'd agree that it would make sense to introduce a real
empty list constant and stop overloading the meaning of nil, but it's
unlikely to happen.
For coding-systems, you can use `no-conversion' in place of nil, and there
was no historical reason to overload the meaning of nil here.


        Stefan

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

* Re: What does the coding system nil mean?
       [not found]     ` <mailman.1343.1075097239.928.help-gnu-emacs@gnu.org>
  2004-01-26 15:07       ` Stefan Monnier
@ 2004-01-26 15:20       ` Jesper Harder
  2004-01-26 17:26         ` Eli Zaretskii
  2004-01-27 14:44         ` Oliver Scholz
  1 sibling, 2 replies; 11+ messages in thread
From: Jesper Harder @ 2004-01-26 15:20 UTC (permalink / raw)


Eli Zaretskii <eliz@elta.co.il> writes:

>> Then nil isn't really a coding system, but just a value that some
>> coding system related functions happen to interpret in a certain way.
>
> It's a coding system in the sense that every primitive that accepts
> a coding system symbol also accepts nil.

But it's not transparent, i.e. some functions behave differently if
you use nil rather than a real coding system.  For example

    (progn
      (setq last-coding-system-used 'none-such)
      (encode-coding-string "foo" nil)
      last-coding-system-used)

    => none-such

If nil was a real coding system, the value of
`last-coding-system-used' would have been changed.  There are also
other cases, where you can tell that nil is not a coding system.

>> Though, I think it's a bit odd for a predicate called
>> `coding-system-p' to return t for an object that is _not_ in fact a
>> coding system.
>
> IMHO, it's no more odd than this:
>
>    M-: (listp nil) RET => t

I would find it a lot more odd if (listp ()) did not return t -- nil
is the empty list, after all.

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

* Re: What does the coding system nil mean?
  2004-01-26 15:20       ` Jesper Harder
@ 2004-01-26 17:26         ` Eli Zaretskii
  2004-01-27 14:44         ` Oliver Scholz
  1 sibling, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2004-01-26 17:26 UTC (permalink / raw)


> Newsgroups: gnu.emacs.help
> From: Jesper Harder <harder@myrealbox.com>
> Date: Mon, 26 Jan 2004 16:20:22 +0100
> >
> > It's a coding system in the sense that every primitive that accepts
> > a coding system symbol also accepts nil.
> 
> But it's not transparent, i.e. some functions behave differently if
> you use nil rather than a real coding system.

That's true, but what I said is still true as well.

> > IMHO, it's no more odd than this:
> >
> >    M-: (listp nil) RET => t
> 
> I would find it a lot more odd if (listp ()) did not return t -- nil
> is the empty list, after all.

No, nil is also a symbol.

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

* Re: What does the coding system nil mean?
  2004-01-26 15:07       ` Stefan Monnier
@ 2004-01-26 17:28         ` Eli Zaretskii
  2004-01-27 15:22         ` Oliver Scholz
  1 sibling, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2004-01-26 17:28 UTC (permalink / raw)


> Newsgroups: gnu.emacs.help
> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Date: Mon, 26 Jan 2004 15:07:48 GMT
> 
> For coding-systems, you can use `no-conversion' in place of nil, and there
> was no historical reason to overload the meaning of nil here.

I think the reason was that you say, e.g., "C-x RET t nil" to disable
any conversions to the terminal.

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

* Re: What does the coding system nil mean?
  2004-01-26 15:20       ` Jesper Harder
  2004-01-26 17:26         ` Eli Zaretskii
@ 2004-01-27 14:44         ` Oliver Scholz
  1 sibling, 0 replies; 11+ messages in thread
From: Oliver Scholz @ 2004-01-27 14:44 UTC (permalink / raw)


Jesper Harder <harder@myrealbox.com> writes:

> Eli Zaretskii <eliz@elta.co.il> writes:
>
[...]
>> IMHO, it's no more odd than this:
>>
>>    M-: (listp nil) RET => t
>
> I would find it a lot more odd if (listp ()) did not return t -- nil
> is the empty list, after all.

Well ...

(and (eq nil '())
     (symbolp '())
     (listp '())
     (atom '())
     (not '()))

[Not to mention (car nil) => nil.]

It's funny that nil never seems to stop being fodder for an
argument ... 

In Emacs Lisp nil/'() is some sort of a Trickster deity in the
pantheon of data types.

Personally I like this a lot and I find it very convenient. YMMV, of
course. Yet, IMO this “overloading” just emphasizes the fact that
lists are a prominent data type.

Hmm … actually C with its NULL/0 isn't so much different here.

    Oliver
-- 
8 Pluviôse an 212 de la Révolution
Liberté, Egalité, Fraternité!

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

* Re: What does the coding system nil mean?
  2004-01-26 15:07       ` Stefan Monnier
  2004-01-26 17:28         ` Eli Zaretskii
@ 2004-01-27 15:22         ` Oliver Scholz
  2004-01-27 16:33           ` Stefan Monnier
  1 sibling, 1 reply; 11+ messages in thread
From: Oliver Scholz @ 2004-01-27 15:22 UTC (permalink / raw)


Stefan Monnier <monnier@iro.umontreal.ca> writes:

[...]
> Given the fact that the only empty list is nil, I don't find it too odd.
> As a former Schemer, I'd agree that it would make sense to introduce a real
> empty list constant and stop overloading the meaning of nil, but it's
> unlikely to happen.
[...]

I am aware that this topic is a bit delicate; but I always have been
curious and asking in either comp.lang.list or comp.lang.scheme would
probably mistakenly regarded as flame bait. But I'd like to get an
answer sine ira et studio:

Is this a matter of taste or does nil belonging to multiple data types
cause problems somewhere (debugging programs, compiler/intepreter
construction, whatever)?

    Oliver
-- 
8 Pluviôse an 212 de la Révolution
Liberté, Egalité, Fraternité!

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

* Re: What does the coding system nil mean?
  2004-01-27 15:22         ` Oliver Scholz
@ 2004-01-27 16:33           ` Stefan Monnier
  0 siblings, 0 replies; 11+ messages in thread
From: Stefan Monnier @ 2004-01-27 16:33 UTC (permalink / raw)


> Is this a matter of taste or does nil belonging to multiple data types
> cause problems somewhere (debugging programs, compiler/intepreter
> construction, whatever)?

It does not cause any particular problem, no.
It's just considered unclean by some.  It can definitely surprise people
that (symbolp ()) is true.  In some cases it's annoying: one example
off the top of my head is (intern-soft "nil").

In a sense, it's similar to whether or not chars and integers should
be distinguishable.


        Stefan

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

end of thread, other threads:[~2004-01-27 16:33 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-01-24 22:13 What does the coding system nil mean? Jesper Harder
2004-01-25  6:10 ` Eli Zaretskii
     [not found] ` <mailman.1298.1075010993.928.help-gnu-emacs@gnu.org>
2004-01-25 21:09   ` Jesper Harder
2004-01-26  6:08     ` Eli Zaretskii
     [not found]     ` <mailman.1343.1075097239.928.help-gnu-emacs@gnu.org>
2004-01-26 15:07       ` Stefan Monnier
2004-01-26 17:28         ` Eli Zaretskii
2004-01-27 15:22         ` Oliver Scholz
2004-01-27 16:33           ` Stefan Monnier
2004-01-26 15:20       ` Jesper Harder
2004-01-26 17:26         ` Eli Zaretskii
2004-01-27 14:44         ` Oliver Scholz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).