From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marco Wahl Subject: Re: ob-calc duplicate stack-element issue Date: Wed, 18 Mar 2020 15:47:22 +0100 Message-ID: <84fte5lnyd.fsf@gmail.com> References: <9eed12f5-face-eb4f-4006-e8ee7890e0a9@webbedtables.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:42270) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEZyi-0006TP-P7 for emacs-orgmode@gnu.org; Wed, 18 Mar 2020 10:47:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEZyg-0002dm-Br for emacs-orgmode@gnu.org; Wed, 18 Mar 2020 10:47:28 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:34409) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jEZyg-0002X8-5B for emacs-orgmode@gnu.org; Wed, 18 Mar 2020 10:47:26 -0400 Received: by mail-wm1-x32d.google.com with SMTP id x3so2487095wmj.1 for ; Wed, 18 Mar 2020 07:47:25 -0700 (PDT) In-Reply-To: <9eed12f5-face-eb4f-4006-e8ee7890e0a9@webbedtables.de> (Heiko Schmidt's message of "Sun, 15 Mar 2020 11:46:29 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane-mx.org@gnu.org Sender: "Emacs-orgmode" To: Heiko Schmidt Cc: emacs-orgmode@gnu.org Heiko Schmidt writes: > - problem: When evaluating the calc snippets the top of stack element > =C2=A0 is dropped. Because every "begin/end_src calc" block drops the top > =C2=A0 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 > =C2=A0 stack > > - tried solution: duplicate the last stack-element on evaluation with > =C2=A0 "' " (emulate press to duplicate the top element of the > =C2=A0 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 > =C2=A0 to the next (which I don't know)? > - alternative: Is there a way to duplicate the top of stack element > =C2=A0 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 <> <> '* #+end_src --8<---------------cut here---------------end--------------->8--- HTH, -- Marco