all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Using `eval-expression' for math
@ 2008-04-03 12:52 reader
  2008-04-03 13:53 ` Lennart Borgman (gmail)
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: reader @ 2008-04-03 12:52 UTC (permalink / raw)
  To: help-gnu-emacs

Can someone show me how to do math with the eval-expression tool?

(+ 2 2) and such simple problems I can do of course but when it comes
to combining things like:

52 * 32 / 12

  Trying (* 52 32 ( / 12)) 

or
        (/  12 ( * 52 32 ))

Goes nowhere fast, and from there I can't really imagine how else to
arrange the parens.

I get completely lost with the paren arrangement.  Obviously my lisp
skills are non-existent but I'm guessing there are a few basic rules
that will allow me to do basic math like the problem above quickly
without having to resort to my old stand by:
  
  awk 'BEGIN{print ((52 * 32) / 12)}'

Or simply:

  awk 'BEGIN{print (52 * 32 / 12)}'

Using awk takes longer to get it done than a quick `eval-expression' inside
emacs would take.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Using `eval-expression' for math
  2008-04-03 12:52 Using `eval-expression' for math reader
@ 2008-04-03 13:53 ` Lennart Borgman (gmail)
  2008-04-03 13:58 ` Thierry Volpiatto
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Lennart Borgman (gmail) @ 2008-04-03 13:53 UTC (permalink / raw)
  To: reader; +Cc: help-gnu-emacs

reader@newsguy.com wrote:
> Can someone show me how to do math with the eval-expression tool?
> 
> (+ 2 2) and such simple problems I can do of course but when it comes
> to combining things like:
> 
> 52 * 32 / 12
> 
>   Trying (* 52 32 ( / 12)) 
> 
> or
>         (/  12 ( * 52 32 ))
> 
> Goes nowhere fast, and from there I can't really imagine how else to
> arrange the parens.

Just think "inner first" and watch for the argument order of course:

   (/ (* 52 32) 12)




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Using `eval-expression' for math
  2008-04-03 12:52 Using `eval-expression' for math reader
  2008-04-03 13:53 ` Lennart Borgman (gmail)
@ 2008-04-03 13:58 ` Thierry Volpiatto
  2008-04-04 20:28   ` reader
  2008-04-03 18:45 ` Nikolaj Schumacher
       [not found] ` <mailman.9953.1207248322.18990.help-gnu-emacs@gnu.org>
  3 siblings, 1 reply; 7+ messages in thread
From: Thierry Volpiatto @ 2008-04-03 13:58 UTC (permalink / raw)
  To: reader; +Cc: help-gnu-emacs

reader@newsguy.com writes:

> Can someone show me how to do math with the eval-expression tool?
>
> (+ 2 2) and such simple problems I can do of course but when it comes
> to combining things like:
>
> 52 * 32 / 12
>
>   Trying (* 52 32 ( / 12)) 
>
> or
>         (/  12 ( * 52 32 ))
>
> Goes nowhere fast, and from there I can't really imagine how else to
> arrange the parens.
>
> I get completely lost with the paren arrangement.  Obviously my lisp
> skills are non-existent but I'm guessing there are a few basic rules
> that will allow me to do basic math like the problem above quickly
> without having to resort to my old stand by:
>   
>   awk 'BEGIN{print ((52 * 32) / 12)}'
>
> Or simply:
>
>   awk 'BEGIN{print (52 * 32 / 12)}'
>
> Using awk takes longer to get it done than a quick `eval-expression' inside
> emacs would take.
>

Not sure to understand what you want to do , is it that?

,----
| ELISP> (/ (* 52 32) 12)
| 138
`----

Or that?

,----
| ELISP> (/ (* 52 32) 12.0)
| 138.66666666666666
`----

Or that?

,----
| ELISP> (/ (round (* 100 (/ (* 52 32) 12.0))) 100.0)
| 138.67
`----

In a shell?

,----
| thierry@thievol ~ $ bc -l<<EOF
| > scale=2
| > 52 * 32 / 12
| > EOF
| 138.66
`----

-- 
A + Thierry
Pub key: http://pgp.mit.edu




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Using `eval-expression' for math
  2008-04-03 12:52 Using `eval-expression' for math reader
  2008-04-03 13:53 ` Lennart Borgman (gmail)
  2008-04-03 13:58 ` Thierry Volpiatto
@ 2008-04-03 18:45 ` Nikolaj Schumacher
       [not found] ` <mailman.9953.1207248322.18990.help-gnu-emacs@gnu.org>
  3 siblings, 0 replies; 7+ messages in thread
From: Nikolaj Schumacher @ 2008-04-03 18:45 UTC (permalink / raw)
  To: reader; +Cc: help-gnu-emacs

reader@newsguy.com wrote:

> Using awk takes longer to get it done than a quick `eval-expression' inside
> emacs would take.

If you don't like the reverse notation, you could also do this:

(calc-eval "52 * 32 / 12")


Personally I like to just type such stuff in the buffer, mark it, and
have it replaced by the result.  That's why I wrote this:

http://nschum.de/src/emacs/macro-math/





regards,
Nikolaj Schumacher




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Using `eval-expression' for math
       [not found] ` <mailman.9953.1207248322.18990.help-gnu-emacs@gnu.org>
@ 2008-04-03 21:11   ` weber
  2008-04-04 20:40   ` Jay Belanger
  1 sibling, 0 replies; 7+ messages in thread
From: weber @ 2008-04-03 21:11 UTC (permalink / raw)
  To: help-gnu-emacs

On Apr 3, 3:45 pm, Nikolaj Schumacher <n_schumac...@web.de> wrote:
> rea...@newsguy.com wrote:
> > Using awk takes longer to get it done than a quick `eval-expression' inside
> > emacs would take.
>
> If you don't like the reverse notation, you could also do this:
>
> (calc-eval "52 * 32 / 12")
>
> Personally I like to just type such stuff in the buffer, mark it, and
> have it replaced by the result.  That's why I wrote this:
>
> http://nschum.de/src/emacs/macro-math/
>
> regards,
> Nikolaj Schumacher

This is great, thanks!
I specially like that it works across newlines:

1
+10
-2
+1
-3

:)


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Using `eval-expression' for math
  2008-04-03 13:58 ` Thierry Volpiatto
@ 2008-04-04 20:28   ` reader
  0 siblings, 0 replies; 7+ messages in thread
From: reader @ 2008-04-04 20:28 UTC (permalink / raw)
  To: help-gnu-emacs

Thierry Volpiatto <thierry.volpiatto@gmail.com> writes:


[...]

All are nice.  All posts contain good info and good solutions.

The `inner first' dictum is good for old folks memory...

Thanks posters





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Using `eval-expression' for math
       [not found] ` <mailman.9953.1207248322.18990.help-gnu-emacs@gnu.org>
  2008-04-03 21:11   ` weber
@ 2008-04-04 20:40   ` Jay Belanger
  1 sibling, 0 replies; 7+ messages in thread
From: Jay Belanger @ 2008-04-04 20:40 UTC (permalink / raw)
  To: help-gnu-emacs


Nikolaj Schumacher <n_schumacher@web.de> writes:
...
> If you don't like the reverse notation, you could also do this:
>
> (calc-eval "52 * 32 / 12")
>
>
> Personally I like to just type such stuff in the buffer, mark it, and
> have it replaced by the result.  That's why I wrote this:
>
> http://nschum.de/src/emacs/macro-math/

You can also do that, in a slightly different way, with Calc's embedded
mode.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-04-04 20:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-03 12:52 Using `eval-expression' for math reader
2008-04-03 13:53 ` Lennart Borgman (gmail)
2008-04-03 13:58 ` Thierry Volpiatto
2008-04-04 20:28   ` reader
2008-04-03 18:45 ` Nikolaj Schumacher
     [not found] ` <mailman.9953.1207248322.18990.help-gnu-emacs@gnu.org>
2008-04-03 21:11   ` weber
2008-04-04 20:40   ` Jay Belanger

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.