From: Carsten Dominik <carsten.dominik@gmail.com>
To: Eric Schulte <schulte.eric@gmail.com>
Cc: emacs-orgmode@gnu.org, Matthew Oesting <oestingm@me.com>
Subject: Re: Possible Calc support for Org-Babel?
Date: Fri, 29 Oct 2010 09:13:32 +0200 [thread overview]
Message-ID: <BDD2AC3B-0073-4387-A266-4EEEDCB09266@gmail.com> (raw)
In-Reply-To: <87zktxv6s2.fsf@gmail.com>
Cool!
- Carsten
On Oct 29, 2010, at 8:42 AM, Eric Schulte wrote:
> "Eric Schulte" <schulte.eric@gmail.com> 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
next prev parent reply other threads:[~2010-10-29 7:13 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-22 17:17 Possible Calc support for Org-Babel? Matthew Oesting
2010-10-26 18:37 ` Eric Schulte
2010-10-29 6:42 ` Eric Schulte
2010-10-29 7:13 ` Carsten Dominik [this message]
2010-10-29 11:14 ` Eric S Fraga
2010-10-29 14:43 ` Eric Schulte
2010-10-29 16:22 ` Eric Schulte
2010-10-29 19:53 ` Eric S Fraga
2010-10-29 20:26 ` Eric Schulte
[not found] ` <87hbg4pooh.fsf@ucl.ac.uk>
[not found] ` <871v7879x5.fsf@gmail.com>
2010-10-30 20:54 ` Eric S Fraga
2010-11-03 20:10 ` Eric Schulte
2010-10-29 11:27 ` Sébastien Vauban
2010-10-29 14:46 ` Eric Schulte
-- strict thread matches above, loose matches on Subject: below --
2010-11-03 22:42 Eric S Fraga
2010-11-04 13:24 ` Eric Schulte
2010-11-04 14:13 ` Eric S Fraga
2010-11-04 14:42 ` Sébastien Vauban
2010-11-04 15:33 ` Eric Schulte
2010-11-04 16:02 ` Sébastien Vauban
2011-01-27 0:39 ` Christopher Allan Webber
2011-02-23 4:35 ` Eric Schulte
2011-02-24 10:13 ` Eric S Fraga
2011-02-27 21:32 ` Eric Schulte
2011-02-28 18:16 ` Eric S Fraga
2011-03-01 17:34 ` Eric Schulte
2011-03-01 20:10 ` Eric S Fraga
2011-03-07 9:16 ` Eric S Fraga
2011-03-01 20:48 orgmode
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=BDD2AC3B-0073-4387-A266-4EEEDCB09266@gmail.com \
--to=carsten.dominik@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=oestingm@me.com \
--cc=schulte.eric@gmail.com \
/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).