[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Quick math calc on any buffer
From: |
Chetan |
Subject: |
Re: Quick math calc on any buffer |
Date: |
Tue, 24 Feb 2009 16:22:14 -0800 |
User-agent: |
Emacs Gnus |
Marc Tfardy <m-t-o___CUT__IT@web.de> writes:
> Chetan schrieb:
>> Scott Frazer <frazer.scott@gmail.com> writes:
>>
>>> On Feb 21, 11:42 am, Rodrigo Lazo <rlazo....@gmail.com> wrote:
>>>> Hi all,
>>>>
>>>> Is there a way to compute a math expression on any buffer? I mean, if I
>>>> have a buffer with the following expression
>>>>
>>>> 2 + 3
>>>>
>>>> I want to mark the region and compute the result
>>>>
>>>> 2 + 3 = 5
>>>>
>>>> It doesn't seems too hard to do, I've looked on calculator.el for a
>>>> "computing" function I can call but I didn't find it.
>>>>
>>> (defun my-calc-result (beg end)
>>> (interactive "r")
>>> (insert " = " (calc-eval (buffer-substring beg end))))
>
>> This makes me wonder, is there a rewriter of math expressions,
>> something like a macro that can rewrite the arithmetic expression as
>> regular lisp function calls?
>
> Yes. See my last post before. The call:
>
> (math-read-exprs "2 + 3")
>
> gives:
>
> ((+ 2 3))
>
> This was my attempt in my version of my-calc-result.
>
> reagrds
> Marc
I was thinking more like
(expr 2 + 3 + value) => (+ 2 3 value)
or (expr a + b * c) => (+ a (* b c))
which is, perhaps, simpler than reading from a string.