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

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

Re: Calculator: no exponent, full number ?


From: Nick Dokos
Subject: Re: Calculator: no exponent, full number ?
Date: Thu, 06 Jun 2019 10:50:05 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Emanuel Berg via help-gnu-emacs <help-gnu-emacs@gnu.org> writes:

> jonetsu wrote:
>
>> Emmanuel Berg: "Or use Lisp, create a file
>> and just type Lisp. With `format', you can
>> get the result look anyway you want."
>>
>> I must say that I do not know anything about
>> Lisp [...]
>
> If you want to do math with Lisp, it is much
> better to be good with math and bad at Lisp,
> than the other way around.
>
> Because it is very easy. Just understand the
> "fully parenthesized prefix notation" [1] and
> that will be it.
>
> So, the operator comes first:
> (+ 1 2 3 4) ; is 1 + 2 + 3 + 4 = 10
>
> And, the priority of operators is never an
> issue as _everything_ is parenthesized.
>
> That's it!
>
> For more advanced math, you'll probably need to
> find a math library with additional operators
> and constants, perhaps in on of the
> [M]ELPA packs, but for the basic stuff, it is
> as simple as it can be.
>
> Here, have a look:
>
>
> (defun hypotenuse (c1 c2)
>   (sqrt (+ (* c1 c1) (* c2 c2))) )
>
>
> or, a little bit more advanced, involving
> a list and a set function:
>
>
> (defun mean-value (vs)
>   (let*((sum  (apply #'+ vs))
>         (mean (/ sum (length vs) 1.0)) )
>     mean) ) ; [2]
>
>
> Eval me: (mean-value '(1 2 3 4 5.5)) ; 3.1
>
>
> One of the advantages with this Lisp-file
> method is that you have every data item in the
> file. Nothing gets lost in the history of the
> calculator, and what you have you can change
> and instantly have the whole thing
> computed anew.
>
>
> [1] https://en.wikipedia.org/wiki/Lisp_(programming_language)
> [2] https://dataswamp.org/~incal/emacs-init/my-math.el

I'd like to put in a plug for Dave Gillespie's calc, that's part
of emacs. Just say

    M-x calc

type `h i', read the manual (as much of it as you can possibly take:
it's big) and go calculate.

-- 
Nick

"There are only two hard problems in computer science: cache
invalidation, naming things, and off-by-one errors." -Martin Fowler




reply via email to

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