# Tag Info

### elisp: Why does + without parameters return 0?

Math. The sum of nothing is obviously nothing. The product of nothing is more mysterious, because it isn’t nothing. But if you look closely you will soon notice that in both cases you get back the ...
• 18.2k

### elisp: Why does + without parameters return 0?

This is a very natural outcome. For instance, (+ 2 10 30) you know the result is 42, right? So, what if we remove the 10? Obviously, the result will decrease by 10, meaning the result of (+ 2 30) ...
• 5,318

### Quickly Evaluate Infix Math Expression?

You can use the built-in calc package to do so. Mark your expression, e.g. 3 * (1 + 1) Call calc-grab-region Call calc-dispatch (default C-x *), then hit g
• 3,878
Accepted

### Hоw add numbers in differents lines?

My favourite method for summing a column: Mark one corner of the rectangle Move point to the opposite corner Type C-x*: Acting on a rectangle is useful because it still works as-is if the numbers ...
• 51.5k
Accepted

### How to subtract 1 from the nth element of a list of numbers?

Using the built-in cl-lib package, you can write the following: (eval-when-compile (require 'cl-lib)) (cl-decf (nth 1 x)) Alternatively, in vanilla Elisp: (setf (nth 1 x) (1- (nth 1 x))) Be ...
• 381

### Does anyone know of a quick method to get hexadecimal line numbers in emacs?

Linum mode provides the linum-format customizable variable that allows you to format how you want your line numbers to appear. Set this variable to have the value "%x" to get hexadecimal ...
• 496

### minor mode to display long integers?

I did some searching and surprisingly couldn't find any existing minor modes that seemed to do this. I thought it would be a fun little project, however, so I've written a minimal minor mode (rainbow-...
• 496

### elisp: Why does + without parameters return 0?

This is due to associativity of addition: Sum(Array1) + Sum(Array2) = Sum(concat(Array1, Array2)) If Array1 is empty, we get Sum(Empty) + Sum(Array2) = Sum(Array2) thus Sum(Empty)=0. See also https:/...
• 6,124
Accepted

### How to change the color of numbers for a theme?

You can achieve highlighting of numbers in the buffers using highlight-numbers package. The face used for numbering is highlight-numbers-number and it inherits from font-lock-constant-face. For a ...

### How to use fixed point decimals in emacs lisp?

You could use the fractional representation of numbers from calc. I am not sure why you think that passing the amount as string is inconvenient for the user. I would pass that input to calc and ...
• 33.2k

### elisp: Why does + without parameters return 0?

I think you ask both: Why are + and * multiple-arity functions and they allow even zero arguments? Why isn't this the case for / (division)? Others have answered #1: both + and * have an identity ...
• 77.8k

### Hоw add numbers in differents lines?

Wrap the numbers in (+ ...), that is insert (+ at the beginning and ) at the end, then hit C-x C-e (eval-last-sexp).
• 14.6k

### Treat all numbers as floats

For numeric calculation there is a parallel universe within Elisp: Calc. The division operator / within defmath works with the floating numbers of Calc. Nevertheless, the interface of Calc with the ...
• 33.2k
Accepted

### Treat all numbers as floats

The following Elisp code demonstrates how you can define your own wrapper macro with-float/ that treats all explicit occurences of / in its body as division of floats. Division operators that are ...
• 33.2k

### Quickly Evaluate Infix Math Expression?

You might also use calc's embedded mode if you intent to replace an expression with its result in the current buffer. C-u C-x * e when your formula / expression is on it's own on a separate line. ...
• 1,906
Accepted

### Next greater or lesser number than ARG in a list of integers

Assuming that by lesser and greater you mean something like < and >, this seems to do what you ask. (defun my-func (num nbs pred) (let (ans) (dolist (nb nbs) (when (and (funcall ...
• 77.8k
Accepted

### Why can't I do this arithmetic operation on eshell? Error: "Symbol’s function definition is void: \,"

Eshell doesn’t like your numbers. It expects you to use a period for the decimal separator, and it also expects you not to use any thousands separator. Like this: ~/\$ (+ 0 -171055.81 -826735.77 ...
• 18.2k

### Using `string-to-number` causes rounding/precision issue for specific floating point values

What Every Programmer Should Know About Floating-Point Arithmetic is an excellent guide to understanding floating point numbers. I thoroughly recommend reading that in full -- I think it will answer ...
• 51.5k
Accepted

### How should one interpret the printed representation of integers in Emacs Lisp?

The ?\C-j is the character representation of 10, in this case it's the same as control-j. For other values, it's more natural, for example 65, which is the ASCII value of A: 65 -> 65 (#o101, #x41,...
• 6,170

What you're seeing is a byproduct of binary floating-point arithmetic. Non-integer decimal values generally don't have a representation in binary floating point that is truly equal. For many ...
• 7,499

### How can I use a char as a counter?

For your specific example, you can also use C-M-% affiliation RET \&[\,(string (+ ?a \#))] RET C-M-% is the default binding of query-replace-regexp affiliation is regexp to search for \&[\,(...
• 14.6k

### How can I use a char as a counter?

You probably want the make-string function. If count starts at 0 and counts up, then: (make-string 1 (+ ?a count)) will go a, b, c, etc.
• 1,456

### How to replace a digit by a letter?

The following should work: M-x query-replace-regexp RET \([0-9]+\) RET \,(string (+ (1- ?a) \#1)) RET
• 1,319

### Hоw add numbers in differents lines?

(defun sum-it-up () "Sum the whole buffer if no active region, or just the active region (if applicable). Copy the result to the kill ring. The result is thrown just in case anyone needs it." (...
• 19.2k
Accepted

### Representing leading zeroes in a list

You can use this org table formula, format is used to ensure the number's width is 2 and padded with zero, as @sds's answer suggested: #+NAME: addition-table | | 0 | 1 | 2 | 3 | 4 | 5 | 6 | ...
• 14.6k

### How to replace first 100 digits with letters?

You can use org-number-to-letter from org-table.el (requires at least Emacs 26.1 or Org 9.1.9?) (require 'org-table) (org-number-to-letters 26) ;; => "Z" (org-number-to-letters 52) ;; => "AZ" ...
• 14.6k

### How to replace first 100 digits with letters?

104 would be cz I think. Using org mode eval setup:-- I suspect there are better choices fr functions but I'm an elisp learner. These conversions might be more appropriates in your code in that ...
• 873
Accepted

### Expanding Abbrev Mode Alphabet

Yes, you can do this: (define-abbrev global-abbrev-table "h4" "hope for") if you really want an h4, you just "undo" (for me that is C-/, but you may have it bound to ...
• 11.9k