unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* A question about category name in ELisp
@ 2013-10-05 10:43 Xue Fuqiao
  2013-10-05 12:41 ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Xue Fuqiao @ 2013-10-05 10:43 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I have a question about category and category table.  In (info
"(elisp) Categories"):

    Each category has a name, which is an ASCII printing character in
  the range ‘ ’ to ‘~’.  You specify the name of a category when you
  define it with ‘define-category’.
    The category table is actually a char-table (*note Char-Tables::).
  The element of the category table at index C is a "category set"—a
  bool-vector—that indicates which categories character C belongs to.
  In this category set, if the element at index CAT is ‘t’, that means
  category CAT is a member of the set, and that character C belongs to
  category CAT.

From the second paragraph, my impression about a category table is
something like this:

|     | a   | -   | .   | "   |
|-----+-----+-----+-----+-----|
| bv1 | bv2 | bv3 | bv4 | bv5 |

(The first row contains the indices of the char-table (i.e., the
"index C" above), and the second row contains the elements at index
C1, C2, ... (i.e., it's a category set, which is a bool-vector.))

As with all arrays, bool-vector indices start from 0, so CAT should be
an integer.  But according to my understanding, CAT is a category
name, which should be an ASCII printing character (instead of just an
integer, from the first paragraph).  Why?  Am I missing something?

-- 
Best regards, Xue Fuqiao.
http://www.gnu.org/software/emacs/



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

* Re: A question about category name in ELisp
  2013-10-05 10:43 A question about category name in ELisp Xue Fuqiao
@ 2013-10-05 12:41 ` Eli Zaretskii
  2013-10-06  4:04   ` Xue Fuqiao
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2013-10-05 12:41 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Sat, 5 Oct 2013 18:43:27 +0800
> From: Xue Fuqiao <xfq.free@gmail.com>
> 
> I have a question about category and category table.  In (info
> "(elisp) Categories"):
> 
>     Each category has a name, which is an ASCII printing character in
>   the range ‘ ’ to ‘~’.  You specify the name of a category when you
>   define it with ‘define-category’.
>     The category table is actually a char-table (*note Char-Tables::).
>   The element of the category table at index C is a "category set"—a
>   bool-vector—that indicates which categories character C belongs to.
>   In this category set, if the element at index CAT is ‘t’, that means
>   category CAT is a member of the set, and that character C belongs to
>   category CAT.
> 
> >From the second paragraph, my impression about a category table is
> something like this:
> 
> |     | a   | -   | .   | "   |
> |-----+-----+-----+-----+-----|
> | bv1 | bv2 | bv3 | bv4 | bv5 |
> 
> (The first row contains the indices of the char-table (i.e., the
> "index C" above), and the second row contains the elements at index
> C1, C2, ... (i.e., it's a category set, which is a bool-vector.))
> 
> As with all arrays, bool-vector indices start from 0, so CAT should be
> an integer.  But according to my understanding, CAT is a category
> name, which should be an ASCII printing character (instead of just an
> integer, from the first paragraph).  Why?  Am I missing something?

You need to read about char-table, your assumption about its structure
is wrong.  In particular, a char-table is not a flat array, and it is
indexed by characters, not by zero-based integers.





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

* Re: A question about category name in ELisp
  2013-10-05 12:41 ` Eli Zaretskii
@ 2013-10-06  4:04   ` Xue Fuqiao
  2013-10-06 15:47     ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Xue Fuqiao @ 2013-10-06  4:04 UTC (permalink / raw)
  To: help-gnu-emacs

On Sat, Oct 5, 2013 at 8:41 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>> Date: Sat, 5 Oct 2013 18:43:27 +0800
>> From: Xue Fuqiao <xfq.free@gmail.com>
>>
>> I have a question about category and category table.  In (info
>> "(elisp) Categories"):
>>
>>     Each category has a name, which is an ASCII printing character in
>>   the range ‘ ’ to ‘~’.  You specify the name of a category when you
>>   define it with ‘define-category’.
>>     The category table is actually a char-table (*note Char-Tables::).
>>   The element of the category table at index C is a "category set"—a
>>   bool-vector—that indicates which categories character C belongs to.
>>   In this category set, if the element at index CAT is ‘t’, that means
>>   category CAT is a member of the set, and that character C belongs to
>>   category CAT.
>>
>> >From the second paragraph, my impression about a category table is
>> something like this:
>>
>> |     | a   | -   | .   | "   |
>> |-----+-----+-----+-----+-----|
>> | bv1 | bv2 | bv3 | bv4 | bv5 |
>>
>> (The first row contains the indices of the char-table (i.e., the
>> "index C" above), and the second row contains the elements at index
>> C1, C2, ... (i.e., it's a category set, which is a bool-vector.))
>>
>> As with all arrays, bool-vector indices start from 0, so CAT should be
>> an integer.  But according to my understanding, CAT is a category
>> name, which should be an ASCII printing character (instead of just an
>> integer, from the first paragraph).  Why?  Am I missing something?
>
> You need to read about char-table, your assumption about its structure
> is wrong.  In particular, a char-table is not a flat array, and it is
> indexed by characters, not by zero-based integers.

Thanks, but IIUC I think bool-vector (the "category set") is not a
char-table.  The "category table" is a char-table.

-- 
Best regards, Xue Fuqiao.
http://www.gnu.org/software/emacs/



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

* Re: A question about category name in ELisp
  2013-10-06  4:04   ` Xue Fuqiao
@ 2013-10-06 15:47     ` Eli Zaretskii
  2013-10-07  0:56       ` Xue Fuqiao
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2013-10-06 15:47 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Sun, 6 Oct 2013 12:04:25 +0800
> From: Xue Fuqiao <xfq.free@gmail.com>
> 
> >> >From the second paragraph, my impression about a category table is
> >> something like this:
> >>
> >> |     | a   | -   | .   | "   |
> >> |-----+-----+-----+-----+-----|
> >> | bv1 | bv2 | bv3 | bv4 | bv5 |
> >>
> >> (The first row contains the indices of the char-table (i.e., the
> >> "index C" above), and the second row contains the elements at index
> >> C1, C2, ... (i.e., it's a category set, which is a bool-vector.))
> >>
> >> As with all arrays, bool-vector indices start from 0, so CAT should be
> >> an integer.  But according to my understanding, CAT is a category
> >> name, which should be an ASCII printing character (instead of just an
> >> integer, from the first paragraph).  Why?  Am I missing something?
> >
> > You need to read about char-table, your assumption about its structure
> > is wrong.  In particular, a char-table is not a flat array, and it is
> > indexed by characters, not by zero-based integers.
> 
> Thanks, but IIUC I think bool-vector (the "category set") is not a
> char-table.  The "category table" is a char-table.

Indeed, and you've drawn a schematics of the category table above,
which is what I was alluding to.  Your picture of the category table
is incorrect, as a char-table is not a flat array.

Another thing that you seem to be missing is that every character is
also a small integer, so a bool-vector of length 128 can be indexed
by any ASCII character.  And a category set is a set of 128 slots, as
you can see by evaluating this:

  (aref (category-table) ?a)

(You can use any ASCII character instead of ?a.)



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

* Re: A question about category name in ELisp
  2013-10-06 15:47     ` Eli Zaretskii
@ 2013-10-07  0:56       ` Xue Fuqiao
  0 siblings, 0 replies; 5+ messages in thread
From: Xue Fuqiao @ 2013-10-07  0:56 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

On Sun, Oct 6, 2013 at 11:47 PM, Eli Zaretskii <eliz@gnu.org> wrote:
> Another thing that you seem to be missing is that every character is
> also a small integer

This is what I was missing.  Thank you!

-- 
Best regards, Xue Fuqiao.
http://www.gnu.org/software/emacs/



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

end of thread, other threads:[~2013-10-07  0:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-05 10:43 A question about category name in ELisp Xue Fuqiao
2013-10-05 12:41 ` Eli Zaretskii
2013-10-06  4:04   ` Xue Fuqiao
2013-10-06 15:47     ` Eli Zaretskii
2013-10-07  0:56       ` Xue Fuqiao

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).