From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: Possible Calc support for Org-Babel? Date: Fri, 29 Oct 2010 09:13:32 +0200 Message-ID: References: <7CDB7386-9B39-46CB-94E8-C6B5CBD59C4F@me.com> <87mxq0ajgw.fsf@gmail.com> <87zktxv6s2.fsf@gmail.com> Mime-Version: 1.0 (Apple Message framework v936) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Return-path: Received: from [140.186.70.92] (port=44423 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PBj9d-0001z8-Su for emacs-orgmode@gnu.org; Fri, 29 Oct 2010 03:13:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PBj9c-0007Dh-IW for emacs-orgmode@gnu.org; Fri, 29 Oct 2010 03:13:37 -0400 Received: from mail-ew0-f41.google.com ([209.85.215.41]:59097) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PBj9c-0007DX-9h for emacs-orgmode@gnu.org; Fri, 29 Oct 2010 03:13:36 -0400 Received: by ewy25 with SMTP id 25so1572136ewy.0 for ; Fri, 29 Oct 2010 00:13:35 -0700 (PDT) In-Reply-To: <87zktxv6s2.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Eric Schulte Cc: emacs-orgmode@gnu.org, Matthew Oesting Cool! - Carsten On Oct 29, 2010, at 8:42 AM, Eric Schulte wrote: > "Eric Schulte" writes: > >> >> Although I'm not familiar with using Calc as anything more than a 1- >> off >> calculator in the bottom of the frame (i.e. M-x calc) this sounds >> like a >> good approach to using calc to execute code blocks. >> > > Did I mention I'm not familiar with Calc. > > I've thrown together a very naive first pass at a function for > evaluating calc code blocks. This inverts the normal calc (as I > understand it) use of ' prefixes and assumes that every line is an > algebraic expression unless that line is prefixed with a ' in which > case > it is taken as a stack operation. > > This *does* change the value of the stack, allowing multiple code > blocks > to collaborate, in effect treating the stack as a session. I'd be > interested to hear what real calc users think of this approach. > > Best -- Eric > > to use this evaluate the following function, and then try the > subsequent > code blocks > > evaluate this code block to add support for calc code blocks > #+begin_src emacs-lisp > (defun org-babel-execute:calc (body params) > "Execute a block of calc code with Babel." > (mapcar > (lambda (line) > (when (> (length line) 0) > (if (string= "'" (substring line 0 1)) > (funcall (lookup-key calc-mode-map (substring line 1)) > nil) > (calc-push-list (list (math-read-number (calc-eval > line))))))) > (split-string body "[\n\r]")) > (calc-eval (calc-top 1))) > #+end_src > > This block pushes 1 and 2 on the stack, then adds them > #+begin_src calc > 1 > 2 > '+ > #+end_src > > This block evaluates 3^3 with calc pushing the result on the stack and > returning it into the Org-mode buffer > #+begin_src calc > 3^3 > #+end_src > > This block evaluates (2+2)*4 pushing the result on the stack, it then > calls calc-plus adding the top two elements on the stack (one of which > is left over from the previous code block). > #+begin_src calc > (2+2)*4 > '+ > #+end_src > > _______________________________________________ > Emacs-orgmode mailing list > Please use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode - Carsten