unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Tutorial question re conventions or usage ??
@ 2007-05-01 17:44 William Case
  2007-05-01 19:31 ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: William Case @ 2007-05-01 17:44 UTC (permalink / raw)
  To: EMACS List

Hi;

I am working my way through the Lisp tutorial.

I have come across the following example for the 'beginning-of-buffer'
function:

I can understand the Lisp in this code; the question is about normal
practises when writing similar code. 
...
(if (> (buffer-size) 10000)
           ;; Avoid overflow for large buffer sizes!
           (* (prefix-numeric-value arg)
              (/ (buffer-size) 10))
         (/ (+ 10 (* (buffer-size)
                     (prefix-numeric-value arg)))
...

In this code the writer has reduced the numbers by a factor of 10 in
order, it seems, to get the user to supply a one digit prefix that
none-the-less ends up being a percentage.  

Is this a convention in emacs or the writer's one time personal choice?

It seems intuitive to me (and easier to follow the code) if it had been
written as a percentage from the beginning and doing any factoring by
100.

Should I always be looking for ways to make prefix numbers a single
digit?

Does it matter?  Is there any gain or loss by using a longer or short
prefix digits?
-- 
Regards Bill

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

* Re: Tutorial question re conventions or usage ??
  2007-05-01 17:44 Tutorial question re conventions or usage ?? William Case
@ 2007-05-01 19:31 ` Eli Zaretskii
  2007-05-01 19:51   ` William Case
  0 siblings, 1 reply; 3+ messages in thread
From: Eli Zaretskii @ 2007-05-01 19:31 UTC (permalink / raw)
  To: help-gnu-emacs

> From: William Case <billlinux@rogers.com>
> Date: Tue, 01 May 2007 13:44:18 -0400
> 
> (if (> (buffer-size) 10000)
>            ;; Avoid overflow for large buffer sizes!
>            (* (prefix-numeric-value arg)
>               (/ (buffer-size) 10))
>          (/ (+ 10 (* (buffer-size)
>                      (prefix-numeric-value arg)))
> ...
> 
> In this code the writer has reduced the numbers by a factor of 10 in
> order, it seems, to get the user to supply a one digit prefix that
> none-the-less ends up being a percentage.  

I think it's more likely that the author wanted to avoid
floating-point arithmetics, and also avoid overflow (as the comment
says).  Interpreting the argument as percentage would require
multiplication by 100, which would exacerbate the integer overflow
problem.

Just a guess.

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

* Re: Tutorial question re conventions or usage ??
  2007-05-01 19:31 ` Eli Zaretskii
@ 2007-05-01 19:51   ` William Case
  0 siblings, 0 replies; 3+ messages in thread
From: William Case @ 2007-05-01 19:51 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

Thanks Eli

On Tue, 2007-05-01 at 22:31 +0300, Eli Zaretskii wrote:
> > From: William Case <billlinux@rogers.com>
> > Date: Tue, 01 May 2007 13:44:18 -0400
> > 
[snip]
> I think it's more likely that the author wanted to avoid
> floating-point arithmetics, and also avoid overflow (as the comment
> says).  Interpreting the argument as percentage would require
> multiplication by 100, which would exacerbate the integer overflow
> problem.
> 
> Just a guess.
> 

Just wanted make sure I understood the problem he was trying to solve.

-- 
Regards Bill

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

end of thread, other threads:[~2007-05-01 19:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-01 17:44 Tutorial question re conventions or usage ?? William Case
2007-05-01 19:31 ` Eli Zaretskii
2007-05-01 19:51   ` William Case

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