unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* (read (current-buffer)) returns an integer in a buffer full of text?
@ 2006-11-22 13:18 Sebastian Tennant
  0 siblings, 0 replies; 11+ messages in thread
From: Sebastian Tennant @ 2006-11-22 13:18 UTC (permalink / raw)


Hi everyone,

If I execute the following code in *scratch* there's no problem:

  (with-temp-buffer
    (insert "hello")
    (backward-word)
    (read (current-buffer)))
  => hello

But in my function, instead of a symbol I get an integer (which is
always the same):

  Debugger entered--returning value: 49243792
    read(#<buffer  *temp*<2>>)
  * (equal (read (current-buffer))

The buffer is visiting an uncompressed ASCII English text file and
point is before the word 'sda:' so it should return 'sda:' as a
symbol, (like 'hello').

Any light much appreciated.

Sebastian

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

* Re: (read (current-buffer)) returns an integer in a buffer full of text?
       [not found] <mailman.981.1164201541.2155.help-gnu-emacs@gnu.org>
@ 2006-11-23 17:31 ` Robert Thorpe
  2006-11-27 16:44   ` Kevin Rodgers
       [not found]   ` <mailman.1205.1164687201.2155.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 11+ messages in thread
From: Robert Thorpe @ 2006-11-23 17:31 UTC (permalink / raw)


Sebastian Tennant wrote:
> Hi everyone,
>
> If I execute the following code in *scratch* there's no problem:
>
>   (with-temp-buffer
>     (insert "hello")
>     (backward-word)
>     (read (current-buffer)))
>   => hello

The function with-temp-buffer creates a temp buffer for the duration of
it's body.  It does _not_ select that buffer as the current buffer.
You must use set-buffer or save-excursion too.

All AFAIK.

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

* Re: (read (current-buffer)) returns an integer in a buffer full of text?
  2006-11-23 17:31 ` (read (current-buffer)) returns an integer in a buffer full of text? Robert Thorpe
@ 2006-11-27 16:44   ` Kevin Rodgers
       [not found]   ` <mailman.1205.1164687201.2155.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 11+ messages in thread
From: Kevin Rodgers @ 2006-11-27 16:44 UTC (permalink / raw)


Robert Thorpe wrote:
> Sebastian Tennant wrote:
>> Hi everyone,
>>
>> If I execute the following code in *scratch* there's no problem:
>>
>>   (with-temp-buffer
>>     (insert "hello")
>>     (backward-word)
>>     (read (current-buffer)))
>>   => hello
> 
> The function with-temp-buffer creates a temp buffer for the duration of
> it's body.  It does _not_ select that buffer as the current buffer.

Why would that matter?  The (read (current-buffer)) form is evaluated
while the temp buffer is current.  Nothing depends on the temp buffer
still being current after that.

> You must use set-buffer or save-excursion too.
> 
> All AFAIK.

-- 
Kevin

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

* Re: (read (current-buffer)) returns an integer in a buffer full of text?
       [not found]   ` <mailman.1205.1164687201.2155.help-gnu-emacs@gnu.org>
@ 2006-11-28 14:34     ` Robert Thorpe
  2006-11-29 13:20       ` Sebastian Tennant
       [not found]       ` <mailman.1280.1164806477.2155.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 11+ messages in thread
From: Robert Thorpe @ 2006-11-28 14:34 UTC (permalink / raw)


Kevin Rodgers wrote:
> Robert Thorpe wrote:
> > Sebastian Tennant wrote:
> >> Hi everyone,
> >>
> >> If I execute the following code in *scratch* there's no problem:
> >>
> >>   (with-temp-buffer
> >>     (insert "hello")
> >>     (backward-word)
> >>     (read (current-buffer)))
> >>   => hello
> >
> > The function with-temp-buffer creates a temp buffer for the duration of
> > it's body.  It does _not_ select that buffer as the current buffer.
>
> Why would that matter?  The (read (current-buffer)) form is evaluated
> while the temp buffer is current.  Nothing depends on the temp buffer
> still being current after that.

You're right, my last sentence is 100% wrong.  With-temp-buffer does
set the temp buffer to be the current buffer.

I have no idea why this code doesn't work, it works for me under
similar conditions.
(The only mistake is that (backward-word) should be (backward-word 1))

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

* Re: (read (current-buffer)) returns an integer in a buffer full of text?
  2006-11-28 14:34     ` Robert Thorpe
@ 2006-11-29 13:20       ` Sebastian Tennant
       [not found]       ` <mailman.1280.1164806477.2155.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 11+ messages in thread
From: Sebastian Tennant @ 2006-11-29 13:20 UTC (permalink / raw)


Quoth "Robert Thorpe" <rthorpe@realworldtech.com>:
> Kevin Rodgers wrote:
>> Robert Thorpe wrote:
>> > Sebastian Tennant wrote:
>> >> Hi everyone,
>> >>
>> >> If I execute the following code in *scratch* there's no problem:
>> >>
>> >>   (with-temp-buffer
>> >>     (insert "hello")
>> >>     (backward-word)
>> >>     (read (current-buffer)))
>> >>   => hello
>> >
>> > The function with-temp-buffer creates a temp buffer for the duration of
>> > it's body.  It does _not_ select that buffer as the current buffer.
>>
>> Why would that matter?  The (read (current-buffer)) form is evaluated
>> while the temp buffer is current.  Nothing depends on the temp buffer
>> still being current after that.
>
> You're right, my last sentence is 100% wrong.  With-temp-buffer does
> set the temp buffer to be the current buffer.
>
> I have no idea why this code doesn't work, it works for me under
> similar conditions.
> (The only mistake is that (backward-word) should be (backward-word 1))

My error was in the location of point.  If two words are separated by
a space, and point at the beginning of the second word,
'(backward-word 2)' is required to move point to the beginning of the
first word.

However, why does this happen:

 (with-temp-buffer
   (insert "586114704")
   (backward-word)
   (read (current-buffer)))

 => 49243792

Is there an integer limit relating to symbols somehow?

Sebastian

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

* Re: (read (current-buffer)) returns an integer in a buffer full of text?
       [not found]       ` <mailman.1280.1164806477.2155.help-gnu-emacs@gnu.org>
@ 2006-11-29 14:17         ` Robert Thorpe
  2006-11-29 18:22           ` Kevin Rodgers
       [not found]           ` <mailman.1300.1164824626.2155.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 11+ messages in thread
From: Robert Thorpe @ 2006-11-29 14:17 UTC (permalink / raw)


Sebastian Tennant wrote:
> Quoth "Robert Thorpe" <rthorpe@realworldtech.com>:
> > Kevin Rodgers wrote:
> >> Robert Thorpe wrote:
> >> > Sebastian Tennant wrote:
> >> >> Hi everyone,
> >> >>
> >> >> If I execute the following code in *scratch* there's no problem:
> >> >>
> >> >>   (with-temp-buffer
> >> >>     (insert "hello")
> >> >>     (backward-word)
> >> >>     (read (current-buffer)))
> >> >>   => hello
> >> >
> >> > The function with-temp-buffer creates a temp buffer for the duration of
> >> > it's body.  It does _not_ select that buffer as the current buffer.
> >>
> >> Why would that matter?  The (read (current-buffer)) form is evaluated
> >> while the temp buffer is current.  Nothing depends on the temp buffer
> >> still being current after that.
> >
> > You're right, my last sentence is 100% wrong.  With-temp-buffer does
> > set the temp buffer to be the current buffer.
> >
> > I have no idea why this code doesn't work, it works for me under
> > similar conditions.
> > (The only mistake is that (backward-word) should be (backward-word 1))
>
> My error was in the location of point.  If two words are separated by
> a space, and point at the beginning of the second word,
> '(backward-word 2)' is required to move point to the beginning of the
> first word.
>
> However, why does this happen:
>
>  (with-temp-buffer
>    (insert "586114704")
>    (backward-word)
>    (read (current-buffer)))
>
>  => 49243792
>
> Is there an integer limit relating to symbols somehow?

The function "read" will read whatever type it finds.  It will treat
586114704 as an integer.

Try the following:-
Type 586114704 into scratch and do C-x C-e straight afterwards.
The echo area will display 49243792.  This is because there is a limit
on integers in Emacs, they are 26-bits long.  This allows you to
represent -67108865 to 67108864 I think.

Emacs doesn't warn you when you exceed the limit unfortunately.

Generally if you want to do numerical things with Lisp you should use
another lisp such as Common Lisp.

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

* Re: (read (current-buffer)) returns an integer in a buffer full of text?
  2006-11-29 14:17         ` Robert Thorpe
@ 2006-11-29 18:22           ` Kevin Rodgers
       [not found]           ` <mailman.1300.1164824626.2155.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 11+ messages in thread
From: Kevin Rodgers @ 2006-11-29 18:22 UTC (permalink / raw)


Robert Thorpe wrote:
> Sebastian Tennant wrote:
>> However, why does this happen:
>>
>>  (with-temp-buffer
>>    (insert "586114704")
>>    (backward-word)
>>    (read (current-buffer)))
>>
>>  => 49243792
>>
>> Is there an integer limit relating to symbols somehow?
> 
> The function "read" will read whatever type it finds.  It will treat
> 586114704 as an integer.
> 
> Try the following:-
> Type 586114704 into scratch and do C-x C-e straight afterwards.
> The echo area will display 49243792.  This is because there is a limit
> on integers in Emacs, they are 26-bits long.  This allows you to
> represent -67108865 to 67108864 I think.

,----[ C-h v most-positive-fixnum RET ]
| most-positive-fixnum is a variable defined in `C source code'.
| Its value is 268435455
|
| Documentation:
| The largest value that is representable in a Lisp integer.
|
| [back]
`----

> Emacs doesn't warn you when you exceed the limit unfortunately.
> 
> Generally if you want to do numerical things with Lisp you should use
> another lisp such as Common Lisp.

-- 
Kevin

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

* Re: (read (current-buffer)) returns an integer in a buffer full of text?
       [not found]           ` <mailman.1300.1164824626.2155.help-gnu-emacs@gnu.org>
@ 2006-11-29 18:46             ` Robert Thorpe
  2006-11-29 20:07               ` Peter Dyballa
       [not found]               ` <mailman.1309.1164830848.2155.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 11+ messages in thread
From: Robert Thorpe @ 2006-11-29 18:46 UTC (permalink / raw)


Kevin Rodgers wrote:
> Robert Thorpe wrote:
> > Sebastian Tennant wrote:
> >> However, why does this happen:
> >>
> >>  (with-temp-buffer
> >>    (insert "586114704")
> >>    (backward-word)
> >>    (read (current-buffer)))
> >>
> >>  => 49243792
> >>
> >> Is there an integer limit relating to symbols somehow?
> >
> > The function "read" will read whatever type it finds.  It will treat
> > 586114704 as an integer.
> >
> > Try the following:-
> > Type 586114704 into scratch and do C-x C-e straight afterwards.
> > The echo area will display 49243792.  This is because there is a limit
> > on integers in Emacs, they are 26-bits long.  This allows you to
> > represent -67108865 to 67108864 I think.
>
> ,----[ C-h v most-positive-fixnum RET ]
> | most-positive-fixnum is a variable defined in `C source code'.
> | Its value is 268435455
> |
> | Documentation:
> | The largest value that is representable in a Lisp integer.
> |
> | [back]
> `----

You must be using a CVS version of Emacs.  My version does not have
that variable and it certainly isn't that high.

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

* Re: (read (current-buffer)) returns an integer in a buffer full of text?
  2006-11-29 18:46             ` Robert Thorpe
@ 2006-11-29 20:07               ` Peter Dyballa
       [not found]               ` <mailman.1309.1164830848.2155.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 11+ messages in thread
From: Peter Dyballa @ 2006-11-29 20:07 UTC (permalink / raw)
  Cc: help-gnu-emacs


Am 29.11.2006 um 19:46 schrieb Robert Thorpe:

> You must be using a CVS version of Emacs.  My version does not have
> that variable and it certainly isn't that high.

GNU Emacs 20.7 had already 134,217,727 = 2^27 - 1.

I remember a mailing from last year, I think, in which the  
incremental progress of most-positive-fixnum was described in some  
detail. In my version of GNU Emacs 21.3.50 (the developer version of  
21.4) it is 2^28 - 1 ...

--
Greetings

   Pete

"Isn't vi that text editor with two modes... one that beeps and one
that corrupts your file?" -- Dan Jacobson, on comp.os.linux.advocacy

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

* Re: (read (current-buffer)) returns an integer in a buffer full of text?
       [not found]               ` <mailman.1309.1164830848.2155.help-gnu-emacs@gnu.org>
@ 2006-11-30 10:43                 ` Robert Thorpe
  2006-11-30 12:19                   ` Sebastian Tennant
  0 siblings, 1 reply; 11+ messages in thread
From: Robert Thorpe @ 2006-11-30 10:43 UTC (permalink / raw)


Peter Dyballa wrote:
> Am 29.11.2006 um 19:46 schrieb Robert Thorpe:
>
> > You must be using a CVS version of Emacs.  My version does not have
> > that variable and it certainly isn't that high.
>
> GNU Emacs 20.7 had already 134,217,727 = 2^27 - 1.
>
> I remember a mailing from last year, I think, in which the
> incremental progress of most-positive-fixnum was described in some
> detail. In my version of GNU Emacs 21.3.50 (the developer version of
> 21.4) it is 2^28 - 1 ...

I made a mistake, mine is 134,217,727 too.  I was trying exponents of 2
which is wrong!

I'm using GNU Emacs 21.3, in this version of Emacs there is no variable
called "most-positive-fixnum" loaded by default. This variable is in
the CL package.

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

* Re: (read (current-buffer)) returns an integer in a buffer full of text?
  2006-11-30 10:43                 ` Robert Thorpe
@ 2006-11-30 12:19                   ` Sebastian Tennant
  0 siblings, 0 replies; 11+ messages in thread
From: Sebastian Tennant @ 2006-11-30 12:19 UTC (permalink / raw)


Quoth "Robert Thorpe" <rthorpe@realworldtech.com>:
> Peter Dyballa wrote:
>> Am 29.11.2006 um 19:46 schrieb Robert Thorpe:
>>
>> > You must be using a CVS version of Emacs.  My version does not have
>> > that variable and it certainly isn't that high.
>>
>> GNU Emacs 20.7 had already 134,217,727 = 2^27 - 1.
>>
>> I remember a mailing from last year, I think, in which the
>> incremental progress of most-positive-fixnum was described in some
>> detail. In my version of GNU Emacs 21.3.50 (the developer version of
>> 21.4) it is 2^28 - 1 ...
>
> I made a mistake, mine is 134,217,727 too.  I was trying exponents of 2
> which is wrong!
>
> I'm using GNU Emacs 21.3, in this version of Emacs there is no variable
> called "most-positive-fixnum" loaded by default. This variable is in
> the CL package.

Thanks all.

Sebastian

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

end of thread, other threads:[~2006-11-30 12:19 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.981.1164201541.2155.help-gnu-emacs@gnu.org>
2006-11-23 17:31 ` (read (current-buffer)) returns an integer in a buffer full of text? Robert Thorpe
2006-11-27 16:44   ` Kevin Rodgers
     [not found]   ` <mailman.1205.1164687201.2155.help-gnu-emacs@gnu.org>
2006-11-28 14:34     ` Robert Thorpe
2006-11-29 13:20       ` Sebastian Tennant
     [not found]       ` <mailman.1280.1164806477.2155.help-gnu-emacs@gnu.org>
2006-11-29 14:17         ` Robert Thorpe
2006-11-29 18:22           ` Kevin Rodgers
     [not found]           ` <mailman.1300.1164824626.2155.help-gnu-emacs@gnu.org>
2006-11-29 18:46             ` Robert Thorpe
2006-11-29 20:07               ` Peter Dyballa
     [not found]               ` <mailman.1309.1164830848.2155.help-gnu-emacs@gnu.org>
2006-11-30 10:43                 ` Robert Thorpe
2006-11-30 12:19                   ` Sebastian Tennant
2006-11-22 13:18 Sebastian Tennant

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