From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?utf-8?Q?S=C3=A9bastien_Vauban?= Subject: Re: Possible Calc support for Org-Babel? Date: Fri, 29 Oct 2010 13:27:40 +0200 Message-ID: <80iq0lp7bn.fsf@mundaneum.com> References: <7CDB7386-9B39-46CB-94E8-C6B5CBD59C4F@me.com> <87mxq0ajgw.fsf@gmail.com> <87zktxv6s2.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: 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-mXXj517/zsQ@public.gmane.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org-mXXj517/zsQ@public.gmane.org To: emacs-orgmode-mXXj517/zsQ@public.gmane.org Hi Eric, "Eric Schulte" wrote: > 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 o= f ' > prefixes and assumes that every line is an algebraic expression unless th= at > 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=3D "'" (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 Tried to run the following: > This block pushes 1 and 2 on the stack, then adds them > #+begin_src calc > 1 > 2 > '+ > #+end_src --8<---------------cut here---------------start------------->8--- executing Calc code block... if: Symbol's function definition is void: calc-push-list --8<---------------cut here---------------end--------------->8--- Required =3Dcalc=3D by calling =3DC-x * *=3D: --8<---------------cut here---------------start------------->8--- +-> Requiring `calc-macs' +-> Requiring `calc-macs'...done Loading c:/Program Files/Emacs-23/emacs/lisp/calc/calc-loaddefs.el... C-x * (Type ? for a list of Calc options) +-> Requiring `calc-ext' +-> Requiring `calc' (already loaded) +-> Requiring `calc-macs' (already loaded) +-> Requiring `calc-ext'...done +-> Requiring `calc-ext' (already loaded) +-> Requiring `calc-macs' (already loaded) Loading nil... +-> Requiring `calc-menu' +-> Requiring `calc-menu'...done +-> Requiring `calc' (already loaded) +-> Requiring `calc-macs' (already loaded) --8<---------------cut here---------------end--------------->8--- Tried again: --8<---------------cut here---------------start------------->8--- calc-do-embedded: Syntax error --8<---------------cut here---------------end--------------->8--- > 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 On the 2 lasts, I had another error: --8<---------------cut here---------------start------------->8--- executing Calc code block... +-> Requiring `calc' (already loaded) +-> Requiring `calc-macs' (already loaded) calc-push-list: Symbol's value as variable is void: calc-command-flags --8<---------------cut here---------------end--------------->8--- Best regards, Seb --=20 S=C3=A9bastien Vauban _______________________________________________ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode-mXXj517/zsQ@public.gmane.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode