"Eric Schulte" <address@hidden> 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.
address@hidden
http://lists.gnu.org/mailman/listinfo/emacs-orgmode