From: Yi Wang <tririverwangyi@gmail.com>
To: John Kitchin <jkitchin@andrew.cmu.edu>,
Richard Stanton <stanton@haas.berkeley.edu>
Cc: emacs-orgmode@gnu.org
Subject: Re: Babel language support for Mathematica
Date: Fri, 13 Mar 2015 23:16:36 +0000 [thread overview]
Message-ID: <CAJferG-z0bf4kLDFfOeOFz4w+UOOMBOMs_rayzW8MnZk48+yRA@mail.gmail.com> (raw)
In-Reply-To: <m21tkssddn.fsf@andrew.cmu.edu>
[-- Attachment #1: Type: text/plain, Size: 1860 bytes --]
Dear Richard,
You can do:
#+BEGIN_SRC mathematica
f[x_] := x+3;
f[5]
#+END_SRC
Here are explanations: I actually put everything in the SRC block into a
Print[...].
So in the second example, what actually runs is
Print[f[x_] := x+3
f[5]]
This does not return any value. Because what it really does is print the
value of "f[x_] := x+3 f[5]"
Here is the code:
(concat
(mapconcat ;; define any variables
(lambda (pair)
(format "%s=%s;"
(car pair)
(org-babel-mathematica-var-to-mathematica (cdr pair))))
vars "\n") "\nPrint[\n" body "\n]\n")
If anybody has idea to improve it, I will be happy to see and work it out!
Best,
Yi
On Sat, Mar 14, 2015 at 7:09 AM John Kitchin <jkitchin@andrew.cmu.edu>
wrote:
> I wonder if this is an output vs value issue on the return of the
> block. If you set :results output does anything change? or, is there a
> way to specify a return value? or specifically print something?
>
> Richard Stanton writes:
>
> > I recently saw this posting about org support for Mathematica. Thanks
> for writing this!
> >
> > Unfortunately, while I can get it to work for simple things (e.g., 2+3),
> even slightly more complex things don't seem to work. For example, suppose
> I'd like to define a function f(x) = x + 3, and then calculate f(5). In a
> MMA notebook, if I type
> >
> > f[x_] := x+3
> > f[5]
> >
> > I get the answer 8. If I try the same code in an org-mode code block,
> here's what happens:
> >
> > #+BEGIN_SRC mathematica
> > f[x_] := x+3
> > f[5]
> > #+END_SRC
> >
> > #+RESULTS:
> > : Null
> >
> > Am I missing something obvious here?
> >
> > Thanks very much.
> >
> > Richard Stanton
>
> --
> Professor John Kitchin
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu
>
[-- Attachment #2: Type: text/html, Size: 3986 bytes --]
next prev parent reply other threads:[~2015-03-13 23:16 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-13 23:06 Babel language support for Mathematica Richard Stanton
2015-03-13 23:09 ` John Kitchin
2015-03-13 23:16 ` Yi Wang [this message]
2015-03-15 17:26 ` Richard Stanton
-- strict thread matches above, loose matches on Subject: below --
2014-01-09 3:46 Yi Wang
2014-01-09 10:28 ` Bastien
2014-01-09 10:34 ` Sebastien Vauban
2014-01-09 10:39 ` Bastien
2014-01-09 10:51 ` Yi Wang
2014-01-09 10:55 ` Bastien
2014-01-09 11:03 ` Yi Wang
2014-01-09 11:15 ` Bastien
2014-01-09 11:31 ` Yi Wang
2014-01-09 11:49 ` Yi Wang
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAJferG-z0bf4kLDFfOeOFz4w+UOOMBOMs_rayzW8MnZk48+yRA@mail.gmail.com \
--to=tririverwangyi@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=jkitchin@andrew.cmu.edu \
--cc=stanton@haas.berkeley.edu \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.