From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Nick Dokos Newsgroups: gmane.emacs.help Subject: Re: Calculator: no exponent, full number ? Date: Thu, 06 Jun 2019 10:50:05 -0400 Message-ID: <87muiurco2.fsf@alphaville.usersys.redhat.com> References: <20190604154307.565d33cf@mistral> <87zhmwzn67.fsf@mbork.pl> <20190605095317.499f2082@mistral> <86tvd3sig6.fsf@zoho.eu> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="100533"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jun 06 16:50:29 2019 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hYtik-000Q0F-FU for geh-help-gnu-emacs@m.gmane.org; Thu, 06 Jun 2019 16:50:26 +0200 Original-Received: from localhost ([127.0.0.1]:33513 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYtij-0004qS-GN for geh-help-gnu-emacs@m.gmane.org; Thu, 06 Jun 2019 10:50:25 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:59745) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYtiY-0004qC-Mo for help-gnu-emacs@gnu.org; Thu, 06 Jun 2019 10:50:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hYtiX-00031v-JD for help-gnu-emacs@gnu.org; Thu, 06 Jun 2019 10:50:14 -0400 Original-Received: from [195.159.176.226] (port=52306 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hYtiX-0002zo-C5 for help-gnu-emacs@gnu.org; Thu, 06 Jun 2019 10:50:13 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1hYtiV-000Pho-BI for help-gnu-emacs@gnu.org; Thu, 06 Jun 2019 16:50:11 +0200 X-Injected-Via-Gmane: http://gmane.org/ Cancel-Lock: sha1:32Pxx1hXWT/gnqCtRQ0QEprRrgg= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 195.159.176.226 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:120777 Archived-At: Emanuel Berg via help-gnu-emacs 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