emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Marco Wahl <marcowahlsoft@gmail.com>
To: Heiko Schmidt <Heiko.Schmidt@webbedtables.de>
Cc: emacs-orgmode@gnu.org
Subject: Re: ob-calc duplicate stack-element issue
Date: Wed, 18 Mar 2020 15:47:22 +0100	[thread overview]
Message-ID: <84fte5lnyd.fsf@gmail.com> (raw)
In-Reply-To: <9eed12f5-face-eb4f-4006-e8ee7890e0a9@webbedtables.de> (Heiko Schmidt's message of "Sun, 15 Mar 2020 11:46:29 +0100")

Heiko Schmidt <Heiko.Schmidt@webbedtables.de> writes:

> - problem: When evaluating the calc snippets the top of stack element
>    is dropped. Because every "begin/end_src calc" block drops the top
>    of stack, one can't reuse the result in following blocks.

> Number of cars (PKW) in germany:
>
> #+begin_src calc :exports both
> 45e6
> #+end_src
>
>
> #+RESULTS:
> : 45000000.
>
> Yearly mileage in [km/y]
>
> #+begin_src calc :exports both
> 15000
> #+end_src
>
>
> #+RESULTS:
> : 15000
>
> Calculate amount of complete km per year
>
> #+begin_src calc :exports both
> '*
> #+end_src
>
>
> #+RESULTS:
> : 675000000000.

> - problem: babel removes the resulting top stack element from the
>    stack
>
> - tried solution: duplicate the last stack-element on evaluation with
>    "' " (emulate <space> press to duplicate the top element of the
>    stack in calc)

> ** hope for a solution or work around from the community
>
> - preferred: Is there a way to leave the top of stack from one snippet
>    to the next (which I don't know)?
> - alternative: Is there a way to duplicate the top of stack element
>    between begin/end_src calc blocks?
> - any advice is appreciated.

Okay.  I take here the "any advice is appreciated" part.

AFAICS at the org babel calc evaluation the last value of the calc stack
gets dropped.

So your workaround is okay, I think.  You can just write any dummy
element at the bottom of each block e.g. just 0.  No need of
duplication.  Looks a bit hackish to me but so what?

Another approach could be "noweb".  Example (you would just evaluate the
block at the bottom):

--8<---------------cut here---------------start------------->8---
Number of cars (PKW) in germany:

#+name: numcars
#+begin_src calc :exports both
45e6
#+end_src

Yearly mileage in [km/y]

#+name: mileage
#+begin_src calc :exports both
15000
#+end_src

Calculate amount of complete km per year

#+begin_src calc :noweb yes
<<numcars>>
<<mileage>>
'*
#+end_src
--8<---------------cut here---------------end--------------->8---


HTH,
-- Marco

  parent reply	other threads:[~2020-03-18 14:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-15 10:46 ob-calc duplicate stack-element issue Heiko Schmidt
2020-03-15 12:06 ` Eric S Fraga
2020-03-15 15:08   ` Heiko Schmidt
2020-03-18 14:47 ` Marco Wahl [this message]
2020-03-18 15:50   ` Eric S Fraga
2020-03-18 16:23     ` Marco Wahl
2020-03-18 16:41       ` Eric S Fraga
2020-04-06  4:39     ` Heiko Schmidt
2020-04-06  4:16   ` Heiko Schmidt

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

  List information: https://www.orgmode.org/

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

  git send-email \
    --in-reply-to=84fte5lnyd.fsf@gmail.com \
    --to=marcowahlsoft@gmail.com \
    --cc=Heiko.Schmidt@webbedtables.de \
    --cc=emacs-orgmode@gnu.org \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).