emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Possible Calc support for Org-Babel?
@ 2010-10-22 17:17 Matthew Oesting
  2010-10-26 18:37 ` Eric Schulte
  0 siblings, 1 reply; 27+ messages in thread
From: Matthew Oesting @ 2010-10-22 17:17 UTC (permalink / raw)
  To: emacs-orgmode

A few of us at my institution have started using CALC in our documents (not embedded, which is far too clumsy for most of us, but C-x * u and simple embedded phrases, often to the tune of several pages) to use Emacs text files rather like Maple and Mathematica files.  We're starting to use GIT and OrgMode together to format the work and save versions and forks; while there are many CAS packages that can be used to write out memos and reports, the power of Elisp/Emacs was simply too good to pass up.

It appears that Calc syntax can be used to assign formulas to spreadsheets, but the result is difficult to read, and unsuitable for a sequence of several dozen lines.  Similarly, using embedded Ruby-symbolic code in the text produces excellent results, but we lose the ability to take advantage of Calc, which is significantly stronger for our purposes.  Other symbolic packages require more time to learn and are difficult to implement across all of our various platforms, whereas Calc is a universal and extremely flexible tool for this work.

My questions are these:
  * Has there been implemented, or would it be at all difficult to implement, a 'calc' language functionality for Org-Babel allowing the following manner of text:

> #+begin_src calc :results output 
> Fish = 2
> Dog = 2 * Fish
> 
> sqrt( Dog ) =>
> sqrt( 4 ) =>
> #+end_src
> 
> #+results:
> : sqrt( Dog ) => 2
> : sqrt( 4 ) = 2

The goal of this exercise would simply be to cut out the text from the code block, feed it to a buffer, run the Emacs Calc mode on it, and then output the appropriate results where => occurs.

 * Has there been implemented, or would it be at all difficult to implement, a 'running tag' approach to the Calc mode, essentially a #+CALC directive allowing the following manner of text, preferably with auto-update:

> This is a discussion.
>
> #+CALC: Fish = 2
>
> Fish deserves significant commentary; however, we expect that there is some command
>  that would allow us to update the entire buffer's #+CALC sequence.  Thus:
> 
> #+CALC: Dog = 2 * Fish
> #+CALC: sqrt( Dog ) =>
> #+results:
> : sqrt( Dog ) => 2
>
> If you need a different result, tweak the 'Fish =' line, above, and request a re-sequencing,
>  either via C-c C-c or via some M-x command, resulting in behavior functionally similar to
> C-x * u.

The goal of this exercise would be, upon updating, to strip all lines beginning with #+CALC and feed them to a buffer, inserting the results of => statements where the respective line occurs.  The benefit of this method over the previous is that it allows for assignments (:=) enduring across entire files (though the same could be accomplished if one SRC_BEGIN block could somehow call another.)

In conclusion, it seems to me that I cannot possibly be the first person to have done research in OrgMode, and that these problems were likely solved long ago.  When searching the manual, however, I find nothing that produces a distinctly clear and encapsulated Calc embed in OrgMode.  Do these exist, and if not, would it require mere hours of time to implement them, or weeks?  Is there a tutorial on writing OrgMode extensions?

- M

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
  2010-10-22 17:17 Matthew Oesting
@ 2010-10-26 18:37 ` Eric Schulte
  2010-10-29  6:42   ` Eric Schulte
  0 siblings, 1 reply; 27+ messages in thread
From: Eric Schulte @ 2010-10-26 18:37 UTC (permalink / raw)
  To: Matthew Oesting; +Cc: emacs-orgmode

Hi Matthew,

Matthew Oesting <oestingm@me.com> writes:

> A few of us at my institution have started using CALC in our documents
> (not embedded, which is far too clumsy for most of us, but C-x * u and
> simple embedded phrases, often to the tune of several pages) to use
> Emacs text files rather like Maple and Mathematica files.  We're
> starting to use GIT and OrgMode together to format the work and save
> versions and forks; while there are many CAS packages that can be used
> to write out memos and reports, the power of Elisp/Emacs was simply
> too good to pass up.
>
> It appears that Calc syntax can be used to assign formulas to
> spreadsheets, but the result is difficult to read, and unsuitable for
> a sequence of several dozen lines.  Similarly, using embedded
> Ruby-symbolic code in the text produces excellent results, but we lose
> the ability to take advantage of Calc, which is significantly stronger
> for our purposes.  Other symbolic packages require more time to learn
> and are difficult to implement across all of our various platforms,
> whereas Calc is a universal and extremely flexible tool for this work.
>
> My questions are these:
>   * Has there been implemented, or would it be at all difficult to
>   implement, a 'calc' language functionality for Org-Babel allowing
>   the following manner of text:
>

A Calc language has not yet been implemented, however (although I'd have
to look at Calc's support for running series of commands) I do not think
it would be difficult to implement such functionality.  In fact I think
this is a very good idea.

If you're feeling brave, it may make sense to look at a couple of the
shorter examples of languages supported by Babel (e.g. ob-dot.el) and
try to adapt their functions for working with Calc as you describe below
(see below for more information on implementing a calc interface).

>
>> #+begin_src calc :results output 
>> Fish = 2
>> Dog = 2 * Fish
>> 
>> sqrt( Dog ) =>
>> sqrt( 4 ) =>
>> #+end_src
>> 
>> #+results:
>> : sqrt( Dog ) => 2
>> : sqrt( 4 ) = 2
>
> The goal of this exercise would simply be to cut out the text from the
> code block, feed it to a buffer, run the Emacs Calc mode on it, and
> then output the appropriate results where => occurs.
>

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.

>
>  * Has there been implemented, or would it be at all difficult to
>  implement, a 'running tag' approach to the Calc mode, essentially a
>  #+CALC directive allowing the following manner of text, preferably
>  with auto-update:
>
>> This is a discussion.
>>
>> #+CALC: Fish = 2
>>
>> Fish deserves significant commentary; however, we expect that there
>> is some command that would allow us to update the entire buffer's
>> #+CALC sequence.  Thus:
>> 
>> #+CALC: Dog = 2 * Fish
>> #+CALC: sqrt( Dog ) =>
>> #+results:
>> : sqrt( Dog ) => 2
>>
>> If you need a different result, tweak the 'Fish =' line, above, and
>> request a re-sequencing, either via C-c C-c or via some M-x command,
>> resulting in behavior functionally similar to C-x * u.
>

I believe this may be much more easily implemented using the "session"
features of Org-mode code blocks, possibly in combination with the
inline code block syntax.  Please see [1] for much more information on
working with code blocks in Org-mode.

>
> The goal of this exercise would be, upon updating, to strip all lines
> beginning with #+CALC and feed them to a buffer, inserting the results
> of => statements where the respective line occurs.  The benefit of
> this method over the previous is that it allows for assignments (:=)
> enduring across entire files (though the same could be accomplished if
> one SRC_BEGIN block could somehow call another.)
>

It is currently possible for one source block to call another, see the
chapter of the manual linked above for details.

>
> In conclusion, it seems to me that I cannot possibly be the first
> person to have done research in OrgMode, and that these problems were
> likely solved long ago.  When searching the manual, however, I find
> nothing that produces a distinctly clear and encapsulated Calc embed
> in OrgMode.

You are certainly not the first to use Org-mode as a research platform,
however you may be the first calc power-user to attempt to combine calc
with Org-mode.

> Do these exist, and if not, would it require mere hours of time to
> implement them, or weeks?  Is there a tutorial on writing OrgMode
> extensions?
>

Using the Babel code block support I would anticipate that this would
take more on the order of hours rather than weeks (assuming some elisp
fluency).  See the existing template file for adding support for a new
language to Org-mode.

http://repo.or.cz/w/Worg.git/blob/HEAD:/org-contrib/babel/ob-template.el

This process should be significantly simplified by the fact that Calc is
an Emacs command (rather than an external utility).

I would be happy to help you in implementing an ob-calc.el file, and if
I find time I may take a stab at it myself.

Best -- Eric

>
> - M
>
> _______________________________________________
> 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

Footnotes: 
[1]  http://orgmode.org/manual/Working-With-Source-Code.html#Working-With-Source-Code

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
  2010-10-26 18:37 ` Eric Schulte
@ 2010-10-29  6:42   ` Eric Schulte
  2010-10-29  7:13     ` Carsten Dominik
                       ` (2 more replies)
  0 siblings, 3 replies; 27+ messages in thread
From: Eric Schulte @ 2010-10-29  6:42 UTC (permalink / raw)
  To: Matthew Oesting; +Cc: emacs-orgmode

"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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
  2010-10-29  6:42   ` Eric Schulte
@ 2010-10-29  7:13     ` Carsten Dominik
  2010-10-29 11:14     ` Eric S Fraga
  2010-10-29 11:27     ` Sébastien Vauban
  2 siblings, 0 replies; 27+ messages in thread
From: Carsten Dominik @ 2010-10-29  7:13 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode, Matthew Oesting

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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
  2010-10-29  6:42   ` Eric Schulte
  2010-10-29  7:13     ` Carsten Dominik
@ 2010-10-29 11:14     ` Eric S Fraga
  2010-10-29 14:43       ` Eric Schulte
  2010-10-29 11:27     ` Sébastien Vauban
  2 siblings, 1 reply; 27+ messages in thread
From: Eric S Fraga @ 2010-10-29 11:14 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode, Matthew Oesting

Eric,

This is really nice!

I had a problem initially in that calc-push-list was undefined.  I had
to initiate calc first so maybe a 

: (require 'calc)

is required to ensure the functions you use are available?

Then, out of the three examples you give, only one (3^3) worked.  The
others give me:

--8<---------------cut here---------------start------------->8---
Debugger entered--Lisp error: (wrong-type-argument stringp (2 "Expected a number"))
  string-match("\\` *\\([0-9]+\\) *\\'" (2 "Expected a number"))
  math-read-number((2 "Expected a number"))
  (list (math-read-number (calc-eval line)))
  (calc-push-list (list (math-read-number ...)))
  (if (string= "'" (substring line 0 1)) (funcall (lookup-key calc-mode-map ...) nil) (calc-push-list (list ...)))
  (progn (if (string= "'" ...) (funcall ... nil) (calc-push-list ...)))
  (if (> (length line) 0) (progn (if ... ... ...)))
  (when (> (length line) 0) (if (string= "'" ...) (funcall ... nil) (calc-push-list ...)))
  (lambda (line) (when (> ... 0) (if ... ... ...)))("  '+")
  mapcar((lambda (line) (when (> ... 0) (if ... ... ...))) ("  1" "  2" "  '+" ""))
  org-babel-execute:calc("  1\n  2\n  '+\n" ((:colname-names) (:rowname-names) (:result-params "replace") (:result-type . value) (:comments . "") (:shebang . "") (:cache . "no") (:noweb . "no") (:tangle . "no") (:exports . "code") (:results . "replace") (:hlines . "no") (:session . "none")))
  org-babel-execute-src-block(nil ("calc" "  1\n  2\n  '+\n" ((:colname-names) (:rowname-names) (:result-params "replace") (:result-type . value) (:comments . "") (:shebang . "") (:cache . "no") (:noweb . "no") (:tangle . "no") (:exports . "code") (:results . "replace") (:hlines . "no") (:session . "none")) "" nil 0))
  org-babel-execute-src-block-maybe()
  org-babel-execute-maybe()
  org-babel-execute-safely-maybe()
  run-hook-with-args-until-success(org-babel-execute-safely-maybe)
  org-ctrl-c-ctrl-c(nil)
  call-interactively(org-ctrl-c-ctrl-c nil nil)
--8<---------------cut here---------------end--------------->8---

Have I done something wrong?

I am particularly excited, once it works for me, to use this for
/inline/ babel executions!

Thanks,
eric

-- 
Eric S Fraga
GnuPG: 8F5C 279D 3907 E14A 5C29  570D C891 93D8 FFFC F67D

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
  2010-10-29  6:42   ` Eric Schulte
  2010-10-29  7:13     ` Carsten Dominik
  2010-10-29 11:14     ` Eric S Fraga
@ 2010-10-29 11:27     ` Sébastien Vauban
  2 siblings, 0 replies; 27+ messages in thread
From: Sébastien Vauban @ 2010-10-29 11:27 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

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 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

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 =calc= by calling =C-x * *=:

--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

-- 
Sébastien 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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
  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
  0 siblings, 2 replies; 27+ messages in thread
From: Eric Schulte @ 2010-10-29 14:43 UTC (permalink / raw)
  To: Eric S Fraga; +Cc: emacs-orgmode, Matthew Oesting

Eric S Fraga <ucecesf@ucl.ac.uk> writes:

> Eric,
>
> This is really nice!
>
> I had a problem initially in that calc-push-list was undefined.  I had
> to initiate calc first so maybe a 
>
> : (require 'calc)
>

Ah yes, that is in the ob-calc.el file, but not in the code snippet I
shared.  I'll commit this entire file to the repository.

>
> is required to ensure the functions you use are available?
>
> Then, out of the three examples you give, only one (3^3) worked.  The
> others give me:
>

I just made a change which should fix this issue.

>
> Debugger entered--Lisp error: (wrong-type-argument stringp (2
>"Expected a number"))
[...]

>
> Have I done something wrong?
>
> I am particularly excited, once it works for me, to use this for
> /inline/ babel executions!
>

Great.

I'd be particularly interested if there are more natural or "idiomatic
calc" ways to interact with Calc through a code block than the one
implemented here.

Cheers -- Eric

>
> Thanks,
> eric

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
  2010-10-29 14:43       ` Eric Schulte
@ 2010-10-29 16:22         ` Eric Schulte
  2010-10-29 19:53         ` Eric S Fraga
  1 sibling, 0 replies; 27+ messages in thread
From: Eric Schulte @ 2010-10-29 16:22 UTC (permalink / raw)
  To: Eric S Fraga; +Cc: emacs-orgmode, Matthew Oesting

Just FYI, I've just pushed up another fix for ob-calc.el which I found
was required to avoid errors on evaluation of calc code blocks.

Best -- Eric

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
  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
  1 sibling, 1 reply; 27+ messages in thread
From: Eric S Fraga @ 2010-10-29 19:53 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode, Matthew Oesting

"Eric Schulte" <schulte.eric@gmail.com> writes:

> Eric S Fraga <ucecesf@ucl.ac.uk> writes:
>
>> Eric,
>>
>> This is really nice!
>>
>> I had a problem initially in that calc-push-list was undefined.  I had
>> to initiate calc first so maybe a
>>
>> : (require 'calc)
>>
>
> Ah yes, that is in the ob-calc.el file, but not in the code snippet I
> shared.  I'll commit this entire file to the repository.

Ah, so should I use the code snippet you sent or should I be requiring
'ob-calc?  In either case, I still have problems (see below).

>> is required to ensure the functions you use are available?
>>
>> Then, out of the three examples you give, only one (3^3) worked.  The
>> others give me:
>>
>
> I just made a change which should fix this issue.

Very strange.  I'm still seeing the same problems, both with
calc-push-list not known (having to manually require 'calc) and then
errors evaluating the 1+2 block:

--8<---------------cut here---------------start------------->8---
Debugger entered--Lisp error: (wrong-type-argument stringp (2 "Expected a number"))
  string-match("\\` *\\([0-9]+\\) *\\'" (2 "Expected a number"))
  math-read-number((2 "Expected a number"))
  (list (math-read-number (calc-eval line)))
  (calc-push-list (list (math-read-number ...)))
  (if (string= "'" (substring line 0 1)) (funcall (lookup-key calc-mode-map ...) nil) (calc-push-list (list ...)))
  (progn (if (string= "'" ...) (funcall ... nil) (calc-push-list ...)))
  (if (> (length line) 0) (progn (if ... ... ...)))
  (when (> (length line) 0) (if (string= "'" ...) (funcall ... nil) (calc-push-list ...)))
  (lambda (line) (when (> ... 0) (if ... ... ...)))("  '+")
  mapcar((lambda (line) (when (> ... 0) (if ... ... ...))) ("  1" "  2" "  '+" ""))
  org-babel-execute:calc("  1\n  2\n  '+\n" ((:colname-names) (:rowname-names) (:result-params "replace") (:result-type . value) (:comments . "") (:shebang . "") (:cache . "no") (:noweb . "no") (:tangle . "no") (:exports . "code") (:results . "replace") (:hlines . "no") (:session . "none")))
  org-babel-execute-src-block(nil ("calc" "  1\n  2\n  '+\n" ((:colname-names) (:rowname-names) (:result-params "replace") (:result-type . value) (:comments . "") (:shebang . "") (:cache . "no") (:noweb . "no") (:tangle . "no") (:exports . "code") (:results . "replace") (:hlines . "no") (:session . "none")) "" nil 0))
  org-babel-execute-src-block-maybe()
  org-babel-execute-maybe()
  org-babel-execute-safely-maybe()
  run-hook-with-args-until-success(org-babel-execute-safely-maybe)
  org-ctrl-c-ctrl-c(nil)
  call-interactively(org-ctrl-c-ctrl-c nil nil)
--8<---------------cut here---------------end--------------->8---

org is up to date as of a minute or two ago:

: GNU Emacs 23.2.1 (i486-pc-linux-gnu, GTK+ Version 2.20.0)
:  of 2010-08-14 on raven, modified by Debian
: Org-mode version 7.02trans (release_7.02.18.g9c83)

> I'd be particularly interested if there are more natural or "idiomatic
> calc" ways to interact with Calc through a code block than the one
> implemented here.

Well, I like being able to say, for instance, =src_calc(2010-1989)= and
have the result appear in an export of the file.  By the way, this works
so some things are working just fine.

Thanks,
eric

-- 
Eric S Fraga
GnuPG: 8F5C 279D 3907 E14A 5C29  570D C891 93D8 FFFC F67D

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
  2010-10-29 19:53         ` Eric S Fraga
@ 2010-10-29 20:26           ` Eric Schulte
       [not found]             ` <87hbg4pooh.fsf@ucl.ac.uk>
  0 siblings, 1 reply; 27+ messages in thread
From: Eric Schulte @ 2010-10-29 20:26 UTC (permalink / raw)
  To: Eric S Fraga; +Cc: emacs-orgmode, Matthew Oesting

Eric S Fraga <ucecesf@ucl.ac.uk> writes:

> "Eric Schulte" <schulte.eric@gmail.com> writes:
>
>> Eric S Fraga <ucecesf@ucl.ac.uk> writes:
>>
>>> Eric,
>>>
>>> This is really nice!
>>>
>>> I had a problem initially in that calc-push-list was undefined.  I had
>>> to initiate calc first so maybe a
>>>
>>> : (require 'calc)
>>>
>>
>> Ah yes, that is in the ob-calc.el file, but not in the code snippet I
>> shared.  I'll commit this entire file to the repository.
>
> Ah, so should I use the code snippet you sent or should I be requiring
> 'ob-calc?  In either case, I still have problems (see below).
>

Require ob-calc, please don't use the snippet below.

>
>>> is required to ensure the functions you use are available?
>>>
>>> Then, out of the three examples you give, only one (3^3) worked.  The
>>> others give me:
>>>
>>
>> I just made a change which should fix this issue.
>
> Very strange.  I'm still seeing the same problems, both with
> calc-push-list not known (having to manually require 'calc) and then
> errors evaluating the 1+2 block:
>

judging from the error below, it looks as though you are still using the
old code (or the snippet below).  Please ensure you're on the latest and
give it another go.

>
> Debugger entered--Lisp error: (wrong-type-argument stringp (2
>"Expected a number"))
>   string-match("\\` *\\([0-9]+\\) *\\'" (2 "Expected a number"))
>   math-read-number((2 "Expected a number"))
>   (list (math-read-number (calc-eval line)))

in the latest code the line

  (list (math-read-number (calc-eval line)))

has been replaced by

  (list ((lambda (res)
    (if (numberp res) res (math-read-number res)))
   (calc-eval line)))

Best -- Eric

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
       [not found]               ` <871v7879x5.fsf@gmail.com>
@ 2010-10-30 20:54                 ` Eric S Fraga
  2010-11-03 20:10                   ` Eric Schulte
  0 siblings, 1 reply; 27+ messages in thread
From: Eric S Fraga @ 2010-10-30 20:54 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode, Matthew Oesting

"Eric Schulte" <schulte.eric@gmail.com> writes:
> alright, thanks for sticking with this.  You are definitely now using
> the latest code.  I believe the newest version of the ob-calc-eval
> function should work -- at the very least it should give a nicer error
> message.  Could you please require update again and let me know how it
> goes?

(for the list's benefit: Eric and I have had a few out-of-the-list
exchanges but as everything now seems to be working fine, I thought I'd
reconnect the thread to the list...)

Eric, 

just to confirm that it all seems to work just fine from a cold boot of
emacs without any extra (require 'ob-eval).  My babel configuration has
the following:

#+begin_src emacs_lisp
(org-babel-do-load-languages
 'org-babel-load-languages
 '((R . t)
   (calc . t)
   (ditaa . t)
   ...
#+end_src

and that's about it really.  Evaluating the calc examples you sent
initially all work perfectly.

Using src_calc{5-2}, for instance, also works just fine for export.

I now wonder if it would be worthwhile discussing the choices you have
made regarding stack versus algebraic evaluation.  I would rather have
the quote mean an algebraic expression, just from the simple reason that
these will be longer than stack operations and so the overhead of a
quote is smaller as a percentage of keystrokes...

Anyway, thanks for this.  I think this is going to be quite useful but
it does mean really getting down and learning emacs calc...

-- 
Eric S Fraga
GnuPG: 8F5C 279D 3907 E14A 5C29  570D C891 93D8 FFFC F67D

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
  2010-10-30 20:54                 ` Eric S Fraga
@ 2010-11-03 20:10                   ` Eric Schulte
  0 siblings, 0 replies; 27+ messages in thread
From: Eric Schulte @ 2010-11-03 20:10 UTC (permalink / raw)
  To: Eric S Fraga; +Cc: emacs-orgmode, Matthew Oesting

Eric S Fraga <ucecesf@ucl.ac.uk> writes:

> "Eric Schulte" <schulte.eric@gmail.com> writes:
>> alright, thanks for sticking with this.  You are definitely now using
>> the latest code.  I believe the newest version of the ob-calc-eval
>> function should work -- at the very least it should give a nicer error
>> message.  Could you please require update again and let me know how it
>> goes?
>
> (for the list's benefit: Eric and I have had a few out-of-the-list
> exchanges but as everything now seems to be working fine, I thought I'd
> reconnect the thread to the list...)
>
> Eric, 
>
> just to confirm that it all seems to work just fine from a cold boot of
> emacs without any extra (require 'ob-eval).  My babel configuration has
> the following:
>
> #+begin_src emacs_lisp
> (org-babel-do-load-languages
>  'org-babel-load-languages
>  '((R . t)
>    (calc . t)
>    (ditaa . t)
>    ...
> #+end_src
>
> and that's about it really.  Evaluating the calc examples you sent
> initially all work perfectly.
>

Fantastic.

>
> Using src_calc{5-2}, for instance, also works just fine for export.
>
> I now wonder if it would be worthwhile discussing the choices you have
> made regarding stack versus algebraic evaluation.  I would rather have
> the quote mean an algebraic expression, just from the simple reason that
> these will be longer than stack operations and so the overhead of a
> quote is smaller as a percentage of keystrokes...
>

Hmm, one point against prefixing the algebraic expressions is that they
would be more likely to be used by themselves in an inline code block.
Maybe there is a better way to recognize when a line is a stack vs. an
algebraic expression.  For example if the line is resolvable to a stack
operation (i.e. an element of '(+ - ...)) then treat it as such,
otherwise just treat it as an algebraic expression.

>
> Anyway, thanks for this.  I think this is going to be quite useful but
> it does mean really getting down and learning emacs calc...

Yes, I need to learn calc as well.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
@ 2010-11-03 22:42 Eric S Fraga
  2010-11-04 13:24 ` Eric Schulte
  0 siblings, 1 reply; 27+ messages in thread
From: Eric S Fraga @ 2010-11-03 22:42 UTC (permalink / raw)
  To: Matthew Oesting, emacs-orgmode

Forgot to CC the list et al.

"Eric Schulte" <schulte.eric@gmail.com> writes:

> Eric S Fraga <ucecesf@ucl.ac.uk> writes:

[...]

>> I now wonder if it would be worthwhile discussing the choices you have
>> made regarding stack versus algebraic evaluation.  I would rather have
>> the quote mean an algebraic expression, just from the simple reason that
>> these will be longer than stack operations and so the overhead of a
>> quote is smaller as a percentage of keystrokes...
>>
>
> Hmm, one point against prefixing the algebraic expressions is that they
> would be more likely to be used by themselves in an inline code block.

Yes, I guess so.  My initial thoughts were that we have plenty of
algebraic languages available already through babel (octave, R, python,
...) so why not support a stack based one more directly.   However, the
real benefit of calc is that it is *emacs* and not external!  Algebraic
is more natural to most people so making it easy for them to express
themselves makes sense.

-- 
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 23.2.1
: using Org-mode version 7.02trans (release_7.3.10.g7f79.dirty)

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
  2010-11-03 22:42 Eric S Fraga
@ 2010-11-04 13:24 ` Eric Schulte
  2010-11-04 14:13   ` Eric S Fraga
                     ` (2 more replies)
  0 siblings, 3 replies; 27+ messages in thread
From: Eric Schulte @ 2010-11-04 13:24 UTC (permalink / raw)
  To: Eric S Fraga; +Cc: emacs-orgmode, Matthew Oesting

Alright,

I've just pushed up support for variables.  The following should all
work as expected (or at least as I would expect them to).  Note that
most all of these blocks would have an effect on the calc stack.  I
think the next step would be to allow different sessions to specify
different stacks.

** playing with calc support
#+begin_src emacs-lisp :results silent
  (require 'ob-calc)
#+end_src

#+begin_src calc :var some=8
  some
  some
  '*
  1
  '+
#+end_src

#+results:
: 65

#+begin_src calc
  2*(8+8)
#+end_src

#+results:
: 32

#+begin_src calc
  2*e
#+end_src

#+results:
: 5.43656365692

#+begin_src calc :var something=9
  2*something
#+end_src

#+results:
: 18

There are very likely some bugs, and as always I'm eager for a calc
power user to show me the light of how this support could be make more
"calc idiomatic".

Cheers -- Eric

Eric S Fraga <ucecesf@ucl.ac.uk> writes:

> Forgot to CC the list et al.
>
> "Eric Schulte" <schulte.eric@gmail.com> writes:
>
>> Eric S Fraga <ucecesf@ucl.ac.uk> writes:
>
> [...]
>
>>> I now wonder if it would be worthwhile discussing the choices you have
>>> made regarding stack versus algebraic evaluation.  I would rather have
>>> the quote mean an algebraic expression, just from the simple reason that
>>> these will be longer than stack operations and so the overhead of a
>>> quote is smaller as a percentage of keystrokes...
>>>
>>
>> Hmm, one point against prefixing the algebraic expressions is that they
>> would be more likely to be used by themselves in an inline code block.
>
> Yes, I guess so.  My initial thoughts were that we have plenty of
> algebraic languages available already through babel (octave, R, python,
> ...) so why not support a stack based one more directly.   However, the
> real benefit of calc is that it is *emacs* and not external!  Algebraic
> is more natural to most people so making it easy for them to express
> themselves makes sense.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
  2010-11-04 13:24 ` Eric Schulte
@ 2010-11-04 14:13   ` Eric S Fraga
  2010-11-04 14:42   ` Sébastien Vauban
  2011-01-27  0:39   ` Christopher Allan Webber
  2 siblings, 0 replies; 27+ messages in thread
From: Eric S Fraga @ 2010-11-04 14:13 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode, Matthew Oesting

"Eric Schulte" <schulte.eric@gmail.com> writes:

> Alright,
>
> I've just pushed up support for variables.  The following should all
> work as expected (or at least as I would expect them to).  Note that
> most all of these blocks would have an effect on the calc stack.  I
> think the next step would be to allow different sessions to specify
> different stacks.

[...]

works well for me!  Thanks.

-- 
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 23.2.1
: using Org-mode version 7.02trans (release_7.3.18.g3818)

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
  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
  2011-01-27  0:39   ` Christopher Allan Webber
  2 siblings, 1 reply; 27+ messages in thread
From: Sébastien Vauban @ 2010-11-04 14:42 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Eric,

> I've just pushed up support for variables. The following should all work as
> expected (or at least as I would expect them to).
>
> ** playing with calc support
> #+begin_src emacs-lisp :results silent
>   (require 'ob-calc)
> #+end_src

There must be something stupid in my config, but even a simple one like the
following does not work for me:

#+begin_src calc
1
2
'+
#+end_src

Error is:

#+begin_src emacs-lisp
executing Calc code block...
calc-push-list: Symbol's value as variable is void: calc-command-flags
#+end_src

Though, I confirm you that I have loaded both =calc= and =ob-calc=... Any idea?


> There are very likely some bugs, and as always I'm eager for a calc power
> user to show me the light of how this support could be make more "calc
> idiomatic".

Be hopeless: I won't be that one ;-(

Best regards,
  Seb

-- 
Sébastien 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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
  2010-11-04 15:33     ` Eric Schulte
@ 2010-11-04 16:02       ` Sébastien Vauban
  0 siblings, 0 replies; 27+ messages in thread
From: Sébastien Vauban @ 2010-11-04 16:02 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Eric,

"Eric Schulte" wrote:
> Sébastien Vauban <wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@public.gmane.org> writes:
>
>> There must be something stupid in my config, but even a simple one like the
>> following does not work for me:
>>
>> #+begin_src calc
>> 1
>> 2
>> '+
>> #+end_src
>>
>> Error is:
>>
>> #+begin_src emacs-lisp
>> executing Calc code block...
>> calc-push-list: Symbol's value as variable is void: calc-command-flags
>> #+end_src
>>
>> Though, I confirm you that I have loaded both =calc= and =ob-calc=... Any idea?
>
> That variable is defined in my version of calc.el (distributed with the
> latest version of Emacs from git).  Is that variable not defined in your
> calc.el file?  Maybe the solution is to upgrade your calc.

I have "GNU Emacs 23.1.50.1 (i386-mingw-nt5.1.2600) of 2009-10-14 on
LENNART-69DE564 (patched)" (known as EmacsW32, latest version that Lennart put
online).

Library is file "c:/Program Files/Emacs/emacs/lisp/calc/calc.elc", and I see
(on line 1544 of the =.el= file):

#+begin_src emacs-lisp
(defvar calc-command-flags)
#+end_src

ELC seems well compiled from that EL, as times report:

--8<---------------cut here---------------start------------->8---
  -rw-rw-rw-  1 Fabrice Aucun 138805 2009-10-14 02:45 calc.el
  -rw-rw-rw-  1 Fabrice Aucun 103841 2009-10-14 02:46 calc.elc
--8<---------------cut here---------------end--------------->8---

Setting it myself to nil -- I have no idea why I must do this! -- :

#+begin_src emacs-lisp
(setq calc-command-flags nil)
#+end_src

has the effect that many examples now work.

Not all, though. For example,

#+begin_src calc
2*e
#+end_src

returns =nil=:

#+results:
: nil

Best regards,
  Seb

-- 
Sébastien 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

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
  2010-11-04 13:24 ` Eric Schulte
  2010-11-04 14:13   ` Eric S Fraga
  2010-11-04 14:42   ` Sébastien Vauban
@ 2011-01-27  0:39   ` Christopher Allan Webber
  2011-02-23  4:35     ` Eric Schulte
  2 siblings, 1 reply; 27+ messages in thread
From: Christopher Allan Webber @ 2011-01-27  0:39 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Matthew Oesting, Eric S Fraga, emacs-orgmode

(failed to wide-reply initially)

I just had use for this for some quick calculations I wanted to add to
one of my files, but...

Any idea why variables inside of parentheses don't work, but variables
outside of them do?

#+BEGIN_SRC calc :var testvar=9000
testvar - 200
#+END_SRC

#+results:
: 8800


#+BEGIN_SRC calc :var testvar=9000
(testvar - 200) 800
#+END_SRC

#+results:
: 800 testvar - 160000

"Eric Schulte" <schulte.eric@gmail.com> writes:

> Alright,
>
> I've just pushed up support for variables.  The following should all
> work as expected (or at least as I would expect them to).  Note that
> most all of these blocks would have an effect on the calc stack.  I
> think the next step would be to allow different sessions to specify
> different stacks.
>
> ** playing with calc support
> #+begin_src emacs-lisp :results silent
>   (require 'ob-calc)
> #+end_src
> #+begin_src calc :var some=8
>   some
>   some
>   '*
>   1
>   '+
> #+end_src
>
> #+results:
> : 65
>
> #+begin_src calc
>   2*(8+8)
> #+end_src
>
> #+results:
> : 32
>
> #+begin_src calc
>   2*e
> #+end_src
>
> #+results:
> : 5.43656365692
>
> #+begin_src calc :var something=9
>   2*something
> #+end_src
>
> #+results:
> : 18
>
> There are very likely some bugs, and as always I'm eager for a calc
> power user to show me the light of how this support could be make more
> "calc idiomatic".
>
> Cheers -- Eric
>
> Eric S Fraga <ucecesf@ucl.ac.uk> writes:
>
>> Forgot to CC the list et al.
>>
>> "Eric Schulte" <schulte.eric@gmail.com> writes:
>>
>>> Eric S Fraga <ucecesf@ucl.ac.uk> writes:
>>
>> [...]
>>
>>>> I now wonder if it would be worthwhile discussing the choices you have
>>>> made regarding stack versus algebraic evaluation.  I would rather have
>>>> the quote mean an algebraic expression, just from the simple reason that
>>>> these will be longer than stack operations and so the overhead of a
>>>> quote is smaller as a percentage of keystrokes...
>>>>
>>>
>>> Hmm, one point against prefixing the algebraic expressions is that they
>>> would be more likely to be used by themselves in an inline code block.
>>
>> Yes, I guess so.  My initial thoughts were that we have plenty of
>> algebraic languages available already through babel (octave, R, python,
>> ...) so why not support a stack based one more directly.   However, the
>> real benefit of calc is that it is *emacs* and not external!  Algebraic
>> is more natural to most people so making it easy for them to express
>> themselves makes sense.
>
> _______________________________________________
> 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
>

-- 


-- 
𝓒𝓱𝓻𝓲𝓼𝓽𝓸𝓹𝓱𝓮𝓻 𝓐𝓵𝓵𝓪𝓷 𝓦𝓮𝓫𝓫𝓮𝓻

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
  2011-01-27  0:39   ` Christopher Allan Webber
@ 2011-02-23  4:35     ` Eric Schulte
  2011-02-24 10:13       ` Eric S Fraga
  0 siblings, 1 reply; 27+ messages in thread
From: Eric Schulte @ 2011-02-23  4:35 UTC (permalink / raw)
  To: Christopher Allan Webber; +Cc: Matthew Oesting, Eric S Fraga, emacs-orgmode

Christopher Allan Webber <cwebber@dustycloud.org> writes:

> (failed to wide-reply initially)
>
> I just had use for this for some quick calculations I wanted to add to
> one of my files, but...
>
> Any idea why variables inside of parentheses don't work, but variables
> outside of them do?
>
> #+BEGIN_SRC calc :var testvar=9000
> testvar - 200
> #+END_SRC
>
> #+results:
> : 8800
>
>
> #+BEGIN_SRC calc :var testvar=9000
> (testvar - 200) 800
> #+END_SRC
>
> #+results:
> : 800 testvar - 160000
>

Hi Christopher,

Sorry about the LONG delay in replying to this email.  I've just pushed
up a fix for this problem.  Thanks for reporting.

Best -- Eric

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
  2011-02-23  4:35     ` Eric Schulte
@ 2011-02-24 10:13       ` Eric S Fraga
  2011-02-27 21:32         ` Eric Schulte
  0 siblings, 1 reply; 27+ messages in thread
From: Eric S Fraga @ 2011-02-24 10:13 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode, Matthew Oesting

"Eric Schulte" <schulte.eric@gmail.com> writes:

> Christopher Allan Webber <cwebber@dustycloud.org> writes:
>
>> (failed to wide-reply initially)
>>
>> I just had use for this for some quick calculations I wanted to add to
>> one of my files, but...
>>
>> Any idea why variables inside of parentheses don't work, but variables
>> outside of them do?
>>
>> #+BEGIN_SRC calc :var testvar=9000
>> testvar - 200
>> #+END_SRC
>>
>> #+results:
>> : 8800
>>
>>
>> #+BEGIN_SRC calc :var testvar=9000
>> (testvar - 200) 800
>> #+END_SRC
>>
>> #+results:
>> : 800 testvar - 160000
>>
>
> Hi Christopher,
>
> Sorry about the LONG delay in replying to this email.  I've just pushed
> up a fix for this problem.  Thanks for reporting.
>
> Best -- Eric

Further on this, any suggestions on how to pass a vector variable to
calc using babel?  I tried

#+begin-src org
  #+begin_src calc :var y=[1 2 3]
3 y
  #+end_src
#+end_src

but get an error that says

: Bad format in variable contents: Expected a number

I've tried putting the vector in quotes but that doesn't help either.
Is this maybe not possible?

Thanks,
eric
-- 
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1
: using Org-mode version 7.4 (release_7.4.529.gb23d)

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
  2011-02-24 10:13       ` Eric S Fraga
@ 2011-02-27 21:32         ` Eric Schulte
  2011-02-28 18:16           ` Eric S Fraga
  0 siblings, 1 reply; 27+ messages in thread
From: Eric Schulte @ 2011-02-27 21:32 UTC (permalink / raw)
  To: Eric S Fraga; +Cc: emacs-orgmode, Matthew Oesting

Eric S Fraga <e.fraga@ucl.ac.uk> writes:

> "Eric Schulte" <schulte.eric@gmail.com> writes:
>
>> Christopher Allan Webber <cwebber@dustycloud.org> writes:
>>
>>> (failed to wide-reply initially)
>>>
>>> I just had use for this for some quick calculations I wanted to add to
>>> one of my files, but...
>>>
>>> Any idea why variables inside of parentheses don't work, but variables
>>> outside of them do?
>>>
>>> #+BEGIN_SRC calc :var testvar=9000
>>> testvar - 200
>>> #+END_SRC
>>>
>>> #+results:
>>> : 8800
>>>
>>>
>>> #+BEGIN_SRC calc :var testvar=9000
>>> (testvar - 200) 800
>>> #+END_SRC
>>>
>>> #+results:
>>> : 800 testvar - 160000
>>>
>>
>> Hi Christopher,
>>
>> Sorry about the LONG delay in replying to this email.  I've just pushed
>> up a fix for this problem.  Thanks for reporting.
>>
>> Best -- Eric
>
> Further on this, any suggestions on how to pass a vector variable to
> calc using babel?  I tried
>
> #+begin-src org
>   #+begin_src calc :var y=[1 2 3]
> 3 y
>   #+end_src
> #+end_src
>
> but get an error that says
>
> : Bad format in variable contents: Expected a number
>
> I've tried putting the vector in quotes but that doesn't help either.
> Is this maybe not possible?
>

With the newest version of Org-mode, I'm now getting the following
output.

#+begin_src calc :var y=[1 2 3]
  3 y
#+end_src

#+results:
: (3, 6)

Does this look correct?

Best -- Eric

>
> Thanks,
> eric

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
  2011-02-27 21:32         ` Eric Schulte
@ 2011-02-28 18:16           ` Eric S Fraga
  2011-03-01 17:34             ` Eric Schulte
  0 siblings, 1 reply; 27+ messages in thread
From: Eric S Fraga @ 2011-02-28 18:16 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode, Matthew Oesting

"Eric Schulte" <schulte.eric@gmail.com> writes:

> Eric S Fraga <e.fraga@ucl.ac.uk> writes:

[...]

>>
>> Further on this, any suggestions on how to pass a vector variable to
>> calc using babel?  I tried
>>
>> #+begin-src org
>>   #+begin_src calc :var y=[1 2 3]
>> 3 y
>>   #+end_src
>> #+end_src
>>
>> but get an error that says
>>
>> : Bad format in variable contents: Expected a number
>>
>> I've tried putting the vector in quotes but that doesn't help either.
>> Is this maybe not possible?
>>
>
> With the newest version of Org-mode, I'm now getting the following
> output.
>
> #+begin_src calc :var y=[1 2 3]
>   3 y
> #+end_src
> #+results:
> : (3, 6)
>
> Does this look correct?
>
> Best -- Eric

This does not look correct: assuming my knowledge of calc is correct,
the result should be the scalar 3 multiplied by each of the vector
elements.  I don't understand how =(3, 6)= can be the output of =3 y=...

The strange thing is that this doesn't work at all for me (with git as
of a few minutes ago): I still get the error message

: byte-code: Bad format in variable contents: Expected a number

However, if I put the vector in double quotes, it works:

--8<---------------cut here---------------start------------->8---
  #+begin_src calc :var y="[1 2 3]"
3 y
  #+end_src

  #+results:
  : [3, 6, 9]
--8<---------------cut here---------------end--------------->8---

*but* if I subsequently remove the double quotes, it doesn't work and if
put them back, it no longer works either.  I am confused...  there's
like a hysteresis loop in org babel :(

Any suggestions on how to debug this are welcome, of course.

-- 
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1
: using Org-mode version 7.4 (release_7.4.553.g83b7.dirty)

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
  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
  0 siblings, 2 replies; 27+ messages in thread
From: Eric Schulte @ 2011-03-01 17:34 UTC (permalink / raw)
  To: Eric S Fraga; +Cc: emacs-orgmode, Matthew Oesting

Eric S Fraga <e.fraga@ucl.ac.uk> writes:

> "Eric Schulte" <schulte.eric@gmail.com> writes:
>
>> Eric S Fraga <e.fraga@ucl.ac.uk> writes:
>
> [...]
>
>>>
>>> Further on this, any suggestions on how to pass a vector variable to
>>> calc using babel?  I tried
>>>
>>> #+begin-src org
>>>   #+begin_src calc :var y=[1 2 3]
>>> 3 y
>>>   #+end_src
>>> #+end_src
>>>
>>> but get an error that says
>>>
>>> : Bad format in variable contents: Expected a number
>>>
>>> I've tried putting the vector in quotes but that doesn't help either.
>>> Is this maybe not possible?
>>>
>>
>> With the newest version of Org-mode, I'm now getting the following
>> output.
>>
>> #+begin_src calc :var y=[1 2 3]
>>   3 y
>> #+end_src
>> #+results:
>> : (3, 6)
>>
>> Does this look correct?
>>
>> Best -- Eric
>
> This does not look correct: assuming my knowledge of calc is correct,
> the result should be the scalar 3 multiplied by each of the vector
> elements.  I don't understand how =(3, 6)= can be the output of =3 y=...
>
> The strange thing is that this doesn't work at all for me (with git as
> of a few minutes ago): I still get the error message
>
> : byte-code: Bad format in variable contents: Expected a number
>
> However, if I put the vector in double quotes, it works:
>
>   #+begin_src calc :var y="[1 2 3]"
> 3 y
>   #+end_src
>
>   #+results:
>   : [3, 6, 9]
>
> *but* if I subsequently remove the double quotes, it doesn't work and if
> put them back, it no longer works either.  I am confused...  there's
> like a hysteresis loop in org babel :(
>
> Any suggestions on how to debug this are welcome, of course.

Oh, I just got an even stranger result, with the latest from git...

#+begin_src calc :var y=[1 2 3]
  3 y
#+end_src

#+results:
: 3 hline

something is most certainly wrong...

Alright, I've made two changes, first, it is now possible to pass elisp
vectors through to code blocks, e.g.,

#+begin_src emacs-lisp :var data=[1 2 3]
  (elt data 1)
#+end_src

#+results:
: 2

Second, I've added a slightly hackey but seemingly necessary
post-processing step to a call to calc-eval in ob-calc to remove quotes
from vectors.  This allows vector processing to take place---at least as
far as my limited calc knowledge is concerned.  For example;

#+begin_src calc :var y=[1 2 3]
  3 y
#+end_src

#+results:
: [3, 6, 9]

Hope this helps -- Cheers -- Eric

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
  2011-03-01 17:34             ` Eric Schulte
@ 2011-03-01 20:10               ` Eric S Fraga
  2011-03-07  9:16               ` Eric S Fraga
  1 sibling, 0 replies; 27+ messages in thread
From: Eric S Fraga @ 2011-03-01 20:10 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode, Matthew Oesting

"Eric Schulte" <schulte.eric@gmail.com> writes:

[...]

> Alright, I've made two changes, first, it is now possible to pass elisp
> vectors through to code blocks, e.g.,
>
> #+begin_src emacs-lisp :var data=[1 2 3]
>   (elt data 1)
> #+end_src
> #+results:
> : 2
>
> Second, I've added a slightly hackey but seemingly necessary
> post-processing step to a call to calc-eval in ob-calc to remove quotes
> from vectors.  This allows vector processing to take place---at least as
> far as my limited calc knowledge is concerned.  For example;
>
> #+begin_src calc :var y=[1 2 3]
>   3 y
> #+end_src
> #+results:
> : [3, 6, 9]
>
> Hope this helps -- Cheers -- Eric

It does indeed.  It all seems to work just fine now.

I don't necessarily know much more emacs calc than you but the little I
know seems to work just fine.  It's such a powerful package sitting
there mostly idle and org babel is probably the best way to release it
for general use!  Especially for inline calculations...  Time to re-read
the calc manual again and play.

Thanks,
eric

-- 
Eric S Fraga (: http://www.homepages.ucl.ac.uk/~ucecesf/ :)

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
@ 2011-03-01 20:48 orgmode
  2011-03-02 11:28 ` Eric S Fraga
  0 siblings, 1 reply; 27+ messages in thread
From: orgmode @ 2011-03-01 20:48 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: orgmode

Hi,

addition of babel support for calc is nice.  However calc also has  
"embedded mode".  that means active calc documents can easily be  
embedded in org documents (and also latex, ...).  It is different from  
babel, but in some instances it may work better.

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Re: Possible Calc support for Org-Babel?
  2011-03-01 20:48 Possible Calc support for Org-Babel? orgmode
@ 2011-03-02 11:28 ` Eric S Fraga
  0 siblings, 0 replies; 27+ messages in thread
From: Eric S Fraga @ 2011-03-02 11:28 UTC (permalink / raw)
  To: orgmode@h-rd.org; +Cc: emacs-orgmode

"orgmode@h-rd.org" <orgmode@h-rd.org> writes:

> Hi,
>
> addition of babel support for calc is nice.  However calc also has
> "embedded mode".  that means active calc documents can easily be
> embedded in org documents (and also latex, ...).  It is different from
> babel, but in some instances it may work better.

Indeed.  Embedded mode is excellent and there is some overlap with what
babel provides.  I like them both.
-- 
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1
: using Org-mode version 7.4 (release_7.4.576.g99675.dirty)

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: Possible Calc support for Org-Babel?
  2011-03-01 17:34             ` Eric Schulte
  2011-03-01 20:10               ` Eric S Fraga
@ 2011-03-07  9:16               ` Eric S Fraga
  1 sibling, 0 replies; 27+ messages in thread
From: Eric S Fraga @ 2011-03-07  9:16 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode, Matthew Oesting

"Eric Schulte" <schulte.eric@gmail.com> writes:


[...]

> Alright, I've made two changes, first, it is now possible to pass elisp
> vectors through to code blocks, e.g.,
>
> #+begin_src emacs-lisp :var data=[1 2 3]
>   (elt data 1)
> #+end_src
> #+results:
> : 2
>
> Second, I've added a slightly hackey but seemingly necessary
> post-processing step to a call to calc-eval in ob-calc to remove quotes
> from vectors.  This allows vector processing to take place---at least as
> far as my limited calc knowledge is concerned.  For example;
>
> #+begin_src calc :var y=[1 2 3]
>   3 y
> #+end_src
> #+results:
> : [3, 6, 9]
>
> Hope this helps -- Cheers -- Eric

Indeed. Works very well.  Thanks!

-- 
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1
: using Org-mode version 7.4 (release_7.4.646.g57806)

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2011-03-07 10:11 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-01 20:48 Possible Calc support for Org-Babel? orgmode
2011-03-02 11:28 ` Eric S Fraga
  -- 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
2010-10-22 17:17 Matthew Oesting
2010-10-26 18:37 ` Eric Schulte
2010-10-29  6:42   ` Eric Schulte
2010-10-29  7:13     ` Carsten Dominik
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

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).