all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Emanuel Berg via help-gnu-emacs <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Cc: Ingemar Holmgren <dag.h@hotmail.se>
Subject: Re: Calculator: no exponent, full number ?
Date: Thu, 06 Jun 2019 01:47:37 +0200	[thread overview]
Message-ID: <86tvd3sig6.fsf@zoho.eu> (raw)
In-Reply-To: 20190605095317.499f2082@mistral

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

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




  reply	other threads:[~2019-06-05 23:47 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-04 19:43 Calculator: no exponent, full number ? jonetsu
2019-06-04 22:42 ` Emanuel Berg via help-gnu-emacs
2019-06-05 11:15   ` Emanuel Berg via help-gnu-emacs
2019-06-05  4:11 ` Marcin Borkowski
2019-06-05  4:26   ` Emanuel Berg via help-gnu-emacs
2019-06-05 13:53   ` jonetsu
2019-06-05 23:47     ` Emanuel Berg via help-gnu-emacs [this message]
2019-06-06 14:50       ` Nick Dokos
2019-06-26  4:09         ` Xavier Maillard
2019-06-06 15:47       ` Marcin Borkowski
2019-06-06 16:50         ` Emanuel Berg via help-gnu-emacs
2019-06-06 17:04           ` tomas
2019-06-06 17:11             ` Emanuel Berg via help-gnu-emacs
2019-06-06 17:25               ` tomas
2019-06-07 19:36           ` Marcin Borkowski
2019-06-14 12:20   ` Van L
2019-06-14 13:26     ` Robert Pluim
2019-06-14 19:57       ` Stefan Monnier
2019-06-15  9:29       ` Van L
2019-06-14 19:43     ` Emanuel Berg via help-gnu-emacs
2019-06-15  9:23       ` Van L
  -- strict thread matches above, loose matches on Subject: below --
2019-06-06 17:28 Joe Trivers via help-gnu-emacs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86tvd3sig6.fsf@zoho.eu \
    --to=help-gnu-emacs@gnu.org \
    --cc=dag.h@hotmail.se \
    --cc=moasenwood@zoho.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.