From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Emanuel Berg via help-gnu-emacs Newsgroups: gmane.emacs.help Subject: Re: Calculator: no exponent, full number ? Date: Thu, 06 Jun 2019 01:47:37 +0200 Message-ID: <86tvd3sig6.fsf@zoho.eu> References: <20190604154307.565d33cf@mistral> <87zhmwzn67.fsf@mbork.pl> <20190605095317.499f2082@mistral> Reply-To: Emanuel Berg Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="256485"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Cc: Ingemar Holmgren 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 01:48:12 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 1hYfda-0014ZD-L2 for geh-help-gnu-emacs@m.gmane.org; Thu, 06 Jun 2019 01:48:10 +0200 Original-Received: from localhost ([127.0.0.1]:51841 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYfdX-00007n-HI for geh-help-gnu-emacs@m.gmane.org; Wed, 05 Jun 2019 19:48:07 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:52253) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYfdJ-00007i-S4 for help-gnu-emacs@gnu.org; Wed, 05 Jun 2019 19:47:54 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hYfdI-00064s-He for help-gnu-emacs@gnu.org; Wed, 05 Jun 2019 19:47:53 -0400 Original-Received: from [195.159.176.226] (port=54990 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hYfdI-0005vq-B7 for help-gnu-emacs@gnu.org; Wed, 05 Jun 2019 19:47:52 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1hYfdC-0014Av-4q for help-gnu-emacs@gnu.org; Thu, 06 Jun 2019 01:47:46 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Mail-Copies-To: never Cancel-Lock: sha1:OQ5WxniR3jkYkW3BpjAmPEvj3ww= 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:120755 Archived-At: 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