help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Run terminal command with output in current buffer


From: Emanuel Berg
Subject: Re: Run terminal command with output in current buffer
Date: Mon, 19 Jul 2021 02:42:44 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Stefan Monnier via Users list for the GNU Emacs text editor wrote:

> Only use `setq` when you really want that variable to
> contain different values at different times.

How do you do it when you compute a value as part of a loop?

We just saw it with binary-search, so let's use that
as example. OK, so they use `setf', not `setq' (set function,
not set function quote - ?)

That's better, really? Not in that sense at least?

(defun binary-search (value array)
  (let ((low 0)
        (high (1- (length array))))
    (cl-do () ((< high low) nil)
      (let ((middle (floor (+ low high) 2)))
        (cond ((> (aref array middle) value)
               (setf high (1- middle)))
              ((< (aref array middle) value)
               (setf low (1+ middle)))
              (t (cl-return middle)))))))

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]